asoffer / Icarus

An experimental general-purpose programming language
Apache License 2.0
9 stars 2 forks source link

Character literal syntax #101

Closed wrhall closed 2 years ago

wrhall commented 2 years ago

Discussing with Andy, the existing syntax is !c for the character literal 'c' (if this were C++). (seen in live code in https://github.com/perimosocordiae/advent-of-code/blob/9de86a79aeb5213539dd71647ab0c6abc51db13f/advent2021/day06.ic#L12)

Some possible alternatives:

wrhall commented 2 years ago

Andy notes that for something like %c{x}, you're burning a unary operator, % without a great reason. And you could just write it as char("x")

asoffer commented 2 years ago

Purely going with gut feelings here, I like !'x' the best. The leading ! makes the parse unambiguous, allowing us to reuse ' without losing it's meaning for function calls.

I don't see significant value in supporting array versions, given that "abc" is already a slice of characters.

perimosocordiae commented 2 years ago

Why add single quotes at all? The !x syntax was strange at first but I've gotten used to it. The only major issue is ! IMO, but that's not too different from other languages that have \ syntax for escaped spaces.