I noticed something today: In arc it appears 'nil is destructurable as multiple nils. For example, here's a crude list printing function: (def print-list ((a . b))
(when a
(prn a)
(print-list b)))
This function can be used in the expected way: >(print-list '(a b c))
a
b
c
Unfortunately, the function has a small wart- It will fail with a nil value in the list: >(print-list '(a b nil c d))
a
b
...then it occured to me: Any list can have its car taken, except the empty list- An empty list is unable to "supply" the car as a value. In my mind, this is analogous to failing to supply a parameter to a function...So what if we allowed the car value to be an optional parameter, which the empty list would "fail to supply": (def print-list (((o a 'end) . b))
(when (isnt a 'end)
(prn a)
(print-list b)))
(This currently does not work)This would fit perfectly into the current optional parameter syntax. Having an explicit ending value is usually no problem: For almost 99% of list processing functions there is an acceptable choice for an ending symbol such as this, from my experience... ...just an idea... |