[plt-scheme] + vs * in bytecode

From: Ryan Culpepper (ryan_sml at yahoo.com)
Date: Wed Feb 15 03:32:49 EST 2006

On 2/15/06, Chung-chieh Shan <ccshan at post.harvard.edu> wrote:
> Hello all,
>
> This is my first post to this group.  I apologize if I am expected to be
> able to find the answer to this question elsewhere.

Not at all; this is the perfect place for this sort of question.

> My students and I noticed that the expansion of the simple arithmetic
> expressions (+ 1 2) and (* 1 2) change depending on whether the EOPL
> language level is loaded.  If I expand
>
>     (require (lib "eopl.ss" "eopl"))
>     (+ 1 2)
>     (* 1 2)
>
> then I get
>
>     (#%app + (#%datum . 1) (#%datum . 2))
>     (#%app * (#%datum . 1) (#%datum . 2))
>
> but if I expand
>
>     (+ 1 2)
>     (* 1 2)
>
> then I get
>
>     (#%app (#%top . +) (#%datum . 1) (#%datum . 2))
>     (#%app (#%top . *) (#%datum . 1) (#%datum . 2))
>
> Why?

This has nothing to do with EOPL per se. If you replace
  (require (lib "eopl.ss" "eopl"))
with
  (require mzscheme)
you will see exactly the same expansion.

You're seeing the difference between top-level and required variables.

Without the require form, + and * are top-level variables, and so are
any variables that you introduce using define. When the macro-expander
hits a top-level variable, it tags it with the #%top form (like it
tags applications with #%app).

When you require a module (like mzscheme or EOPL) that provides
bindings for + and *, though, they become required variables, and the
macro-expander doesn't tag these.

There's some more information about this in Chapter 8 (Namespaces) of
the MzScheme Language Manual in the Help Desk.

Ryan


Posted on the users mailing list.