Retrieving the value of a symbol

Pondering the philosophy behind the language

Retrieving the value of a symbol

Postby cameyo » Mon Feb 11, 2019 6:33 pm

These expressions generate an error:
Code: Select all
(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):
Code: Select all
(setf '"name" 3) -> 3
(setq "name" 3) -> 3

Now the problem: how to retrieve the value of the symbol "name"?
Code: Select all
(println "name") -> name

Code: Select all
(setq a "name")
(println a) -> "name"

Thanks
cameyo
 
Posts: 31
Joined: Sun Mar 27, 2011 3:07 pm

Re: Retrieving the value of a symbol

Postby fdb » Mon Feb 11, 2019 8:20 pm

Hi, I presume you want to convert a string into a symbol , which can be done like this:
Code: Select all
(set (sym "name") 3)

name ->3

If you however want to convert "name" including quotes into a symbol then use this code:
Code: Select all
(set (sym {"name"}) 3)


and to retrieve the value from "name":
Code: Select all
(eval (sym {"name"})) -> 3
fdb
 
Posts: 39
Joined: Sat Nov 09, 2013 8:49 pm

Re: Retrieving the value of a symbol

Postby cameyo » Mon Feb 11, 2019 8:53 pm

You solve my question with:
Code: Select all
(eval (sym {"name"})) -> 3

Thanks fdb :-)
cameyo
 
Posts: 31
Joined: Sun Mar 27, 2011 3:07 pm


Return to Whither newLISP?

Who is online

Users browsing this forum: No registered users and 1 guest

cron