forgot to cc the list...
Am 11.08.2010 20:11, schrieb Andrei Pelinescu-Onciul:
On Aug 11, 2010 at 18:39, Klaus Darilionklaus.mailinglists@pernau.at wrote:
Am 11.08.2010 17:19, schrieb Andrei Pelinescu-Onciul:
On Aug 11, 2010 at 17:13, Klaus Darilionklaus.mailinglists@pernau.at wrote:
Hi Andrei!
Am 11.08.2010 16:18, schrieb Andrei Pelinescu-Onciul:
- all the module functions can now be called with any constant expression
as parameters. E.g.: f("7 *" +" 6 = " + 7 * 6);
What is the result of this example?
f("7 * 6 = 42")
... + 7 * 6) ^ ^ | | A B
IMO it is very confusing (if not even wrong) that A is a string concat and B is a arithmetic operation. What happens with:
... + 7 + 6) ?
f("7 + 6 = 76") :-)
but
f("7 +" +" 6 = " + (7 + 6)) is f("7 + 6 = 13"), as expected.
I agree it's confusing, but when I wanted to add a separate operator for string concat (e.g. '.') lots of people opposed it on the grounds that it will be too difficult for a script writer to use 2 different operators (or something similar). Now we have auto-conversion everywhere...
Maybe we can revisit this and the option of declaring only typed variable for a future release.
I can't remember if I was for or against a dedicated concat parameter, but now I think a dedicated parameter would be good. '.' might be confusing as well once we support float numbers.
Is it possible to analyze how sr evaluates the term?
regards klaus
On Aug 12, 2010 at 09:26, Klaus Darilion klaus.mailinglists@pernau.at wrote:
forgot to cc the list...
Am 11.08.2010 20:11, schrieb Andrei Pelinescu-Onciul:
On Aug 11, 2010 at 18:39, Klaus Darilionklaus.mailinglists@pernau.at wrote:
Am 11.08.2010 17:19, schrieb Andrei Pelinescu-Onciul:
On Aug 11, 2010 at 17:13, Klaus Darilionklaus.mailinglists@pernau.at wrote:
Hi Andrei!
Am 11.08.2010 16:18, schrieb Andrei Pelinescu-Onciul:
- all the module functions can now be called with any constant expression
as parameters. E.g.: f("7 *" +" 6 = " + 7 * 6);
What is the result of this example?
f("7 * 6 = 42")
... + 7 * 6) ^ ^ | | A B
IMO it is very confusing (if not even wrong) that A is a string concat and B is a arithmetic operation. What happens with:
... + 7 + 6) ?
f("7 + 6 = 76") :-)
but
f("7 +" +" 6 = " + (7 + 6)) is f("7 + 6 = 13"), as expected.
I agree it's confusing, but when I wanted to add a separate operator for string concat (e.g. '.') lots of people opposed it on the grounds that it will be too difficult for a script writer to use 2 different operators (or something similar). Now we have auto-conversion everywhere...
Maybe we can revisit this and the option of declaring only typed variable for a future release.
I can't remember if I was for or against a dedicated concat parameter, but now I think a dedicated parameter would be good. '.' might be confusing as well once we support float numbers.
Is it possible to analyze how sr evaluates the term?
f("7 + 6 = " + 7 + 6) =>
since '+' has the same priority: ("7 + 6 = " + 7) + 6 => ("7 + 6 = " + (str) 7) + 6 [first term is str => forces str conversion] ("7 + 6 = 7" + 6) => ("7 + 6 = 7" + (str)6) => "7 + 6 = 76"
In the '*' case: ("7 + 6 = " + 7 * 6) '*' has higher prio then '+' => ("7 + 6 = " + (7*6)) => ("7 + 6 = " + 42 ) ...
The '+' operator is special in the sense that it converts its right operand to the type of the left operand and the result also has the type of the left operand. The other operators force conversion and always have a fixed return type (e..g '*' converts both of its operands to int and always returns int).
More examples:
"1" + 2 = "12" 1 + "2" => error "1" + "2" = "12"
"1" * 2 => error 1 * "2" => error "1" * "2" => error (int)"1" * 2 = 2
Note also that the code internally supports a CONCAT operator (that works only on strings) and IPLUS operator (+ for integers only). Right now they are used in optimizations (when possible the PLUS operator is replaced during the optimization phase with either CONCAT or IPLUS). They could easily be enabled from cfg.y (if we find a "name" for them).
Andrei
Am 13.08.2010 11:11, schrieb Andrei Pelinescu-Onciul:
The '+' operator is special in the sense that it converts its right operand to the type of the left operand and the result also has the type of the left operand. The other operators force conversion and always have a fixed return type (e..g '*' converts both of its operands to int and always returns int).
More examples:
"1" + 2 = "12" 1 + "2" => error "1" + "2" = "12"
"1" * 2 => error 1 * "2" => error "1" * "2" => error
Why are these errors? You said "The other operators force conversion"
regards klaus
(int)"1" * 2 = 2
On Aug 13, 2010 at 13:14, Klaus Darilion klaus.mailinglists@pernau.at wrote:
Am 13.08.2010 11:11, schrieb Andrei Pelinescu-Onciul:
The '+' operator is special in the sense that it converts its right operand to the type of the left operand and the result also has the type of the left operand. The other operators force conversion and always have a fixed return type (e..g '*' converts both of its operands to int and always returns int).
More examples:
"1" + 2 = "12" 1 + "2" => error "1" + "2" = "12"
"1" * 2 => error 1 * "2" => error "1" * "2" => error
Why are these errors? You said "The other operators force conversion"
Sorry I should have said "expects and converts only if '+' and target type is string". strings are never converted to integers unless an explicit cast is used (e.g. (int)"1").
Andrei