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

Unicode operator support #555

Open
edemaine opened this issue Jun 16, 2023 · 5 comments
Open

Unicode operator support #555

edemaine opened this issue Jun 16, 2023 · 5 comments
Labels
enhancement New feature or request proposal Proposal or discussion about a significant language feature

Comments

@edemaine
Copy link
Collaborator

edemaine commented Jun 16, 2023

Some folks don't use ligatures, but still would like nice notation. Here are some operators that we could support in a simple transpilation sense:

Unicode ASCII equivalent Done?
<=
>=
!=
== (I guess)
===
!==
² ** 2
²³ ** 23 (ideally)
²⁺³ ** (2+3) (ideally)
:=
??
+= (I guess)
++ (I guess)
||
<<
>>
>>>
^ or ^^ (maybe, common notation for XOR)
¬ ! (maybe)
|| (maybe)
&& (maybe)
...
..
?=
<? (instanceof shorthand)
is in
is not in
|>
->
=>
’s 's
“...” '''...''' (?)
‘...’ '''...'''

Let me know if I missed any! There are some pretty interesting opportunities with shorthand like . APL here we come.

Note: These Unicode characters are relative easy to type using a compose key. On Windows, I use WinCompose, which emulates a feature built into X-Windows (I believe).

This is somewhat related to the (unwritten) proposal to support emoji in identifiers — ideally translating e.g. 😊 to smiling or similar, for JS interop, though it might be easier to translate it to something like $1F60A, to avoid a lookup table. It might be nice to "support" other mathematical operators like as identifiers, so that users can define them via operator. (Or maybe such Unicode operators are automatically infix, but need to be defined via function or operator.)

@fabiospampinato
Copy link

If num² is equal to num ** 2, should numᵖᵒʷ be equal to num ** pow? Maybe it's not worth it.

@GoToLoop
Copy link

GoToLoop commented Jun 16, 2023

Keyword var is still lacking a shorthand for it though.
I also miss a shorthand for prototype like in CoffeeScript, which uses :: btW.
And also Python's keyword elif.

edemaine added a commit that referenced this issue Jun 26, 2023
Some simpler and less controversial Unicode operators from #555
@edemaine edemaine added enhancement New feature or request proposal Proposal or discussion about a significant language feature labels Jul 6, 2023
@orenelbaum
Copy link

make it configurable so I can use whatever characters and emojis I want, it would be the best feature in Civet

@edemaine
Copy link
Collaborator Author

edemaine commented Aug 6, 2023

@orenelbaum Thoughts on what this would look like? I wonder if templates (#587) would be a good answer, if you could define your own symbols like so:

template 🧪
  try
template 💀
  catch

Normally templates can only appear in contexts where function calls can appear, though, so I'm not sure whether this would work without some special casing.

Another option would be to specify simple string replacements, maybe like so:

"civet 🧪='try ' 💀='catch '"

But that seems pretty fragile especially when it comes to spacing.

@unlessgames
Copy link

A few more symbols to consider

  • ⧐ for ||> to complement ▷
  • ⊆ for <?
    as <? returns true for both x <? SuperClassOfX and x <? ClassOfX it somewhat parallels the original meaning of "Subset or equal to")
  • ⧖ for await

I second being able to use templates to define symbols, it would be quite funny to use some geometry in place of the type system keywords like

  • △ as interface
  • ◇ as enum
  • □ as type
  • ⚪ as class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request proposal Proposal or discussion about a significant language feature
Projects
None yet
Development

No branches or pull requests

5 participants