public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Using eval with environments and R7RS modules
@ 2020-11-30  6:21 Duncan Mak
  2020-11-30  6:35 ` Per Bothner
  2020-11-30 10:13 ` Damien MATTEI
  0 siblings, 2 replies; 10+ messages in thread
From: Duncan Mak @ 2020-11-30  6:21 UTC (permalink / raw)
  To: kawa mailing list

Hello all,

I'm trying to use EVAL in a R7RS module. I'm having trouble specifying the
environment that contains the current bindings.

I could either use (environment '(scheme base)), but I don't see my own
functions, or (environment '(my library)) then I don't see something basic
like QUASIQUOTE.

Is there a way for me to load multiple modules into the environment?

Thanks!

-- 
Duncan.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using eval with environments and R7RS modules
  2020-11-30  6:21 Using eval with environments and R7RS modules Duncan Mak
@ 2020-11-30  6:35 ` Per Bothner
  2020-11-30  8:12   ` Duncan Mak
  2020-11-30 10:13 ` Damien MATTEI
  1 sibling, 1 reply; 10+ messages in thread
From: Per Bothner @ 2020-11-30  6:35 UTC (permalink / raw)
  To: Duncan Mak, kawa mailing list

On 11/29/20 10:21 PM, Duncan Mak via Kawa wrote:
> I'm trying to use EVAL in a R7RS module. I'm having trouble specifying the
> environment that contains the current bindings
> 
> I could either use (environment '(scheme base)), but I don't see my own
> functions, or (environment '(my library)) then I don't see something basic
> like QUASIQUOTE.
> 
> Is there a way for me to load multiple modules into the environment?

One possible work-around is to have (my library) explicitly export
the symbols that you need from (scheme base).
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using eval with environments and R7RS modules
  2020-11-30  6:35 ` Per Bothner
@ 2020-11-30  8:12   ` Duncan Mak
  2020-11-30 12:30     ` Per Bothner
  0 siblings, 1 reply; 10+ messages in thread
From: Duncan Mak @ 2020-11-30  8:12 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa mailing list

Thanks for the tip, Per.

That did tie me over, but it doesn't feel like a great way to fix it.

Would the right thing to do be to allow something like this?

(environment '((scheme base) (my library) ...))


Duncan.

On Mon, Nov 30, 2020 at 1:35 AM Per Bothner <per@bothner.com> wrote:

> On 11/29/20 10:21 PM, Duncan Mak via Kawa wrote:
> > I'm trying to use EVAL in a R7RS module. I'm having trouble specifying
> the
> > environment that contains the current bindings
> >
> > I could either use (environment '(scheme base)), but I don't see my own
> > functions, or (environment '(my library)) then I don't see something
> basic
> > like QUASIQUOTE.
> >
> > Is there a way for me to load multiple modules into the environment?
>
> One possible work-around is to have (my library) explicitly export
> the symbols that you need from (scheme base).
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/
>


-- 
Duncan.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using eval with environments and R7RS modules
  2020-11-30  6:21 Using eval with environments and R7RS modules Duncan Mak
  2020-11-30  6:35 ` Per Bothner
@ 2020-11-30 10:13 ` Damien MATTEI
  2020-11-30 12:21   ` Per Bothner
  1 sibling, 1 reply; 10+ messages in thread
From: Damien MATTEI @ 2020-11-30 10:13 UTC (permalink / raw)
  To: kawa

hello,

i rarely use EVAL but i recently wrote a function using eval inside and 
i was surprised to see that the arguments of the function

where not known from EVAL:

(define (foo L)

    (eval L (interaction-environment))

and i got an error like UNBOUND VARIABLE L

but this not only in Kawa,it is in Scheme, i was in a R5RS , if there is 
a way to know the current bindings from EVAL i will be happy

to know it, because without this , i do not see any use for EVAL , 
having only the toplevel bindings is not enought for development.

Damien

Le 30/11/2020 à 07:21, Duncan Mak via Kawa a écrit :
> Hello all,
>
> I'm trying to use EVAL in a R7RS module. I'm having trouble specifying the
> environment that contains the current bindings.
>
> I could either use (environment '(scheme base)), but I don't see my own
> functions, or (environment '(my library)) then I don't see something basic
> like QUASIQUOTE.
>
> Is there a way for me to load multiple modules into the environment?
>
> Thanks!
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using eval with environments and R7RS modules
  2020-11-30 10:13 ` Damien MATTEI
@ 2020-11-30 12:21   ` Per Bothner
  2020-11-30 18:09     ` Damien MATTEI
  0 siblings, 1 reply; 10+ messages in thread
From: Per Bothner @ 2020-11-30 12:21 UTC (permalink / raw)
  To: Damien.Mattei, kawa

On 11/30/20 2:13 AM, Damien MATTEI wrote:
> (define (foo L)
> 
>     (eval L (interaction-environment))
> 
> and i got an error like UNBOUND VARIABLE L
> 
> but this not only in Kawa,it is in Scheme, i was in a R5RS ,

The eval functon is really not compatible with lexical scoping, at least
not unless you use a different evaluation strategy which make Scheme
run much slower and use more memory. And that would be all the time,
not just when eval is used (possibly unless you made eval a special
syntax the compiler could recognize, rather than a procedure).

Scheme from the very beginning has focused on lexical scoping and
being able to compile it to efficient code:

https://en.wikisource.org/wiki/Lambda_Papers

> if there is a way to know the current bindings from EVAL i will be happy

Dynamic bindings, yes, but lexical bindings, no.  And that won't change.

> to know it, because without this , i do not see any use for EVAL ,

I've many times said there is very little use for eval, and that too many
people overuse it.

If you think you have a good use for eval, you're probably wrong.

> having only the toplevel bindings is not enought for development.

If you mean that eval is not very useful for debugging, that is true.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using eval with environments and R7RS modules
  2020-11-30  8:12   ` Duncan Mak
@ 2020-11-30 12:30     ` Per Bothner
  2020-11-30 22:15       ` Duncan Mak
  0 siblings, 1 reply; 10+ messages in thread
From: Per Bothner @ 2020-11-30 12:30 UTC (permalink / raw)
  To: Duncan Mak; +Cc: kawa mailing list

On 11/30/20 12:12 AM, Duncan Mak wrote:
> Thanks for the tip, Per.
> 
> That did tie me over, but it doesn't feel like a great way to fix it.
> 
> Would the right thing to do be to allow something like this?
> 
> (environment '((scheme base) (my library) ...))

No, but I just realized you should be able to do:

(environment '(scheme base) '(my library) ...)

-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using eval with environments and R7RS modules
  2020-11-30 12:21   ` Per Bothner
@ 2020-11-30 18:09     ` Damien MATTEI
  2020-12-02 14:58       ` Jamison Hope
  0 siblings, 1 reply; 10+ messages in thread
From: Damien MATTEI @ 2020-11-30 18:09 UTC (permalink / raw)
  To: kawa

yes Per i almost never use EVAL, i finally find a better solution than 
with EVAL in the macro i was writting.

I needed to EVAL a quoted argument of a macro but ,it was finally useless.


Le 30/11/2020 à 13:21, Per Bothner a écrit :
> On 11/30/20 2:13 AM, Damien MATTEI wrote:
>> (define (foo L)
>>
>>     (eval L (interaction-environment))
>>
>> and i got an error like UNBOUND VARIABLE L
>>
>> but this not only in Kawa,it is in Scheme, i was in a R5RS ,
>
> The eval functon is really not compatible with lexical scoping, at least
> not unless you use a different evaluation strategy which make Scheme
> run much slower and use more memory. And that would be all the time,
> not just when eval is used (possibly unless you made eval a special
> syntax the compiler could recognize, rather than a procedure).
>
> Scheme from the very beginning has focused on lexical scoping and
> being able to compile it to efficient code:
>
> https://en.wikisource.org/wiki/Lambda_Papers
>
>> if there is a way to know the current bindings from EVAL i will be happy
>
> Dynamic bindings, yes, but lexical bindings, no.  And that won't change.
>
>> to know it, because without this , i do not see any use for EVAL ,
>
> I've many times said there is very little use for eval, and that too many
> people overuse it.

strange that the SICP cover book put the couple EVAL / APPLY as 
important notion, APPLY seems more usefull,

i will try to find examples in the french edition of this book i have

>
> If you think you have a good use for eval, you're probably wrong.
for now no, but i just discover i have to rewrite code that only works 
in toplevel (Gasp...)
>
>> having only the toplevel bindings is not enought for development.
>
> If you mean that eval is not very useful for debugging, that is true.


Damien


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using eval with environments and R7RS modules
  2020-11-30 12:30     ` Per Bothner
@ 2020-11-30 22:15       ` Duncan Mak
  0 siblings, 0 replies; 10+ messages in thread
From: Duncan Mak @ 2020-11-30 22:15 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa mailing list

(environment '(scheme base) '(my library) ...) - this is working out for
me, thanks!

On Mon, Nov 30, 2020 at 7:30 AM Per Bothner <per@bothner.com> wrote:

> On 11/30/20 12:12 AM, Duncan Mak wrote:
> > Thanks for the tip, Per.
> >
> > That did tie me over, but it doesn't feel like a great way to fix it.
> >
> > Would the right thing to do be to allow something like this?
> >
> > (environment '((scheme base) (my library) ...))
>
> No, but I just realized you should be able to do:
>
> (environment '(scheme base) '(my library) ...)
>
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/
>


-- 
Duncan.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using eval with environments and R7RS modules
  2020-11-30 18:09     ` Damien MATTEI
@ 2020-12-02 14:58       ` Jamison Hope
  2020-12-04  8:05         ` Damien MATTEI
  0 siblings, 1 reply; 10+ messages in thread
From: Jamison Hope @ 2020-12-02 14:58 UTC (permalink / raw)
  To: kawa

On Mon, Nov 30, 2020 at 1:09 PM Damien MATTEI <damien.mattei@oca.eu> wrote:

>
> strange that the SICP cover book put the couple EVAL / APPLY as
> important notion, APPLY seems more usefull,


FWIW, I would point out that SICP is *not* a book on how to program in
Scheme. It uses Scheme, yes, but much like the pseudo code in CLRS, it’s
just as an easy-to-understand syntax for presenting concepts about
programming. We did have to write and run some programs in 6.001 on actual
computers for homework, but most of the work was done on paper or a
chalkboard. (There were no computers in the room for the final exam.)

The pair of EVAL/APPLY presented the two stages of *Interpreting* a
Computer Program using the environment model: after parsing the Structure
(which for Lisp just means turning text with parentheses into a list of
atoms and lists — I don’t recall SICP mentioning vector literals, but it’s
been a while), the two steps to interpret the program — to decide what the
program’s result is — are to evaluate the car of the list to see what
function it represents, then evaluate each function argument, and then to
apply the function to its arguments (each of those EVAL steps might entail
recursively EVAL/APPLYing an inner function application). There’s a little
more to it to handle special forms like IF which don’t evaluate every
argument first, but that’s the essence of the model.

This was really a mental exercise, not a description of how a real physical
computer does or should work. The chapter on register machines and
compilation addresses the fact that in reality we don’t need to use EVAL to
look up each variable at runtime, because we can precompute where that
variable resides in the stack based on where it was defined (see the
section called “Lexical Addressing”).


>
>
> Damien
>
> -JH

-- 
Jamison Hope

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Using eval with environments and R7RS modules
  2020-12-02 14:58       ` Jamison Hope
@ 2020-12-04  8:05         ` Damien MATTEI
  0 siblings, 0 replies; 10+ messages in thread
From: Damien MATTEI @ 2020-12-04  8:05 UTC (permalink / raw)
  To: kawa


Le 02/12/2020 à 15:58, Jamison Hope a écrit :
> On Mon, Nov 30, 2020 at 1:09 PM Damien MATTEI <damien.mattei@oca.eu> wrote:
>
>> strange that the SICP cover book put the couple EVAL / APPLY as
>> important notion, APPLY seems more usefull,
>
> FWIW, I would point out that SICP is *not* a book on how to program in
> Scheme. It uses Scheme, yes, but much like the pseudo code in CLRS, it’s
> just as an easy-to-understand syntax for presenting concepts about
> programming. We did have to write and run some programs in 6.001 on actual
> computers for homework, but most of the work was done on paper or a
> chalkboard. (There were no computers in the room for the final exam.)
>
> The pair of EVAL/APPLY presented the two stages of *Interpreting* a
> Computer Program using the environment model: after parsing the Structure
> (which for Lisp just means turning text with parentheses into a list of
> atoms and lists — I don’t recall SICP mentioning vector literals, but it’s
> been a while), the two steps to interpret the program — to decide what the
> program’s result is — are to evaluate the car of the list to see what
> function it represents, then evaluate each function argument, and then to
> apply the function to its arguments (each of those EVAL steps might entail
> recursively EVAL/APPLYing an inner function application). There’s a little
> more to it to handle special forms like IF which don’t evaluate every
> argument first, but that’s the essence of the model.

i was just trying some sort of coding, for evaluating a postfix expression :

i started with recusively EVALuating all but unfortnately it worked only 
at TOPLEVEL

and finally 3 page of wrong code with EVAL where replaced by a single 
special form:

;; (define x 7)

;; (postfix ((2 (3 2 +) *) x +)) -> 17

;; (let ((x 7)) (postfix ((2 (3 2 +) *) x +))) -> 17
(define-syntax postfix (syntax-rules ()

                ((_ (a ... op)) ((postfix op) (postfix a) ...))
                ((_ a) a) ;; MUST be here not before to avoid ambigious call
                ;; misenterpreting a = (a ... op)

                ))

> This was really a mental exercise, not a description of how a real physical
> computer does or should work. The chapter on register machines and
> compilation addresses the fact that in reality we don’t need to use EVAL to
> look up each variable at runtime, because we can precompute where that
> variable resides in the stack based on where it was defined (see the
> section called “Lexical Addressing”).
>
>
>>
>> Damien
>>
>> -JH

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-12-04  8:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30  6:21 Using eval with environments and R7RS modules Duncan Mak
2020-11-30  6:35 ` Per Bothner
2020-11-30  8:12   ` Duncan Mak
2020-11-30 12:30     ` Per Bothner
2020-11-30 22:15       ` Duncan Mak
2020-11-30 10:13 ` Damien MATTEI
2020-11-30 12:21   ` Per Bothner
2020-11-30 18:09     ` Damien MATTEI
2020-12-02 14:58       ` Jamison Hope
2020-12-04  8:05         ` Damien MATTEI

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).