Re: Eval in Haskell

[Moving to cafe, this is only barely Haskell-related.] On Sun, Jun 01, 2003 at 04:16:36PM -0700, oleg@pobox.com wrote:
Eval of the kind let x = 1 in eval "x" is plainly an abomination.
I agree, though not because of the optimization issues but rather as a matter of principle: a closed variable should be _closed_, it should not be visible to anything but the body of the let-expression that binds it. And an externally acquired eval-able expression is definitely "anything but". Nevertheless, this abomination is supported even by some scheme implementations: guile> (define local-environment (procedure->syntax (lambda (exp env) env))) guile> (define (eval-where-x-bound exp) ... (let ((x 'foo)) (local-eval exp (local-environment)))) guile> (eval-where-x-bound '(list 'x x)) (x foo)
Incidentally, restricting eval to top-level or "standard" bindings is not a significant limitation. It is, in general, a very good practice to apply eval to closed expressions only.
This depends entirely on what you want to achive with eval, so I don't think the "in general" is justified. If you just want to evaluate closed expressions whose results are printable and readable, then you really just have an embedded interpreter which happens to read the same language as your source code. On the other hand, it is common for perl programs and especially shell scripts to eval configuration files with the explicit purpose that the configuration file may alter variables which are bound in the main program. For such usage, it is essential that the main program and the evaled file access the same enviroment. (Naturally a configuration file shouldn't be allowed to mess with _everything_ in the main program, but I don't think perl allows detailed adjustment of the bindings in the environment. Some schemes do, though.) Lauri Alanko la@iki.fi

In article <20030601235255.GA4498@la.iki.fi>, Lauri Alanko
Nevertheless, this abomination is supported even by some scheme implementations:
guile> (define local-environment (procedure->syntax (lambda (exp env) env))) guile> (define (eval-where-x-bound exp) ... (let ((x 'foo)) (local-eval exp (local-environment)))) guile> (eval-where-x-bound '(list 'x x)) (x foo)
Guile seems to be a bit "sloppy" in general. I think it just keeps a dictionary of symbol bindings and passes it around at runtime. guile> (eval '(define b 5)) guile> b 5 -- Ashley Yakeley, Seattle WA

[We now have lost all pretence of topicality] On Sun, Jun 01, 2003 at 08:43:03PM -0700, Ashley Yakeley wrote:
Guile seems to be a bit "sloppy" in general. I think it just keeps a dictionary of symbol bindings and passes it around at runtime.
guile> (eval '(define b 5)) guile> b 5
This particular kind of sloppiness is pretty common in Scheme REPLs: la:~$ kawa #|kawa:1|# (eval '(define b 5)) #|kawa:2|# b 5 #|kawa:3|# la:~$ mzscheme Welcome to MzScheme version 204, Copyright (c) 1995-2003 PLT
(eval '(define b 5)) b 5
la:~$ bigloo ------------------------------------------------------------------------------ Bigloo (2.5c) ,--^, `a practical Scheme compiler' _ ___/ /|/ Wed Nov 27 10:49:16 CET 2002 ,;'( )__, ) ' Manuel Serrano ;; // L__. email: ' \ / ' Manuel.Serrano@sophia.inria.fr ^ ^ ------------------------------------------------------------------------------ Welcome to the interpreter 1:=> (eval '(define b 5)) b 1:=> b 5 1:=> la:~$ mit-scheme Scheme Microcode Version 14.9 MIT Scheme running under GNU/Linux Type `^C' (control-C) followed by `H' to obtain information about interrupts. Scheme saved on Tuesday June 18, 2002 at 2:26:05 AM Release 7.7.1 Microcode 14.9 Runtime 15.1 SF 4.40 Liar (Intel i386) 4.115 Edwin 3.112 1 ]=> (eval '(define b 5) system-global-environment) ;Value: b 1 ]=> b ;Value: 5 1 ]=> End of input stream reached Happy Happy Joy Joy. ... though admittedly it's a bit confusing, since "define" either binds or assigns to a variable, depending on whether it was already bound. Lauri Alanko la@iki.fi
participants (2)
-
Ashley Yakeley
-
Lauri Alanko