Re: command_line() - convert a sequence to an atom value?

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

I usually use thing code when I need to convert a sequence to a number
value.
It's faster than value(), and you don't have to include get.e
This only takes care of whole numbers, but it could easily be modified for
decimal values.
If you want to use scientific notation, or hex values it's easier to just
use value().

Chris

--CODE
sequence cmd_line
cmd_line=command_line()
if length(cmd_line)<3 then abort(1) end if -- no param
atom val    val=0
for i=1 to length(cmd_line[3]) do
    if cmd_line[3][i]<'0' or cmd_line[3][i]>'9' then abort(1) end if -- not
a number
    val=val*10+cmd_line[3][i]
end for
--END CODE


----- Original Message -----
From: <heyjoel at mindspring.com>
To: "EUforum" <EUforum at topica.com>
Sent: Tuesday, August 14, 2001 8:26 PM
Subject: command_line() - convert a sequence to an atom value?


>
> I want to convert my program from prompting for user input to including
this
> input on the command line.  I have used the command_line() function to do
> so, but have come across a small problem.
>
> If my program prompts the user for the data from within the program:
> Enter the data :
> 30
> then then value 30 can be stored as an atom as declared.
>
> But command_line() returns a sequence with the value {51,48} which cannot
be
> stored in my nice little atom.
>
> So, I am looking at reworking my code to treat everything as a sequence,
but
> it would be a whole lot nicer if there happens to be a way of storing the
> numerical value of the command_line() sequence {51,48} as 30 in my atom.
>
> Any ideas?
>
> Joel Garcia
>
>
>
>
>
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu