Arc Forumnew | comments | leaders | submitlogin
3 points by rocketnia 5158 days ago | link | parent

What we're looking at here is the base case of a dotted list:

  (a b . rest)
  (a . rest)
  rest
The syntax for a single cons cell is (a . b). The (a b c . d) syntax is a shorthand for (a . (b . (c . d))), and the (a b c) syntax is a shorthand for (a b c . ()), where () is nil. Here's a bit of a demonstration:

  arc>
    (def inspect-conses (x)
      (treewise (fn (a b) (+ "(" a " . " b ")")) [tostring:write _] x))
  #<procedure: inspect-conses>
  arc> (inspect-conses '(a b c))
  "(a . (b . (c . nil)))"
  arc> (inspect-conses '(a b . c))
  "(a . (b . c))"
  arc> (inspect-conses '(mac lol (first second . rest) ...))
  "(mac . (lol . ((first . (second . rest)) . (... . nil))))"
  arc> (inspect-conses '(mac lol (first . rest) ...))
  "(mac . (lol . ((first . rest) . (... . nil))))"
  arc> (inspect-conses '(mac lol all-args ...))
  "(mac . (lol . (all-args . (... . nil))))"
If you come from Common Lisp, maybe you already know all this, but I hope it helps someone out there. :-p


1 point by orthecreedence 5158 days ago | link

Thanks for the help, guys!

-----