stuck in eval..

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

stuck in eval..

Post by newdep »

Hi Lutz,

Im confused currently why the code below does not work..

Actualy what I want is to replace inside a nexted-list a variable
if use 'REF for this and it returns ( 9 2 4 2). I also use 'ref because
'ref is the only function that returns an index from a nested list.

Oke now I have a list containing the indexes.. But only net-set and set-nth can
work with nested lists... right?..
(i could not get 'replace to fix it..)


So if I want to use 'set-nth/nth-set im doing this, but set-nth doesn't eat it... ->

>(setq x (cons 'YY (ref 'XX 'YY)))
(YY 9 2 4 2)
> x
(YY 9 2 4 2)

>(set-nth x 'QQ)
value expected in function set-nth : x


If set-nth is unable to evaluate the index-x how do I replace
inside a nested-list an index found with 'ref?


Regards, Norman.
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

I fixed it by using pop and push... allitle more code but works nice ;-)
but i prefer a more direct way on this if i.e. set-nth would be able to handle it ;-)
-- (define? (Cornflakes))

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

I think you use implicit indexing to modify list elements in nested lists via reference lists:

Code: Select all

(set 't '(a 0 (a 1 (b 2 3 4 (c 5 6 7)))))

(println t)

;-> (a 0 (a 1 (b 2 3 4 (c 5 6 7))))

(set 'r (ref 'c t))

(set-nth (t r) 1311234123)

(println t)

;-> (a 0 (a 1 (b 2 3 4 (1311234123 5 6 7))))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

WHA! ;-)

You just cracked an egg ;-)

I realy did not think of that .. thanks!
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

What is the difference then actualy?


The manual says this i.e. ->

(set 'aList '(a b (c d (e f g) h) i))
(nth-set (aList 2 2 0) 'x)

Then I would think, logicaly that this also would work ->

(set 'aList '(a b (c d (e f g) h) i))
(set-nth (cons 'aList (ref 'e aList)) 'x)

because (cons 'aList (ref 'e aList)) returns (aList 2 2 0) too
and is also a list and a reference-list because
(eval (cons 'aList (ref 'e aList))) returns 'e too

Mmmm...odd.. ;-)
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Mmm OKe for now it looks like set-nth does not evaluate its (list) but
expects a static ref list indeed... pitty...
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

The parentheses around (aList 2 2 0) are part of the syntax of set-nth/nth-set. Just like they are in (dolist (x lst) ...).

Lutz

Locked