Hi Pd,

>    - three base data types: Numbers, Symbols and Cons Pairs (Lists),
>    ...
>     suggesting dotted pairs are the same as lists, both are
> indistinguishable so it should be possible to write any list as a dotted
> pair, i. e. (1 2) = (1 . (2 . NIL)) but what is the list for (1 . 2) dotted
> pair?

Lists are a special kind of cons pairs. We call it a list if the last cell has
NIL in its CDR, just like in your example.

So both (1 2) and (1 . 2) are cons pairs. In fact, each cell in a list is a cons
pair), but only (1) or (1 2) is called a list.


> 2- In the same doc talking about function arguments you can read "A lambda
> expression always has a list of executable expressions as its CDR. The CAR,
> however, must be a either a list of symbols, or a single symbol ...

> a)   : (de foo (X Y . Z)                 # CAR is a list with a dotted-pair
> tail

Right

> According with the parameters rules the first is supposed to bind X to the
> first evaluated parameter, Y to the second and Z to the rest of parameters

Yes

> but here the rule to apply is the first one, car is a list of symbols (X, Y
> and Z the last two in the dotted pair Y.Z) so every symbol must be binded
> to evaluated parameters

No, the 'Z' means that the rest of the symbols is *not* evaluated.


> (foo (1 2 3 4))
> 
> should bind 1 to X, 2 to Y and 3 to Z discarding 4 but the examples says it
> really binds 1 to X, 2 to Y and (3 4) to Z thus effectively merging first

No. It binds X to (1 2 3 4), and both Y and Z to NIL


If you call

   (foo 1 2 3 4)

then it binds X to 1, Y to 2 and Z to (3 4).




> b)  : (de foo (X . @)                   # CAR is a dotted-pair with '@'
> 
> This case is similar to the previous but merging first and second rules but
> in this case first rule doesn't apply because as comment remarks CAR is a
> dotted pair not a list


Perhaps it helps to think about this procedurally: While the list of formal
parameters is a cons pair (i.e. not atomic), the next symbol is popped of and
the evaluated parameter bound to it. Then, if the remaining piece is not NIL,
the rest of the list is bound to it unevaluated.

So if the "list" of formal parameters is just Z

   (de foo Z ..)
   (foo 1 2 3 4 5)

then 'Z' is bound to (1 2 3 4 5).

On the other hand, if it is (X Y . Z)

   (de foo (X Y . Z)
   (foo 1 2 3 4 5)

then first X is popped off

   : (setq Lst '(X Y . Z))
   -> (X Y . Z)

   : (pop 'Lst)
   -> X

so 'X' is bound to 1. 'Lst' is now

   : Lst
   -> (Y . Z)

again, we pop

   : (pop 'Lst)
   -> Y

so we bind Y to 2.

But now 'Lst' is

   : Lst
   -> Z

It became atomic! So we are back at the "simple" case above where we had

   (de foo Z ..)

and Z is bound to (3 4 5).
   

The same systematics apply to cases like

   (de foo @ ...)

and

   (de foo (X Y Z . @)

Does this make sense?



> and what means the following notation?
> 
>   -  (dbs . lst)

This notation is meant to represent a function like

   (de dbs Lst ..)

so that a call

   (dbs a b c d)

binds (a b c d) to 'Lst'.

   (dbs a b c d) = (dbs . (a b c d))



> 4- Usually in classical lisp syntax you must use dot surrounded by spaces
> to indicate a dotted pair, I supposed this will be the same in picolisp
> because of fixed point numbers notation so you always shoud use (sym . sym)

Yes. The dot is not a delimiter.

Atoms are delimited by these characters:

   " \t\n\r\\"'(),[]`~{}"


> to write a dotted paid in particular with transient symbols ("hello" .
> "world") but I saw in this lists messages seeming to use the notation

I would not write it this way, but always as ("hello" . "world").

However, ("hello"."world") is correctly read because the double qoutes
are delimiters.

Same with e.g. ("hello"("world")"!")


I hope I could clear up some smoke.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to