Skip to content
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

Make an RFC for splicing-begin #87

Open
sorawee opened this issue Jul 25, 2019 · 1 comment
Open

Make an RFC for splicing-begin #87

sorawee opened this issue Jul 25, 2019 · 1 comment

Comments

@sorawee
Copy link
Contributor

sorawee commented Jul 25, 2019

One common mistake for Racket beginners (including me and some of my friends) is thinking that begin is used for grouping things. However, begin is in fact context-sensitive:

  • In the expression context, it can be used to group expressions.
  • In non-expression contexts, it splices its body out to enclosing form.

This causes a lot of confusion to me in the past. E.g.,

(let ()
  (begin (define x 1)
         (println (+ x 2)))
  (println x)) 
;; 3
;; 1 <= why is x bound here?
(identity (begin (define x 1)
                 (println (+ x 2)))) 
;; define: not allowed in an expression context in: (define x 1) <= why doesn't it work

I propose that we have splicing-begin which is only for splicing, and change (begin body ...) to be semantically equivalent to (let () body ...).

  1. This is more consistent: now all splicing forms are prefixed with splicing-.
  2. (let () ...) idiom can be gone--which is good. For people who are not familiar with Scheme, this expression is very confusing: why do you use let if you are not going to introduce any binding?

If this will be confusing to existing Schemers, we could also change the name altogether. E.g., block and splicing-block, or seq and splicing-seq.

@jackfirth
Copy link
Sponsor Collaborator

This is a fantastic idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants