Email list hosting service & mailing list manager

Re: SRFI-212: aliasing to a *not yet* bound identifier, and modules/libraries. Marc Nieper-Wißkirchen (24 Oct 2020 22:26 UTC)

Re: SRFI-212: aliasing to a *not yet* bound identifier, and modules/libraries. Marc Nieper-Wißkirchen 24 Oct 2020 22:25 UTC


thanks for your interest in this SRFI.

Am So., 25. Okt. 2020 um 00:00 Uhr schrieb Jeronimo Pellegrini (via
srfi-212 list) <>:
> Hello,
> I was hoping to use aliases in a proposal for a rewrite of STklos'
> macro system, and I'd like to know what would be the expected behavior
> when I make an alias to an identifier that is not yet bound. Both Chez

At the moment, SRFI 212 says that the identifier that receives the
binding will be unbound as well.

> and Kawa seem to allow this, although Kawa issues a warning:
> Kawa:
> #|kawa:1|# (define-alias one two)
> /dev/tty:1:19: warning - no declaration seen for two
> #|kawa:2|#  (set! one 10)
> #|kawa:3|# two
> 10
> Chez:
> > (import (chezscheme))
> > (alias one two)
> > (set! one 10)
> > two
> 10
> I actually think this is useful (at least for me).

This is a test of Chez's REPL, whose semantics differ from those of a
top-level program. If this were part of a top-level program, you
wouldn't be able to "set!" an unbound identifier. (Moreover, Chez
doesn't allow to alias an unbound identifier there.)

As the REPL semantics is underspecified in the standard, SRFI 212
cannot say much here. In an implementation where every identifier is
initially conceptually bound (to some unspecified location) in a REPL,
you will get this behaviour with SRFI 212.

> Would it be a good idea to add this to the spec, or could it perhaps
> be a problem?
> For example,
> (let ((a 10))
>   (alias x b)
>   (let ((b 20))
>     x))          ;; error! x is an alias to global b

This would be no error if a global "b" was bound.

> However -- if between the second and third line on that code, for
> example, a thread sets a binding for global b, then I would expect
> that the code would return the new value of b, since x *is* a binding
> to "whatever binding b has at the moment in the global environment".
> Or is it not the idea?

The binding of "b" at the point where the "alias" definition occurs
counts. So if "b" is unbound there, "x" will be unbound there as well.

Note that "alias" does not make "x" and "b" equivalent. It just copies
the (lexical) binding at that point.

> Also, I suppose that if (alias x b) is done inside a module or library,
> and the alias is not to a locally created identifier, the binding should

Can you give an example? I think I understand but I am not 100% sure.

> refer to "b in that module/library" -- is that the intended behavior?
> Then, could it be made explicit in the SRFI text?

I can speak explicitly of "lexical bindings" in SRFI 212 if this helps.

> Thank you!

You're welcome!


> Jeronimo