On Wed, 7 Sep 2011, Hans-Christoph Steiner wrote:
Yeah, I agree, I have no problem if someone wants to make an externals
that interprets 4+2 or "four" as 4, but it doesn't seem like something
that should be in the core.
Well, there would be no conflict if such a feature existed, because it
would only happen when atom_getfloat() is called on a A_SYMBOL atom, and
it would only happen when that symbol does not parse as a float (strtof
would return 4 and report to have stopped parsing at the + sign, meaning
that the whole symbol is not just 4).
However, nearly all programming languages that have implicit conversions
would just let arithmetic stay out of the core.
Pd's [expr] and Tcl's [expr] are two notable weird exceptions, in which
you can pass a symbol instead of a float, where the intention of the user
was to allow using a float in the expression, yet you can pass 4+2 or
whatever :
banging [expr $1] with $1=4+2 gives 6
banging [expr $1*-1] with $1=4+2 gives 4+2*-1 = 4-2 = 2 (really)
banging [expr ($1)*-1] with $1=4+2 gives 4
making it so that the argument is float is longer : you need to use $f1
with an additional [f $1] (and in cases with multiple inlets, you may have
to [loadbang] too, etc)
I suggest to stick with the simple stuff, that is, if you get "4+2" as a
A_SYMBOL and atom_getfloat is used, you'd get « error: 4+2 can't be cast
to float », because strtof() stopped before the end of the string. That's
why you have to avoid atof... otherwise you'd cast 4+2 to 4 and give no
error, and that's weird.
perl -e 'print("4+2"+0,"\n")' gives 4. (I don't approve.)
tcl's «expr "4+2" + 0» gives 6.
tcl's «expr {"4+2" + 0}» gives :
can't use non-numeric string as operand of "+"
About hex 0x form, that could conceivably fall under the "anything that
looks like a number is a float", as least for programmers. In most
programming languages, 0x10 is just a number like 16.
Yeah, but it's a new incompatibility, just like changing the meaning of
doublequotes. I don't mean that we shouldn't do it, just that it is
something to be careful about.
Martin is not alone to use the 0x syntax for making symbols that represent
ints bigger than what float32 can hold (which is limited to int25). I also
use that for window-id of X11 screenshots, as used in
http://gridflow.ca/help and also the Patch-dans-Patch series.
_______________________________________________________________________
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management ->
http://lists.puredata.info/listinfo/pd-list