Ludii Forum
Treating True and False as 1 and 0 - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Suggestions (https://ludii.games/forums/forumdisplay.php?fid=10)
+--- Forum: Ludii Features / Services (https://ludii.games/forums/forumdisplay.php?fid=11)
+--- Thread: Treating True and False as 1 and 0 (/showthread.php?tid=530)



Treating True and False as 1 and 0 - Michael - 04-01-2021

Would it be possible to let us do arithmetic on booleans? It would be very useful to be able to treat the boolean True as the integer 1 and the boolean False as the integer 0.


RE: Treating True and False as 1 and 0 - cambolbro - 04-01-2021

Hi,

Yes it should be possible to add a ludeme that converts a boolean value to an integer, e.g.

(int <boolean>)

Or even perhaps allow boolean values to be passed as arguments to integer parameter and silently do the conversion. This would be equivalent to making <boolean> a clause of the <int> rule:

<int> ::= <boolean> | all the other int functions...

We'll look into this after Easter.

Regards,
Cameron


RE: Treating True and False as 1 and 0 - Michael - 04-01-2021

Wonderful, thanks!


RE: Treating True and False as 1 and 0 - Michael - 04-01-2021

I just realized that the language basically includes the first option already: There are conditional integers. I didn't know about this, but have thought about it a couple of times. When I finally checked I was pleasantly surprised to see it was already there :)

I still think it would be neat to be able to plug a boolean directly into an arithmetic formula, though. But it is obviously not as pressing as I thought.


RE: Treating True and False as 1 and 0 - Eric Piette - 04-06-2021

Hi,

I just added to our dev version, the ludemes (toInt ...), (toBool ...) and (toFloat ....) to convert any of the two others to the third one.

That will be in the next release.

Regards,
Eric