Hi Tomas,

> > All functions ignore atomic CDRs of the last argument cell. You could
> > also try (onOff A B . X), the 'X' will be simply ignored.
> so why is not NIL in the (onOff . NIL) ignored? ;-)

Well, the NIL _is_ ignored, in the same sense as the 'X' is ignored. The
NIL you observe results from the fact that missing arguments evaluate to

> 'list' is a good example where I find this behaviour rather strange.
> >    : (list)    
> >    -> (NIL)
> Here I would expect NIL and not (NIL).  Any other lisp I know works this

I would definitely always implement 'list' in this way. The reasons are
very pragmatic:

1. Why should anybody call (list) to get 'NIL'? If somebody wants 'NIL',
   he should write 'NIL'.

2. If you, however, want to create a single-cell list containing 'NIL'
   (for example, because you need an empty cell that is filled later),
   you have to write (list NIL) or (cons NIL NIL). But as the first
   argument evaluates to NIL anyway, you can save space in your program
   (a single cell each time) by writing (list) instead of (list NIL).

   I do this quite frequently with (cons), if I need a single cell.
   'cons' and 'list' behave identical in this situation.

3. If 'list' were implemented to return NIL if called without arguments,
   one additional runtime argument check is necessary, introducing
   overhead only for the pathological case where somebody wants to get
   'NIL' from (list) instead of simply writing 'NIL' directly.

> seems broken to me.  Do you have any example or code in picolisp that
> takes advantage of this behaviour?

Not for (list), but for (cons) there are plenty:

      (*PRG (pushForm (cons)))

      (cons (cons) (cons))

      '((N) (later (cons) (cons *Pid (* N N))))

and I find more in production applications.

- Alex
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to