@damien_mattei: your modification to if
is ambiguous. What do you want the following program to evaluate to?
(let ((then 0))
(if #t then
10))
Both Scheme and Racket would evaluate the above to 0
, but your extension would evaluate it to 10
.
/////////////////////////
I also want to note this: it is really frustrating to help with anything related to the Scheme+ project.
Most people use Racket the way it’s intended to be used. For example, we write programs in modules. We use syntax-parse
to easily write macros.
The Scheme+ project seems to have its own ways of doing things. E.g., everything is written outside modules. Unhygienic reader extensions are used to customize syntax.
As a result, I think the code in this project can barely be called “Racket code”. You will have trouble doing things. This means you will need more and more help. But people won’t be able to help you because they are not familiar with Scheme+. And this becomes a cycle.
To be honest, with how things currently are, my personal opinion is that this forum is not a good fit to ask these kinds of questions.
It also doesn’t help that the Scheme+ related posts always contain a lot of code that no one would have an idea what it is. E.g., no one would know what condx
or exec
is. I think communication really needs to be improved for anyone to understand what you are trying to do. E.g., provide us necessary context, but make things self-contained.
/////////////////////////
Here’s an example of a way to implement your if
extension using Racket facilities.
#lang racket
(require syntax/parse/define)
(define-syntax (then stx)
(raise-syntax-error #f "out of context use" stx))
(define-syntax-parser if
[(_ test-expr:expr
{~literal then}
then-expr:expr ...
{~literal else}
else-expr:expr ...)
#'(cond
[test-expr then-expr ...]
[else else-expr ...])]
[(_ test-expr:expr {~literal then} then-expr:expr ...)
#'(when test-expr
then-expr ...)]
[(_ test-expr:expr {~literal else} else-expr:expr ...)
#'(unless test-expr
else-expr ...)]
[(_ test-expr:expr then-expr:expr else-expr:expr)
#'(cond
[test-expr then-expr]
[else else-expr])])
(let ((then 0))
(if #t then
10)) ;=> 0
(let ((not-then 0))
(if #t then
10)) ;=> 10
That’s ~20 lines to create a hygienic macro. Contrast that with the ~80 lines of unhygienic reader extension.
Sorry for being blunt, but I think it’d be useful for you to get this feedback now rather than later.