RE: [NASL2] Auto-conversion with + and -
"Jim Cervantes" <[email protected]>
| Newsgroups | gmane.comp.security.nessus.devel |
|---|---|
| Message-ID | <[email protected]> |
When a programmer chooses an operator, she will mean either addition or
string concatenation, without any ambiguity in mind. It's pretty
unfortunate if the language doesn't capture this information. Since you
have chosen '+' to mean string concatenation and addition, you need to
disambiguate which operation is meant at run time (it has to be done at run
time since the disambiguation depends on operand types, which is only known
at run time). Seems like a pretty odd problem since the programmer knew
what he meant in the first place.
When you combine ambiguity of operators with ambiguity of data types (either
through automatic type conversion or undefined values or both), you end up
with too many difficult question to answer.
I would recommend disambiguating the meaning of your operators. Use '+' to
mean addition and something else to mean string concatenation. Then a
simpler and more natural set of rules can be constructed.
Examples ('.' is the string concatenation operator):
"x" + 3 generates a runtime error
"x" . 3 produces "x3" (3 is converted to "3")
"123" + "7" produces 130 ("123" converted to 123 and "7" converted to 7)
"123" . "7" produces "1237"
Etc.
-Jim
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Michel Arboi
> Sent: Saturday, February 08, 2003 12:02 PM
> To: [email protected]
> Subject: [NASL2] Auto-conversion with + and -
>
>
> My philosophical problem with the undefined value led me to look
> better at the + and - operators.
> The code is ugly, so I decided to rewrite it in a simpler way.
> The big question is: what do we do when we have heterogeneous
> arguments?
> For +, the (current) result is a string as soon as one argument is a
> string.
> e.g. "x" + 3 = "x3" and 3 + "x" = "3x"
> This also means that "123" + 7 = "1237"
>
> For -, the behavior is identical, although I am not sure it is a good
> idea, because "string subtraction" is a rather special operation.
>
> Maybe after we should just print a warning and returns an error (null)
> but I suspect that this would break a couple of scripts.
>
> --
> mailto:[email protected]
> GPG Public keys: http://michel.arboi.free.fr/pubkey.txt
> http://michel.arboi.free.fr/ http://arboi.da.ru/
> FAQNOPI de fr.comp.securite : http://faqnopi.da.ru/