Closed gelisam closed 1 year ago
Btw @david-christiansen , is there a specific reason why users are forbidden from defining their own identifiers starting with #%
? We could allow those characters inside identifiers and then a #lang
could choose to rename quote
to #%quote
. Currently a #lang
cannot do that because #%
are not valid identifier characters but the parser makes an exception for #%string
and the other special primitives.
The reason is that they represent hooks that are used to allow user interpolation of operators into a context that is not otherwise syntactically marked. Otherwise, the variable naming system can be used to override the meanings of named operators (e.g. quote
or lambda
).
The reason to not allow other #%
names is just to prevent confusion about what they do, and catch typos earlier. There's not a way for users to add new interpolation points, after all.
Thanks for the explanation, the part about avoiding typos makes a lot of sense.
I now see that identifiers have three levels of discoverability:
lambda
appear as-is in the code, e.g. (lambda (x) x)
becomes (lambda (x) x)
. Users can thus easily look up that identifier in the documentation.quote
are shortened to a small number of special character, e.g. (open-syntax 'foo)
becomes (open-syntax (quote foo))
. Users can thus look up the special character in the documentation, but this requires making sure the documentation's search bar supports those special characters.#%app
and #%string
are inserted around existing code, without any syntactic markers, e.g. (f "foo")
becomes (#%app f (#%string "foo"))
. Users might thus struggle to find the identifier's documentation, and might not even realize that an extra macro call is added.It thus seems useful to keep the number of #%
identifiers to a minimum, so that the user can read the entire section on #%
identifiers and remember all the places where they are inserted. Therefore, I now agree not to rename quote
to #%quote
.
While using the name
quote
is more compatible with other lisps, using the name#%quote
would be more consistent, because"foo"
and'(foo)
are both syntactic sugar for a macro call, namely(#%string "foo")
and(quote (foo))
.