stuck in eval..

Started by newdep, June 16, 2007, 11:15:31 AM

Previous topic - Next topic

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

#1
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

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


(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

#3
WHA! ;-)



You just cracked an egg ;-)  



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

newdep

#4
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

#5
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

#6
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