david <firstname.lastname@example.org> wrote:
| anonymous.c.lis...@gmail.com wrote:
| > He is talking about doing something like:
| > (read-from-string (format nil "(~a)" "go north"))
| > produces:
| > (go north)
| > Which in turn gets evaluated.
| > You convert the string into a lisp expression, then read it.
| thanks. it never occurred to me to use format like that.
| i was going to write a function to do that.
I tend to prefer this sort of style to that FORMAT hack:
> (with-input-from-string (s "go north")
(loop with eof = (list :eof)
for form = (read s nil eof)
until (eq form eof)
It gives you an easier handle on the intermediate forms, so you
can do some special processing, if you like, before (or instead of)
calling EVAL, e.g., rewriting CL:GO [which is what the above "GO"
really is!!] into MY-APP::MY-GO or something.
By the way, you might find OPFR useful for this sort of thing:
opfr> get-universal-time ; Functions look like "commands"
opfr> expt 2 100
opfr> list 1 2 :foo 4
(1 2 :FOO 4)
opfr> 37 ; Rewrites to avoid FUNCALLing single non-function values.
opfr> most-positive-fixnum ; Ditto)
 http://rpw3.org/hacks/lisp/opfr.lisp The library.
http://rpw3.org/hacks/lisp/opfr.cmucl Wrapper script for CMUCL.
http://rpw3.org/hacks/lisp/opfr.clisp Wrapper script for CLISP.
Rob Warnock <email@example.com>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607