On Sat, Jan 28, 2017 at 09:55:14PM +0100, pd wrote:
> Thank you Alex for your patience, I see I have a severe confussion about
> how picolisp manages lists

No problem! It is good to discuss this here, as it may help others too.

> let's start by the begining... as far as I know   (f a b 4)  is just a list
> equivalent to (f . (a . (b . (4 . NIL))))  and the fact being also a
> function call to function f applying parameters a b 4 is just a matter of
> "convention", simply when picolisp evals a list with a first item not being
> a number it supposes it's a function call and tries to evaluate first item
> (it doesn't matter if first item is a symbol or another list, it gets
> evaluated) which is supposed to be evaluated to a function value

That's right.

> With this point of view I understand what you mean when saying  (f 1 a b c)
> is just the same as (f 1 . (a b c)) and thus you can view a, b, c as a list


> so you can describe this funcion as (f num . 'lst), ok, but also I think
> ...
> you could describe the function f also as (f . 'lst) . The only difference

Yes, but without the quotes. As a function reference (f num . 'lst) is
impossible, as the quote indicates evaluation which is not handled by PicoLisp
this way.

> But if you describe a function like (g num 'lst) is a quite different thing
> because you are expecting two arguments the first one being a number and
> the second being a list (of unlimited number of items), really all


> functions described have an unlimited number of arguments but function g
> packs all arguments but the first in a list.

No. This is not done by 'g'. This function *expects* a list after evaluating its
second argument.

> >    (if (testSomething) (doSomething1) (doSomething2) (doSomething3))
> ...
> but this also means the only way to indicate several executable expressions
> in the "then-clause" is to surround them between parens, i.e.  (if (= 2 2)
> ((print "equal") (print "2")) (print "not equal") (print "not 2"))   I

No. This gives a crash (try it, and think about why ;).

The "then" clause must be a single expression. Typicaley you use 'prog'
if you need to call more than one expression here.

> appreciate here an absence of symmetry, you must pack all exe expressions

That's right.

> why not to define and describe function if in a symmetrical way as   (if
> 'any prg1 prg2)  even when not obeying parens economy?   (sure there is a
> good reason to do it that way simply I'm not able to see)

If 'if' were specified this way, it would lose its simplicity because you always
need additional nesting for the "then" clause.

For more complex conditional expressions, we use 'cond' instead of 'if'.

> - two functions f described this way:
>    (f num . lst)
>    (f num1 num2)
> then the list (f 1 2) is a valid call for both functions, the first f will
> bind first parameter to numer 1 and second parameter to list (2) (all
> remaining parameters as a list) while the second f will bind 1 to num1 and
> 2 to num2 (descarding empty list NIL).


> My confusion here is picolisp must
> do two pops to bind parameters for a first f function call but three pops
> to bind parameters for a second f function call. How discriminate picolisp
> between each cases? I suppose the answer is function definition:
> first f defined as (de f (X . Rest) (...) )
> second f defined as (de f (X Y) (...) )

Exactly. The interpreter finds either (X . Rest) or (X Y) when evaluating (f 1 
so it knows what to do.

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

Reply via email to