El 14/01/2018 03:30, "PositronPro" <[email protected]>
escribió:
>
>
> Hi, all
>
> I want the below code to return
> 2nd & 1st list element from the argument provided to the describe-path
function but it returns NIL in their place.

Do you want your function to return just 2nd & 1st of the parameter list
(maybe as a list) or the full text list with 3nd & 1st elements of passed
list inserted in between the text?

> (de describe-path (Path)
> '(1st text `(cadr Path) 2nd text `(car Path) 3rd text.) )

Up to my understanding your function defined that way should return a
literal list because you're quoting,  it returns:

(1st text `(cadr Path) 2nd text `(car Path) 3rd text.)

Whatever being the argument you pass

> #run the function
> (describe-path '(first second third))
> -> 1st text NIL 2nd text NIL 3rd text
> #output has NIL?

I don't know why it returns such a NIL value  it should return always the
same and so does common lisp

(describe-path '(first second third))
-> (1st text `(cadr Path) 2nd text `(car Path) 3rd text.)
(describe-path 'D)
-> (1st text `(cadr Path) 2nd text `(car Path) 3rd text.)

maybe picolisp has a kind of ` reader macro that expands when reading text
and thus evaluates `(cadr Path) in an environment where parameter Path is
not yet defined and thus yields to nil

Sure Alex can explain in order we all learn a bit more ;)

>
> But below code works fine
> (setq newList '(1st 2nd 3rd))
> '(some text `(car newList) more text `(cadr newList) end text)
> -> some text 1st more text 2nd end text
Again this not work that way in common lisp so I pretty sure in picolisp `
is a reader macro who expands while reading and evaluates the expression.
That's the reason for this to work in REPL where newList is defined when
calling ` macro but not inside a function where the parameter is not
defining at the time of ` macro expansion

>
> The describe-path function is a rough translation of the code below
>
> (defun describe-path (path) `(there is a ,(second path) going ,(first
path) from here -))

This function has nothing in common with previous one.

In your previous function you returned a quoted (') list so everything
within is unevaluated

But this function returns a quasiquoted (`) list which is a completely
different thing, it returns a quoting list (thus unevaluated) BUT
evaluating expressions preceding by ,

So this second function evaluates the call to functions second and first
yielding the desired result

So if you want to achieve the behavior of last function you should define
it that way:

(de describe-path (Path)
`(1st text ,(cadr Path) 2nd text ,(car Path) 3rd text.) )

>
> Some help will be appreciated.
> Thanks in advance.

Reply via email to