Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment vs equality (and more generally, expressions vs statements) #333

Open
dylanbeattie opened this issue Mar 24, 2024 · 1 comment
Milestone

Comments

@dylanbeattie
Copy link
Collaborator

Background:

C-style languages use = for assignment and == for equality. This has the nice side-effect that statements are also expressions: an assignment statement x = 4 is also an expression which returns the value 4 (i.e. the result of the assignment). However, it means having to use a different symbol/syntax for equality.

VBScript (which has had more of an influence on Rockstar than I'd like to admit) uses = for both assignment and equality, and the operator behaves differently whether it's in an expression or a statement context. VB has two functions for running code at runtime: Execute() will execute a statement (but not return anything), and Eval will evaluate an expression (but can't be used to execute statements).

https://ericlippert.com/2003/09/20/why-does-vbscript-have-execute-executeglobal-and-eval/

I'd very much like to adopt the C-style philosophy that statements can also be expressions, but this means the keyword is (and aliases was, were, etc) can't be used for both assignment and comparison.

One option would be to restrict is to equality, and use different syntaxes for assignment:

X is 5 (expression which returns true/false depending on the value of X)

Let X be 5
Make X 6
Put 7 into X

Anybody got any other good ideas as to how we might resolve this?

@dylanbeattie dylanbeattie added this to the 2.0 milestone Mar 24, 2024
@gaborsch
Copy link

gaborsch commented Mar 24, 2024

Only one idea came into my mind: assignments could use has, have, has got, have got 's got got (possessive expressions) syntax for an assignment expression. It's an unused yet very common language feature, I think.

Janie’s got a gun  (assigns Janie the value of  'a gun', single statement)

It would save this famous line, since the poetic assignment now requires the like keyword. It's a breaking change anyways.

Let a mistake be like a kiss
While our love has a mistake without like forgiveness is stronger than nothing  
Make a mistake our love
Shout our love! Baby
(counts down from 3 to 1)

(Don't ask how much time did it take to create a bearably-sounding example... 😅 )

The key is the While line: we assign a mistake - 1 to our love, then compare the value to 0.
The bad thing is that we may lose the in-place increment/decrement capability (our love has without 1 would be really useful but does not sound good at all, at least for me)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants