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

Backslash escaping operator sections #159

Closed
sullyj3 opened this Issue Sep 18, 2016 · 6 comments

Comments

Projects
None yet
3 participants
@sullyj3

sullyj3 commented Sep 18, 2016

Would it be possible to allow something like:

>>> [1,2,3,4,5] \(+ 1) map
[2,3,4,5,6]

This seems much nicer than the current way to do it:

[1,2,3,4,5] {(+ 1)} map

As well as being more consistent.

@evincarofautumn

This comment has been minimized.

Owner

evincarofautumn commented Sep 18, 2016

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.)

@evincarofautumn evincarofautumn added this to the Land New Compiler milestone Nov 6, 2016

@trans

This comment has been minimized.

trans commented Nov 7, 2016

Is the difference b/c it would otherwise have to be written, { 1 (+) }? Also, is \( + 2 + 1 ) valid?

@evincarofautumn

This comment has been minimized.

Owner

evincarofautumn commented Nov 7, 2016

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.

@trans

This comment has been minimized.

trans commented Nov 8, 2016

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?

@evincarofautumn

This comment has been minimized.

Owner

evincarofautumn commented Nov 8, 2016

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.

@evincarofautumn

This comment has been minimized.

Owner

evincarofautumn commented Jan 2, 2017

Fixed in 5552773.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment