chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] compile-time eval-time mismatch


From: Michele Simionato
Subject: Re: [Chicken-users] compile-time eval-time mismatch
Date: Wed, 8 Dec 2004 10:52:44 -0500

For future reference of other people confused by eval-when:

$ cat eval-when.sh
echo "************ case 0: eval-when () ***********************************"
echo '
(eval-when ()
  (print "... ok"))
' > tmp.scm
echo  "interpreting ..."; csi -script tmp.scm
echo  "compiling ...   "; csc tmp.scm 
echo  "running ...     "; tmp     


echo "************ case 1: eval-when (eval) *******************************"
echo '
(eval-when (eval)
  (print "... ok"))
' > tmp.scm
echo  "interpreting ..."; csi -script tmp.scm
echo  "compiling ...   "; csc tmp.scm 
echo  "running ...     "; tmp     


echo "************ case 2: eval-when (compile) ****************************"
echo '
(eval-when (compile)
  (print "... ok"))
' > tmp.scm
echo  "interpreting ..."; csi -script tmp.scm
echo  "compiling ...   "; csc tmp.scm 
echo  "running ...     "; tmp     


echo "************ case 3: eval-when (load) *******************************"
echo '''
(eval-when (load)
  (print "... ok"))
''' > tmp.scm
echo  "interpreting ..."; csi -script tmp.scm
echo  "compiling ...   "; csc tmp.scm 
echo  "running ...     "; tmp     


echo "************ case 4: eval-when (eval compile) ***********************"
echo '''
(eval-when (compile eval)
  (print "... ok"))
''' > tmp.scm
echo  "interpreting ..."; csi -script tmp.scm
echo  "compiling ...   "; csc tmp.scm 
echo  "running ...     "; tmp     



echo "************ case 5: eval-when (compile load) ***********************"
echo '''
(eval-when (compile load)
  (print "... ok"))
''' > tmp.scm
echo  "interpreting ..."; csi -script tmp.scm
echo  "compiling ...   "; csc tmp.scm 
echo  "running ...     "; tmp     


echo "************ case 6: eval-when (eval load) **************************"
echo '''
(eval-when (load eval)
  (print "... ok"))
''' > tmp.scm

echo  "interpreting ..."; csi -script tmp.scm
echo  "compiling ...   "; csc tmp.scm 
echo  "running ...     "; tmp     


echo "************ case 7: eval-when (eval compile load) ******************"
echo '''
(eval-when (compile load eval)
  (print "... ok"))
''' > tmp.scm
echo  "interpreting ..."; csi -script tmp.scm
echo  "compiling ...   "; csc tmp.scm 
echo  "running ...     "; tmp     

Executing the script makes clear what is happening:

$ bash eval-when.sh
************ case 0: eval-when () ***********************************
interpreting ...
compiling ...   
running ...     
************ case 1: eval-when (eval) *******************************
interpreting ...
... ok
compiling ...   
running ...     
************ case 2: eval-when (compile) ****************************
interpreting ...
compiling ...   
... ok
running ...     
************ case 3: eval-when (load) *******************************
interpreting ...
compiling ...   
running ...     
... ok
************ case 4: eval-when (eval compile) ***********************
interpreting ...
... ok
compiling ...   
... ok
running ...     
************ case 5: eval-when (compile load) ***********************
interpreting ...
compiling ...   
... ok
running ...     
... ok
************ case 6: eval-when (eval load) **************************
interpreting ...
... ok
compiling ...   
running ...     
... ok
************ case 7: eval-when (eval compile load) ******************
interpreting ...
... ok
compiling ...   
... ok
running ...     
... ok

So, the issue of evaluation times is clear (even if I would have
implemented things differently, with two independent mechanism,
say a construct "execute-at-compile-time" and a global variable
"this-code-is-being-run-by-the-interpreter"). But I guess eval-when
is known to lispers and it is arguably fine for them.

What I regard as a bug is the fact that the evaluator works differently at
load time: as Felix pointed out, define-macro is not recognized by the 
evaluator at load time, so a script like this

$ cat eval-define-macro.scm 
echo "eval"
echo "
(eval-when (eval)
  (eval '(define-macro (m x) x)))
" > tmp.scm
csc tmp.scm; tmp

echo "compile"
echo "
(eval-when (compile)
  (eval '(define-macro (m x) x)))
" > tmp.scm
csc tmp.scm; tmp

echo "load"
echo "
(eval-when (load)
  (eval '(define-macro (m x) x)))
" > tmp.scm
csc tmp.scm; tmp

has the following output:

$ bash eval-define-macro.sh
eval
compile
load
Error: unbound variable: x

tmp.scm: 3    eval

I would like to be sure instead that "eval" understands (at least) all
r5rs constructs
at all times.

         Michele Simionato




reply via email to

[Prev in Thread] Current Thread [Next in Thread]