Closed sullyj3 closed 7 years ago
Good idea. I think it’s safe to relax \
to work on any term, so \term
should always be equivalent to { term }
. A bit strangely, it would make \(foo bar baz)
perfectly legal syntax for { foo bar baz }
, but I think that’s acceptable, because people would prefer the latter anyway.
One minor problem with this IIRC is that Emacs treats \(
as matching \)
, not )
, because of some regexp dialects. So we’d have to account for that in kitten-mode
. (Editor integrations need a lot of love anyway.)
Is the difference b/c it would otherwise have to be written, { 1 (+) }
? Also, is \( + 2 + 1 )
valid?
Operator sections are sugar to avoid some stack operations:
(+ 1)
→ 1 (+)
(1 +)
→ 1 swap (+)
This change would just make e.g. \(+ 1)
valid and equivalent to { (+ 1) }
, because \foo
is already valid and equivalent to { foo }
.
(+ 2 + 1)
is currently valid, and equivalent to (+ (2 + 1))
or (+ 3)
, but that’s kind of a bug because it can lead to misleading precedence.
I've given it some thought, but I don't see the common pattern.
(+ 1) → 1 (+)
(1 +) → 1 swap (+)
What's the rule of translation? How does the swap
come into it?
Operator sections are just partially applied operators. For some operator @
:
(a @ b)
is fully applied, and desugared into a b (@)
.(@ b)
is desugared into b (@)
because (@ b)
= -> x; x @ b
= -> x; x b (@)
= b (@)
(a @)
is desugared into a swap (@)
because (a @)
= -> x; a @ x
= -> x; a x (@)
= -> x; x a swap (@)
= a swap (@)
So while (+ 1)
is a function that adds 1 to its argument, { (+ 1) }
(or, with this proposal, \(+ 1)
) is a function that pushes that function to the stack.
Fixed in 5552773d45238e53ab726a423c28abeb3c395147.
Would it be possible to allow something like:
This seems much nicer than the current way to do it:
[1,2,3,4,5] {(+ 1)} map
As well as being more consistent.