[Top][All Lists]

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

Re: new function

From: Taylan Kammer
Subject: Re: new function
Date: Thu, 23 Sep 2021 22:48:19 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

Responding to myself:

On 23.09.2021 22:27, Taylan Kammer wrote:

> I can't seem to find syntax-local-binding in Guile 2.2 or 3.0.  Did you
> have to import some special module, or are you using another version?

Worked when I imported (system syntax internal).

> Either way, I suspect that the following will not work with your macro:
>   (let ()
>     (let ()
>       (<$ x 1))
>     (display x)
>     (newline))

Indeed it doesn't work, though for a different reason:

  While compiling expression:
  Syntax error:
  unknown file:43:8: body should end with an expression in form (let () (<$ x 

That's because indeed the inner let expands into:

  (let ()
    (define x 1))

And there has to be at least one expression after the define.  So I tried:

  (let ()
    (let ()
      (<$ x 1)
    (display x)

And as I expected, it says 'x' is unbound:

  ;;; <stdin>:44:45: warning: possibly unbound variable `x'
  <$ : global scope : x
  ice-9/boot-9.scm:1685:16: In procedure raise-exception:
  Unbound variable: x

The only way it will work is if you never use nested scopes, but that will
lead to very strange Scheme code, and there will probably be many cases
where you accidentally use a nested scope without immediately noticing it.

Note also that definitions aren't allowed everywhere.  Consider this:

  (let ()
    (if 'whatever
        (<$ x 1)
        (<$ x 2))
    (display x)

It leads to:

  While compiling expression:
  Syntax error:
  unknown file:49:17: definition in expression context, where definitions are 
not allowed, in form (define x 1)

Because the arms of 'if' aren't allowed to be definitions.


reply via email to

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