[Top][All Lists]

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

Re: local eval

From: Damien Mattei
Subject: Re: local eval
Date: Wed, 26 Apr 2023 21:27:38 +0200

hello Mikael,
hello Robby,

yes my infix evaluator _with_ precedence is more complex than evaluating a
single var. What became your macro Mikael in case of an expression? , in my
original code ,now, i'm passing all vars quoted, so i need to evaluate the
whole expression, because evaluating special form would fail (even if i can
remove special form) ok it all start with $nfx$ from SRFI 105 that i have
to define for operator precedence so there is some procedures  call by the
$nfx$ macro, i skip the details,it looks like that:

(define-syntax $nfx$
  (syntax-rules ()

    ((_ sexpr ...) (let ((env (the-environment)))

    (compute (infix-with-precedence2prefix (! (quote sexpr) ...)) env)))))

basically infix-with-precedence2prefix and ! and other procedures not
listed do the infix precedence conversion to prefix scheme and 'compute' do
the evaluation

(define (compute expr env)
  (display "evaluate : expr =") (display expr) (newline)
  ;;(eval expr2eval (interaction-environment)))
  (local-eval expr2eval env))

i just need the good macro that finally replace the last line:
(local-eval expr2eval env)

evaluate the expression expr2eval in the environment env, example of
(<+ x (<- y (+ (* 3 5) 2)))   ( was in infix SRFI 105: {x <+ y <- 3 * 5 +
2}  and in srfi 105 this expression is converted by the reader in: ($nfx$ x
<+ y <- 3 * 5 + 2)  )

so $nfx$ is here a macro that quote all the arguments to pass it to the
procedures and finally the result is evaluated. (there is other strategies
and version in my code that do only partial 'quoting or no 'quoting at all
but the more powerful (can deal special form and easily operator
overload,will be to quote all)


On Wed, Apr 26, 2023 at 7:25 PM Mikael Djurfeldt <>

> (However, I suspect that you didn't *really* mean (quote var) in your
> original code, or? If you didn't, then of course my simpler syntax-rules
> macro isn't what you want.)
> On Wed, Apr 26, 2023 at 7:20 PM Mikael Djurfeldt <>
> wrote:
>> How about:
>> (define-syntax eval-var
>>   (syntax-rules ()
>>     ((_ var) var)))
>> ?
>> Then you don't need to import (ice-9 local-eval) and re-export things
>> from there.
>> Just for elucidation:
>> The reason why we chose the syntax-case macro system for Guile was that
>> it *both* gives you hygiene *and* quite a lot of control. The reason why
>> the original code didn't work (your first post in this thread) is that
>> "(the-environment)" was expanded in the lexical context where it was
>> written (the Scheme+ module),
>> However, syntax-case gives you the ability to insert that identifier into
>> the context of the expansion instead:
>> (define-syntax eval-var
>>   (lambda (x)
>>     (syntax-case x ()
>>       ((_ var)
>>        (with-syntax ((the-environment (datum->syntax #'var
>> 'the-environment)))
>>          #'(let ((env (the-environment)))
>>               (local-eval (quote var) env)))))))
>> (It's the datum->syntax form which gives the lexical context of var to
>> the-environment.)

reply via email to

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