Re: Irv: Re: For loop and a newbie

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

On Mon, 26 Mar 2001, jc at cknet.net wrote:

> Hello Irv
> 
> > but I'm curious why you
> > are using atom(vcommands[1])?
> > The command line parameters are _always_ strings, so, even if
> > you type "ex myprog One 2 Three 4",  each item is a string.
> 
> Ignorance plain and simple. This simple little routine has produced a
> significant amount of frustration, trying to learn EU and get this thing to
> work. I was under the impression that an atom was an individual number, 

An atom _is_ an individual number. However, the parameters input 
via the command line are not numbers at all, but an "array" of 
space delimited strings.

> I was thinking that this would test and see if a given parameter was a number
> or a 'string'. I'm simply trying to get the command line parameters and make
> sure they are numbers (ascii codes) in a range of 0 to 255. After I check
> them out I'm going to send them to the printer. This little routine (that
> I'd written years ago in pascal) is to send control codes to printers or
> cash drawers. Believe it or not, people pay me money to program in another
> environment, but I'm feeling like less than a rank beginner! What I think I
> want are simple chr() and asc() functions. I guess it's back to the drawing
> board on this 'sequence, atom, integer' business.

Here's a routine to validate and translate numbers:
include get.e
 
object x
x = command_line()
for i = 3 to length(x) do
  x[i] = value(x[i])
  if x[i][1] = 1 then
     printf(1,"Error: parameter %d must be a number.\n",i)
  else x[i] = x[i][2]
  end if
end for
 
You will end up with x as a sequence containing:
"exu","prgname",n1,n2,n3,n4......
up to however many params were entered.
n1... etc _are_ now atoms.

If you need a set number of params, then just check the 
length of the command line first - don't forget to account 
for the first two "automatic" params:

x = command_line()
if length(x) < 5 then puts(1,"Need 3 parameters!")
end if       
-- 
Regards,
Irv

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

Search



Quick Links

User menu

Not signed in.

Misc Menu