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

Add boolean constants #154

Closed
wants to merge 1 commit into from
Closed

Add boolean constants #154

wants to merge 1 commit into from

Conversation

spnda
Copy link
Contributor

@spnda spnda commented Jun 1, 2020

I'm not sure if this is already a thing, but I don't think it is.
I feel like this is a neat addition but maybe there should be some checking that these are correctly used? They just expand to 0 and 1 respectively.

@Yexo
Copy link
Contributor

Yexo commented Jun 1, 2020

Do you have a particular use-case in mind for this?

@spnda
Copy link
Contributor Author

spnda commented Jun 1, 2020

For example, the dual-headed for trains expects a 0 or 1, so false or true.

@Yexo
Copy link
Contributor

Yexo commented Jun 1, 2020

Fair enough, there are several other vehicle_is_* variables that are essentially bools. Then again, they're currently all documented as 0 | 1. I see advantages in introducing a boolean type, but I'd rather do that properly instead of relying on integer values 0/1 disguising themselves as boolean.

That'd be a different approach than this PR is taking: the nml AST already has a Boolean type. Make use of that for true and false and then type-check all expressions including in switch-blocks to make sure those constants aren't mis-used.

@frosch123
Copy link
Member

Defining "true" as 0, and "false" as 1, is asking for disaster.

@spnda
Copy link
Contributor Author

spnda commented Jun 1, 2020

Fair enough, there are several other vehicle_is_* variables that are essentially bools. Then again, they're currently all documented as 0 | 1. I see advantages in introducing a boolean type, but I'd rather do that properly instead of relying on integer values 0/1 disguising themselves as boolean.
That'd be a different approach than this PR is taking: the nml AST already has a Boolean type. Make use of that for true and false and then type-check all expressions including in switch-blocks to make sure those constants aren't mis-used.

Ok, I'll look into that.

Defining "true" as 0, and "false" as 1, is asking for disaster.

ohh... oops

@andythenorth
Copy link
Contributor

andythenorth commented Jun 3, 2020

Odd timing, I am looking at a case right now where True and False as constants might be useful.

True and False as return values from a procedure might be more readable than the current 1 and 0 I'm using.

Not sure it's essential, and I could add them in my python compile as constants if I wanted. I didn't do that so eh :)

@spnda
Copy link
Contributor Author

spnda commented Jun 17, 2020

nevermind, i'm not gonna finish this PR.
someone else should take over and implement boolean values.

@spnda spnda closed this Jun 17, 2020
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

Successfully merging this pull request may close these issues.

None yet

4 participants