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
NIL.


> '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:

   lib/form.l:120
      (*PRG (pushForm (cons)))

   lib/simul.l:161
      (cons (cons) (cons))

   test/lib.l:36
      '((N) (later (cons) (cons *Pid (* N N))))

and I find more in production applications.

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

Reply via email to