newLISP Fan Club

Forum => Whither newLISP? => Topic started by: cameyo on February 11, 2019, 10:33:07 AM

Title: Retrieving the value of a symbol
Post by: cameyo on February 11, 2019, 10:33:07 AM
These expressions generate an error:
(set '"name") -> ERR: symbol expected in function set : '"name"
(set (quote "name") 3) -> ERR: symbol expected in function set : '"name"

But the following are valid (then "name" is a valid symbol):
(setf '"name" 3) -> 3
(setq "name" 3) -> 3

Now the problem: how to retrieve the value of the symbol "name"?
(println "name") -> name
(setq a "name")
(println a) -> "name"

Thanks
Title: Re: Retrieving the value of a symbol
Post by: fdb on February 11, 2019, 12:20:33 PM
Hi, I presume you want to convert a string into a symbol , which can be done like this:

(set (sym "name") 3)

name ->3

If you however want to convert "name" including quotes into a symbol then use this code:

(set (sym {"name"}) 3)


and to retrieve the value from "name":

(eval (sym {"name"})) -> 3
Title: Re: Retrieving the value of a symbol
Post by: cameyo on February 11, 2019, 12:53:08 PM
You solve my question with:
(eval (sym {"name"})) -> 3
Thanks fdb :-)