newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Jeff on April 08, 2007, 06:09:52 AM

Title: Equate string to lambda
Post by: Jeff on April 08, 2007, 06:09:52 AM
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 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?
Title:
Post by: Jeff on April 08, 2007, 06:28:53 AM
Never mind. I solved it like this:



(eval-string (format "(lambda? %s:%s)" some-context some-string))
Title:
Post by: Jeff on April 09, 2007, 05:32:11 PM
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).