Equate string to lambda

Started by Jeff, April 08, 2007, 06:09:52 AM

Previous topic - Next topic

Jeff

I have input as a string.  It will eventually be eval'd, but I want to verify that it is a lambda defined in a particular context - not necessarily the current context - before running it (i.e. to make sure that it was not code mapped in).  The idea is to map segments of a url to definitions in a particular context.  So, if I have a url like http://www.something.com/blah/yadda/foo/bar">www.something.com/blah/yadda/foo/bar, it would verify that "blah" is a lambda in, for example, the context 'webpages, and then, if it is, eval something like (blah 'yadda 'foo 'bar).  If I convert blah then to a symbol, it can only be validated as a symbol, and I obviously don't want to do something like (catch (eval "blah")), because that evals it without validation.  And on top of that, I have a symbol (say, 'uri-seg1'), pointing to "blah".  I'm a bit confused :(.  Anyone have any advice?
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Jeff

#1
Never mind. I solved it like this:



(eval-string (format "(lambda? %s:%s)" some-context some-string))
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Jeff

#2
Just as a note, this technique is not safe for live site use. A person could put lisp syntax into the url and that would put the onus on the programmer to filter out lisp keywords.



The safe way to map urls to functions is to manually map them (i.e. a-la-django, where regexp strings are equated to functions).
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code