-
Notifications
You must be signed in to change notification settings - Fork 987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
weird cond expansion #835
Comments
R6RS specifies that each of the pieces of syntax in the else clause are an Since the default environment for
|
Got it. Thank you. Indeed when the cond is not in a definition position it works as I expected: But, even understanding the cause, the following still "feels" wrong: If instead of expanding (cond (else result1 result2 ...)) into (begin result1 result2 ...) Like: Thanks! |
It's worth noting that this behavior only appears for > (cond
[#f (define x 1234) x]
[else (define y 5678) y])
Exception: invalid context for definition (define x 1234)
> (cond
[#f (define x 1234) x])
Exception: invalid context for definition (define x 1234) Though I'm not sure if that's an argument for making only-child else branches behave as if there were other branches in the cond, or just saying "well don't write code that way" |
but this should not works: (foo) 7 |
Instead of detecting non-expression contexts, the macro could make sure that the result is an expression context. For example, It looks like Fixing |
I see that |
I remain unconvinced that anything is broken, even if it's a little strange. Both the r6rs and r7rs specs give definitions of I'm a bit hesitant about any non-backwards-compatible change that makes previously valid code no longer valid, absent a major version number change. It does seem rather unlikely that something is relying on this specific behavior, though. |
On Fri, May 24, 2024 at 12:59 AM Jamie Taylor ***@***.***> wrote:
I remain unconvinced that anything is *broken*, even if it's a little
strange.
It may not be formally broken, but it leaves undetected an error which
could be detected and reported at no cost.
Message ID: ***@***.***>
… |
Hello,
this expansion is surprising:
> (expand '(cond (else (define x 7) x)))
(begin (set! x 7) x)
No difference between cond from chezscheme or from rnrs.
If I understand correctly the spec, in R6RS it's an error.
It would be better to either make all cond branches bodies, as Racket does, or raise an error.
As it is now:
> (cond (else (define x 7) x))
7
> x
7
Cheers
The text was updated successfully, but these errors were encountered: