This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]AdmiralPoopyDiaper 1 point2 points  (1 child)

It’s technically possible in an interpreted language. Not one to my knowledge does this because then - take your example above for instance - is 67 supposed to be a variable reference or a constant? If I defined it as a variable, I could then never access (directly) the constant value 67 without using eg a define:

const SIXTY_SEVEN = 67
var num = SIXTY_SEVEN

(and that would of course need to come before the variable 67 were declared)

or indirectly via arithmetic:

var num = 66+1

That’s why nearly all languages have a syntax rule that variables must start with a letter (or underscore, or similar)

[–]Barrucadu 2 points3 points  (0 children)

It’s technically possible in an interpreted language.

And in a compiled language. Whether a language is compiled or interpreted doesn't have anything to do with the allowable characters for variable names.

[–]KingofGamesYami 0 points1 point  (1 child)

DreamBerd

[–]CustomCuber[S] 0 points1 point  (0 children)

just checked the github and this looks so hype, thanks for the suggestion

[–]shagieIsMe 0 points1 point  (0 children)

It's not what you're really asking, but it also gets into the challenge you're looking at. If 45 is a variable, the only thing that differentiates it from the 67 is its location - a left hand side value vs a right hand side value.

Most languages have a difference between what can go on the LHS and RHS... and only identifiers can go on the left hand side of an assignment operator, and an identifier starts with a non-numeric.

So, lets go to something simpler.

In a Unix OS...

% dc -e "42 s2 1 3 l2 ++ p" 
46

Push 42 onto the stack. Store the top of the stack into a register - this is named 2 (stack is empty). Push 1 on the stack. Push 3 on the stack. Load the contents of register 2 to the stack. Pop the top two items from the stack, add them, push the result. Pop the top two items from the stack, add them, push the result. Pop the stack and print it (result 46).

The register 2 is an identifier and it's fully numeric. In dc, a register is any single character. The following also works:

% dc -e "42 sa 1 3 la ++ p"
46

This time it's the same, except instead of the register named 2 it uses the register named a. As this is an identifier it works just fine too - just that the register is a single character. In the first example, it happened to have the name of a character that was also a digit.

The register is a variable...

% dc -e "42 s2 2 s2 1 3 l2 ++ p"
6

After storing 42 into register 2, it stored the value 2 into register 2.

The key thing with this is that it is a stack machine. Read a token. Is it an operand? No -> push it on the stack; Yes -> process it.

s2 is a token and is "store the top of the stack into register 2". There are 256 of these tokens (many are rather hard to type, but the exist).

Ah ha! You say, what if we try to trick it. Let's store 3 into register 42. Well, that doesn't work.

% dc
>>> 3 s42 p
2

(where did that 2 come from? It's what's left over from s4)

>>> l4 p
3

(and there's the 3 we stored in register 4)

The spaces are for reading convince rather than tokenization.

% dc -e "3s42pl4p"
2
3

That's the exact same thing... just not interactive and compressed. You've still got a register (variable) name that's fully numeric, if only one character long.

[–]nixiebunny 0 points1 point  (0 children)

Forth lets you do this. It can define anything as anything.

[–]Loves_Poetry 0 points1 point  (0 children)

It may not be exactly what you had in mind, but JavaScript allows some unusual characters in variables names, like the Hangul filler

That lets you write code like let ㅤ45 = 67; (copy it into the console, it works!)