In the past it has been discussed whether it is better or worse to have quoted things be apostrophe'd.
Historical Rebol actively prohibits the use of a lit-word! with FOREACH for the loop variable:
>> foreach 'x [1 2 3] [print [x]]
** Script Error: foreach expected word argument of type: get-word word block
R3-Alpha and Red don't allow it either.
But it might seem you'd want to be able to do this in Ren-C...because there are quoting constructs that can quote backwards:
>> backquote: enfixed func [:x] [print ["I backquoted" x]]
== make action! [[:x] [...]]
>> foo: backquote
I backquoted foo:
So if you try for-each backquote
, the backwards-quoting BACKQUOTE would get the FOR-EACH before the forwards-quoting FOR-EACH could get the BACKQUOTE. That's just the order that the evaluator works in (unless there's nothing to the right of BACKQUOTE, which is the exception that would allow HELP BACKQUOTE to work).
You can work around that with:
for-each ('backquote) [1 2 3] [print [backquote]]
But it seems like it would be nicer if you could write it without the parentheses.
Should All Quoting Sites REQUIRE Quoted Input?
The quoted parameter convention exists to save you the trouble of quoting the callsites. If this isn't what that's for, then what is it for?
I'd be happy to buck the status quo if I thought it were clearly wrong. But when we look across the board we see how nice and fluent type of foo looks vs. 'type of foo. Over time it gets internalized to the point that type: type of foo doesn't feel weird at all (thought it might look so when you see it the first time).
While there's something to be said for the educational value of seeing when a word is being used by name vs. by value, it's just... "uglier"
type: 'type of foo
We seem lose something about knowing the "rules of OF" and the parts of speech involved by context, in order to add a bit of visual noise. To my tastes, it seems this is not in the same "clear win" zone over type-of
and type?
that we were in before.
It seems to me a core experimental theory in the language is that there is value in allowing acclimations in our mind to writing things that "start looking natural" even if they don't follow systemic rules. That speedbump of typing type of x of hitting the apostrophe key, as well as the visual jarringness, suggests it's a place to take advantage of not quoting when it's possible.
Should All Quoting Sites Merely PERMIT Quoted Input?
I mentioned that the current workaround for slipping past cases of things like backquoting operators is to use a GROUP!.
for-each ('foo) [1 2 3] [print [x]]
We might ask if the operation with the quoting slot should be lenient and let you just alternately write:
for-each 'foo [1 2 3] [print [x]]
Quoted words won't dispatch functions, so you don't have to worry about FOO's associated behavior if you do this.
A problem with being lenient in that way is that now the function spec is expanded to where it has to accept either WORD! -or- QUOTED! in its quoted slot. That complicates things, and now the author of the quoting function needs to be bothered with the quote-or-not of their argument.
If you take the easy-way-out and just DEQUOTE your argument (which leaves it as is if it's not quoted), then you may be permitting things with arbitrary numbers of quotes.
for-each '''''''''foo [1 2 3] [print [x]]
I'm pretty sure UNQUOTE should require its argument to be quoted, for the sake of sanity. So the implementation of functions like FOR-EACH would get hairier if they were to have to check and preprocess their arguments, e.g. to permit one-and-only one level of quote that they strip off. This could be made easier with some helper for the purpose, though.
A Benefit To Requiring Quotes
I've mentioned in the past that for things like FOR-EACH, if we required the first argument to be quoted then there could be a special interpretation for when there wasn't a quote. e.g. just run a function without naming a variable:
>> for-each ["No" "Variable"] :print
No
Variable
This keeps you from having to write something like:
for-each _ ["No" "Variable"] :print
A plain function declaration isn't particularly interesting in this form, even with a lambda it's wordier (and symboly-er) than the old-style without:
for-each [1 2 3] x -> [print [x]]
But when you bring in something like "POINTFREE" it gets more interesting:
>> block: [a b c]
>> for-each [1 2 3] (<- append block)
>> block
== [a b c 1 2 3]
With the idea that # is legal, it might look better if you "opt-in" to the variables:
for-each # [1 2 3] (<- append block)
This would let you do a template for what you want and don't want passed to your function.
>> block: [a b c]
>> for-each [# _] [1 2 3 4] (<- append block)
>> block
== [a b c 1 3]
This allows us to justify why the variable slot has usefulness even if we're not using a variable. Maybe that's the answer. And if we shorten FOR-EACH to simply EACH it would come out cleaner, even in complex invocations:
each [# _] [1 2 3 4] (<- append block)
Switch to #
for opt-in on variables, allow (but don't require) QUOTED! ?
...is this a plan? Does it cover all the angles?