gosukiwi / Blueberry

A beautiful programming language with clean syntax which compiles to PHP
MIT License
63 stars 10 forks source link

Constants aren't supported #28

Closed hikari-no-yume closed 9 years ago

hikari-no-yume commented 10 years ago

Currently there's no way to reference them, because bare names are variables. You could add a prefix to mean a constant like Snowscript does, which has !FOO_BAR translate to PHP FOO_BAR.

But here's a more radical and perhaps nicer idea: Why not just make entirely uppercase names be constants? So if I want to check against INF, I could do if foo != INF. The main downside here is it might not be obvious if you didn't know the rule, and it'd stop you from dealing with projects that use $UPPERCASE_GLOBALS - but those projects probably suck.

This does also raise a problem of how to declare them. You could make FOO = 3 implicitly be a constant declaration, or you could have const FOO = 3 like PHP. I'm not sure which is nicer.

gosukiwi commented 9 years ago

Implemented in 7fe4431 using all uppercase syntax, as it's much nicer.

If legacy support is needed it's possible to use PHP's constant function: constant('myLowerCaseConstant').