1. Of what value is s = value()?
I'd appreciate understanding, by way of basic examples, in what situations
the routine "value()" might be useful. At first I thought of it as a way of
converting one or more numeric character(s) to a number that could then be
used in computations - is that right? Then I realised it would convert a
character string to a sequence of corresponding ASCII values - when might
you capitalise on that capability? Finally I learnt that it would return
the same result for "36" as for "36P" - why might it be useful to do that?
Thank you
Alex Caracatsanis
2. Re: Of what value is s = value()?
> I'd appreciate understanding, by way of basic examples, in what situations
> the routine "value()" might be useful. At first I thought of it as a way of
> converting one or more numeric character(s) to a number that could then be
> used in computations - is that right? Then I realised it would convert a
> character string to a sequence of corresponding ASCII values - when might
> you capitalise on that capability? Finally I learnt that it would return
> the same result for "36" as for "36P" - why might it be useful to do that?
> Thank you
> Alex Caracatsanis
value() converts a string representing a euphoria object into the
euphoria object it represents, it is similar to get() except that it
is used on a string already held in a sequence not one being read
from a file or the keyboard. Like get it also returns
{error_status,value}, if the error_status is GET_SUCCESS then value
will be the value of the euphoria object that was represented in the
string.
Some examples:
include get.e
object foo
foo = value("99")
--foo[1]=GET_SUCCESS
--foo[2]=99
foo = value("{1,2,3,4,5}")
--foo[1]=GET_SUCCESS
--foo[2] = {1,2,3,4,5}
foo = value("not an object")
--foo[1]=GET_FAIL
--foo[2]=0
foo=value("{1,2,3,") --<-Note how its missing the ending bracket
--foo[1]=GET_EOF
--foo[2]=0