Re: Quick question: eval and read-from-string scoping
- From: Jeremy Smith <nospamjeremy@xxxxxxxxxxxxxx>
- Date: Fri, 30 Dec 2005 00:24:11 GMT
Tin Gherdanarra <tinman31337@xxxxxxxxx> wrote in
news:41j4tfF1cpgeiU1@xxxxxxxxxxxxxx:
> Jeremy Smith wrote:
>> Hi,
>>
>> When I run this code in CLisp:
>>
>> (let ((left 5) (top 10))
>> (eval(read-from-string "(eq left (margin top
>> 20))")))
>>
>> When executed, it complains that "*** - EVAL: variable left has no
>> value". At first I wondered why the local variables were not in scope
>> for the eval'd code and was going to post, but I found this thread:
>
> (eval) gets its own scope. It would be nice if you could pass
> the current environment with all its local variables to eval.
> However, I don't know a way to do this.
Ah, okay, thanks for the confirmation.
> What you might use is
> closures, but they more or less just replace global variables
> with global functions.
I understand the idea. I think the best thing will be something in one of
the other posts, about eval'ing the code with the variables and initial
values inserted before the code.
> (let ((left 5)) (top 10))
> (defun get-left nil left)
> (defun get-top nil top)
> (eval (read-from-string "(eq left top)")))
>> Finally, my reasons for knowing this is that I am implementing a
>> small description language for OCR (optical character recognition)
>> software but I'm implementing it in Lisp before I write a parser, so
>> I 'eval' the descriptions as if read in from a text file. The reason
>> I need to be able to pass data to the eval'd code is because they are
>> the attributes of the current character object (such as
>> top,bottom,left,right) and thus should not be global.
>
> You could make lisp your declaration language. Syntax sucks anyway.
> If your program is used and extended for a long time, the syntax
> will grow. After a few years today's improvisations will haunt
> you and will force you and your users to live with cruft.
I suppose you're saying to use Lisp as the language. That sounds like a
good idea, partly because it has minimal syntax, as long as I can get
around the problem of malicious code. Also, it's not necessarily "today's
improvisations" - I'm just experimenting at the moment, and nothing is
set in stone. The basic idea is to get it working first. Also, I'm going
to read On Lisp once it works enough to be improved.
Thanks for your help, have a happy new year!
Cheers,
Jeremy.
.
- References:
- Quick question: eval and read-from-string scoping
- From: Jeremy Smith
- Re: Quick question: eval and read-from-string scoping
- From: Tin Gherdanarra
- Quick question: eval and read-from-string scoping
- Prev by Date: Re: Quick question: eval and read-from-string scoping
- Next by Date: Re: Python and Lisp Test
- Previous by thread: Re: Quick question: eval and read-from-string scoping
- Next by thread: Re: Quick question: eval and read-from-string scoping
- Index(es):
Relevant Pages
|