PyHP-pph / PyHP_pph

This repository serves as a centre for collaboration on the PyHP++# language. It will also include a functioning interpreter and compiler for PyHP++# once the standard is finalised.
https://www.reddit.com/r/PyHP_pph/
GNU Affero General Public License v3.0
23 stars 3 forks source link

How should types be casted? #25

Open Kampfkarren opened 7 years ago

Kampfkarren commented 7 years ago

We can take the C/C++ approach with either (type)value or type(value) or the PHP-esque route of adding functions to the global namespace, such as to_boolean(value), to_int(value), etc.

ghost commented 7 years ago

It should be implicit, with vaguely defined rules. If, say, you have a function like this:

int Twice(int x)
  {
    return x * 2
  }

And you pass it something that's not an int, say... a boolean:

$Result = Twice(True);
Console.StandardOutputStream >> disp($Result) >> Console.Characters.EndLine;

Then it should convert from boolean to int in an odd, unclearly defined way. In this case, I'd guess the output would be:

2

But it could also be:

0

Or:

example.pyph_pph:1:16: error: Cannot convert boolean to int.