newLISP Fan Club

Forum => newLISP in the real world => Topic started by: newdep on June 16, 2007, 11:15:31 AM

Title: stuck in eval..
Post by: newdep on June 16, 2007, 11:15:31 AM
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.
Title:
Post by: newdep on June 16, 2007, 12:33:23 PM
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 ;-)
Title:
Post by: cormullion on June 16, 2007, 01:34:44 PM
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))))
Title:
Post by: newdep on June 16, 2007, 02:26:58 PM
WHA! ;-)



You just cracked an egg ;-)  



I realy did not think of that .. thanks!
Title:
Post by: newdep on June 16, 2007, 02:44:27 PM
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.. ;-)
Title:
Post by: newdep on June 16, 2007, 02:53:55 PM
Mmm OKe for now it looks like set-nth does not evaluate its (list) but

expects a static ref list indeed... pitty...
Title:
Post by: Lutz on June 16, 2007, 03:23:05 PM
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