DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.34k stars 28 forks source link

Unicode operator support #555

Open edemaine opened 1 year ago

edemaine commented 1 year ago

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 commented 1 year ago

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

GoToLoop commented 1 year ago

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.

orenelbaum commented 11 months ago

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

edemaine commented 11 months ago

@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 commented 7 months ago

A few more symbols to consider

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