Which languages allow emoji identifiers?
-
For an exercise, I would like to create some sample program where identifiers are easy to discern, but otherwise make no sense at all. So I got this weird idea that emoji would serve that purpose well.
Now because most language designers do understand it is a in any sort of production code, most languages, if they allow unicode at all, only allow letters, digits and a couple of special characters.
The only language I can readily remember as allowing emoji is swift, but we'll have mostly Windows and I hate with passion so I'm not touching that with 10 meter pole anyway. Otherwise I am open to almost anything.
So which other languages could I use?
-
@bulb I think TCL would probably work for you. almost any string can be used as a command name or variable name. Maybe @dkf can confirm?
-
also:
@jbert said in clustering:
@pie_flavor It's more fun to put your compiler in Unicode mode and use Emoji variables.
StringBuilder oh💩 = new StringBuilder(); oh💩.append("We are sorry for this outage. Please stand by while we look at the problem"); System.out.println(oh💩.toString());
-
I found a good candidate:
$ php -a Interactive shell php > function 😃($😂) { php { return $😂+1; php { } php > echo 😃(3); 4 php >
-
@bulb Java and Rust spring to mind. PowerShell would work too. I don't know if C# does it or not.
edit:
-
@pie_flavor Rust only allows XID_Continue for identifiers (and only XID_Start at the beginning), and emoji aren't XID_Continue.
-
@ben_warre said in Which languages allow emoji identifiers?:
also:
@jbert said in clustering:
@pie_flavor It's more fun to put your compiler in Unicode mode and use Emoji variables.
StringBuilder oh💩 = new StringBuilder(); oh💩.append("We are sorry for this outage. Please stand by while we look at the problem"); System.out.println(oh💩.toString());
@Ben_Warre I have since edited my post to make it clear I was joking and added this:
It looks like I should have clearly stated that I was joking. However, Java does allow a lot of Unicode characters which are marked as a Letter in Unicode and you can check with
Character.isJavaIdentifierStart(int)
orCharacter.isJavaIdentifierPart(int)
.This means that Katakana characters like ツ or Greek characters like π are no issue.
Somebody on StackOverflow had the following example:
int ಢ_ಢ = 42;
So you can do some special smileys, but emojis are still out for the moment.
EDIT: See Lowercase letters, Uppercase letters or Letters, other for inspiration (click on the "List" link at the bottom of the page).
-
@jbert boo!
-
@ben_warre ¯\_(ツ)_/¯
-
I thought javascript did, but my (chrome) browser console disagrees. I can confirm PHP though.
-
Found another one:
Though it doesn’t work without||
around the identifiers: the script fails with an error about an unknown token.
-
@pleegwat said in Which languages allow emoji identifiers?:
I thought javascript did, but my (chrome) browser console disagrees. I can confirm PHP though.
Not the same thing, but:
» o = { '😂': () => '💩' } < Object { "😂": 😂() } » o['😂']() < "💩"
-
Swift allows this IIRC
-
-
4 years ago...
-
@bb36e said in Which languages allow emoji identifiers?:
Swift allows this IIRC
You were d by the OP.
-
@ben_warre said in Which languages allow emoji identifiers?:
I think TCL would probably work for you. almost any string can be used as a command name or variable name. Maybe @dkf can confirm?
Commands can use anything (with exceptions for multi-colon sequences), but expressions are more restricted so I don't recommend using variable names with non-ASCII names. Array element names are completely free.
I also don't recommend using emoji in identifiers in any language.
Ever.
Just No.
-
@antiquarian said in Which languages allow emoji identifiers?:
https://twitter.com/t3xtm0de/status/600711130324008961?lang=en
Just as comprehensible as regular Haskell!
-
@pie_flavor The worst part is I know exactly what it does.
spoiler
It's a map function.
-
@dkf said in Which languages allow emoji identifiers?:
Commands can use anything (with exceptions for multi-colon sequences), but expressions are more restricted so I don't recommend using variable names with non-ASCII names. Array element names are completely free.
Thought so. Here's the evidence from an interactive session
sh$ tclsh8.6 % proc 🙁 {x y} {expr { $x**2 + $y }} % 🙁 3 4 13
(That looks really strange in my terminal; apparently my fixed-width font doesn't give emoji the same fixed width as everything else. Because why would you want that?!)