Hi Manuel,

> Unfortunately Rick's solution form doesn't work. May be when calling the
> function the first thing is a string?
> This is what I'm trying:
> (de *FuncList ())

Are you sure? This sets *FuncList to (NIL), not to NIL

> (de defun1 F
>    (setq *FuncList (cons *FuncList (cons (car F) (caddr F))))
>    (def (car F) (cons (cadr F) (cadddr F))) )

This is also a bit strange.

   (setq *FuncList (cons *FuncList ...

Isn't it the case that you want:

   (setq *FuncList (cons ... *FuncList))

which can be written shorter as

   (push '*FuncList ..)


With your code, you end up with

   : *FuncList
   -> ((NIL) hola1 . "This is just a test (1)")

Is this desired?

> [manuel@arch ux]$ pil main.l -bye +
> Calling 'hola1'.
> Calling 'hola2'.
> Hola Otto

'hola1' doesn't work, because the function body is not right:

   : (pp 'hola1)
   (de hola1 (Str)
      "Hola "
      Str )
   -> hola1

See? 'prinl' is no longer called as a function.

> I was failing because in (def (car P) (cons (cadr P) (cdddr P))) ) I didn't
> put the first cons. When I try
> (de defun3 F
>    (setq *FuncList (cons *FuncList (cons (car F) (caddr F))))
>    (def (car F) (cadr F) (cadddr F)) )
>                          ^ Notice there isn't cons here
> I get:
> [main.l:29] !? (hola2 "Otto")
> hola2 -- Undefined
> And, unfortunately, I don't understand why it doesn't works. Why it needs
> to be a cons? In the docs it says def will set the symbol to "any", being
> "any" the third parameter. In my case, shouldn't be set to the parameter
> list?

'def' with three arguments sets a _property_.

If you want to define a function, you must set the _value_.

The reason for (def (car P) (cons (cadr P) (cdddr P))) is this:

'P' is

   (hola1 (Str) "This is just a test (1)" (prinl "Hola " Str))

So we have
   The CAR is 'hola1', which is the symbol
   The CADR is the function's paramter lsit (Str)
   The CADDR is the doc string is just a test (1)"
   The CDDDR is the function's body ((prinl "Hola " Str))


   : (cons (cadr P) (cdddr P))
   -> ((Str) (prinl "Hola " Str))

which is the desired funcion to be 'def'd as a value to 'hola1'.

♪♫ Alex

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

Reply via email to