Page 1 of 1

expand ('foo 'a)

Posted: Thu Oct 01, 2009 8:07 pm
by Fritz
Looking at the "expand" function in manual (http://www.newlisp.org/downloads/newlis ... tml#expand):

(set 'x 2 'a '(d e))
(set 'foo 'a)
(expand 'foo 'a) → (d e)
(expand '(a x b) 'x) → (a 2 b)
(expand '(a x (b c x)) 'x) → (a 2 (b c 2))
(expand '(a x (b c x)) 'x 'a) → ((d e) 2 (b c 2))

I have some strange results trying to repeat it. (expand 'foo 'a) gives me only "foo"

Posted: Thu Oct 01, 2009 8:53 pm
by Kazimir Majorinc
It is OK, because foo is expression that doesn't contain a, so there is nothing to expand. The fact that value of foo is a shouldn't matter.

So, error is in manual.

Expression (expand foo 'a) should evaluate to (d e). And it does.

Posted: Thu Oct 01, 2009 8:59 pm
by Fritz
Kazimir Majorinc wrote:...foo is expression that doesn't contain a, so there is nothing to expand.
Is there a way to expand "(d e)" from foo?

(expand foo 'a) works, but I suspect, it just shows us a.

Posted: Thu Oct 01, 2009 9:19 pm
by Lutz
yes, you can expand on the top level, but there is not much usage for that:

Code: Select all

> (set 'foo '(d e))
(d e)
> (expand foo 'foo)
(d e)
> 
but it would make sense here (not on the top level):

Code: Select all

> (set 'bar '(x foo y))
(x foo y)
> (expand bar 'foo)
(x (d e) y)
>
ps: the manual is corrected