Phix value() function

new topic     » topic index » view thread      » older message » newer message

This is about something old, unurgent and probably of limited general interest …

The Phix documentation says about sequence s = value(string st):

Note this is an "inherited" routine, that I don’t much like. Whenever I try to use it, I tend to get stuck, give up, and roll my own. However if it works for you, then fine.

It luckily works for me — converting strings to numbers is something I can't do without — but, what is wrong with value(), and is there a recommended alternative? (Sorry if I've missed something obvious.)

Also,

After reading one valid representation of a phix object, value() will stop reading and ignore any additional characters in the string. For example, "36" and "36P" will both give you {GET_SUCCESS, 36}.

What I do, rather clumsily, to decide whether a string is actually a valid number, is that I add "9" to the string, and see whether this changes the value — in the above example, "36" and "369" give different values (so, yes, 36 is a number), while the values of "36P" and "36P9" will be the same (therefore, 36P is not a number). It works, but is there a less clumsy way to decide?

As I've said, it works for me, but Pete's threat regarding inherited routines, "any grief may lead to an offending routine simply being removed rather than fixed," has me worried! :)

Robert

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu