Need help getting (eval ...) to work

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
pixelfck
Militia Captain
Militia Captain
Posts: 571
Joined: Tue Aug 11, 2009 8:47 pm
Location: Travelling around in Europe

Hi,

I'm trying to use the function (eval ...). So far, I do not get it to work. Or at least, I cannot get it to do anything useful.

Maybe I'm indoctrinated in my expectation based on other languages, maybe the function is bugged limited in functionality, maybe my brain just isn't compatible, in any case, I cannot figure it out.

Scenario:
I want the to run a string as code. The string is build from user input.

Example of what I would like to accomplish:

Code: Select all

(block (theInput)
    (setq theInput "(objAddItem gPlayerShip (itmCreate 0x00104006 1))")
    (printTo 'log (cat "eval result: " (eval theInput)))
    )
Desired outcome:
  • one &itDallSphere; added into the cargo hold of the player ship
  • a line in the log file saying:
    01/12/2015 21:12:21 eval result: True
Actual outcome:
  • a line in the log file saying:
    01/12/2015 21:12:21 eval result: No binding for symbol ["(objAddItem gPlayerShip (itmCreate 0x00104006 1))"] ### (eval theInput) ###
  • Pixelfck annoyed
I've tried all sorts of variation on the above code snipped. I've read the function description on xelerus, tried all sorts of other combinations... but nothing seems to trigger the engine in actually interpreting a string as TLisp.

So, what syntax lets (eval ...) evaluate a string as code?

~Pixelfck
Image
Download the Black Market Expansion from Xelerus.de today!
My other mods at xelerus.de
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

eval takes an expression tree:

Code: Select all

(eval (list 'add 2 2)) -> 4
(eval '(add 2 2)) -> 4
(eval '(add (divide 10 5) 2)) -> 4
If you want to convert a string into an expression tree, you can use link:

Code: Select all

(link "(add 2 2)") -> (add 2 2)
(eval (link "(add 2 2)")) -> 4
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

george moromisato wrote:eval takes an expression tree:

Code: Select all

(eval (list 'add 2 2)) -> 4
(eval '(add 2 2)) -> 4
(eval '(add (divide 10 5) 2)) -> 4
If you want to convert a string into an expression tree, you can use link:

Code: Select all

(link "(add 2 2)") -> (add 2 2)
(eval (link "(add 2 2)")) -> 4
Edit: This is classic Lisp behavior (http://en.wikipedia.org/wiki/Eval#Lisp), which doesn't mean that it's right. If eval were smarter it would take a string argument and attempt to convert it into an expression automatically.
User avatar
pixelfck
Militia Captain
Militia Captain
Posts: 571
Joined: Tue Aug 11, 2009 8:47 pm
Location: Travelling around in Europe

Thanks! that was the missing (link ...) I guess :-)

~Pixelfck
Image
Download the Black Market Expansion from Xelerus.de today!
My other mods at xelerus.de
Post Reply