1. Variables

--=====================_871925994==_

I am trying to write a program in Euphoria that processes information about
the various states of the United States.  I'm getting all tangled up with
Euphoria's rules for declaring variables, putting strings (which are really
sequences) in quotes, and other matters.  I'm also having trouble with
"global" variables.  Can somebody offer some suggestions?


--=====================_871925994==_

I have an external file containing fixed information about the
various states, and my program will dip into that file, extract
information pertaining to the particular state or states that
concern it at the moment, apply that information to those states,
and go on to another state or group of states to repeat the
process.

I have been working on this project for some time, using another
language, and I am looking forward to using the features of
Euphoria to streamline the process.  However, so far Euphoria
isn't streamlining, it's bogging down.

In my previous efforts, both the fixed file and the working file
dealt with the U.S.Postal Service's official two-letter
abbreviations for the various states.  In Euphoria, these two-
letter abbreviations are strings, and they have to be enclosed in
quotes to be used by Euphoria.  But Euphoria won't deal with the
abbreviations themselves; they have to be assigned to variables
that in turn have to be declared before they can be used.

For example, suppose I want to get the contribution of the state
of Pennsylvania to the population of the U.S.; add that number to
the corresponding numbers for other states on the eastern
seaboard; and file the total as the eastern seaboard's share of
the total population.  I can't just get the population for PA
from the fixed file and add it to the partial total population
for NY, NJ, MD and DE; those states have to be identified as
"PA", "NY", "NJ", "MD", and "DE", and each of them has to have a
variable name identified as a sequence.  The simplest variable
name, in turn, is just another abbreviation for the state name --
or, in places like Ohio and Iowa, the state name in full.

I'd prefer to leave the fixed file with no quotes, no variable
names, or similar extraneous matters.  If I do that, Euphoria
says I didn't declare a variable name for the file data; when I
declare a variable, Euphoria says I didn't assign a value to that
variable.  I'm going around in circles, and getting dizzy.

Also, where should "global" variables be defined?  I have put
them at the top, after the list of 'include' files, and at the
beginning of the main program after all procedures and functions,
but Euphoria can't seem to handle them either place.

Wally Riley
wryly at mindspring.com

--=====================_871925994==_--

new topic     » topic index » view message » categorize

2. Re: Variables

Wallace B. Riley wrote:
> <STUFF SKIPPED>
>I have an external file containing fixed information about the
>various states, and my program will dip into that file, extract
>information pertaining to the particular state or states that
>concern it at the moment, apply that information to those states,
>and go on to another state or group of states to repeat the
>process.
> <OTHER STUFF SKIPPED>
>In my previous efforts, both the fixed file and the working file
>dealt with the U.S.Postal Service's official two-letter
>abbreviations for the various states.  In Euphoria, these two-
>letter abbreviations are strings, and they have to be enclosed in
>quotes to be used by Euphoria.  But Euphoria won't deal with the
>abbreviations themselves; they have to be assigned to variables
>that in turn have to be declared before they can be used.
>
>For example, suppose I want to get the contribution of the state
>of Pennsylvania to the population of the U.S.; add that number to
>the corresponding numbers for other states on the eastern
>seaboard; and file the total as the eastern seaboard's share of
>the total population.  I can't just get the population for PA
>from the fixed file and add it to the partial total population
>for NY, NJ, MD and DE; those states have to be identified as
>"PA", "NY", "NJ", "MD", and "DE", and each of them has to have a
>variable name identified as a sequence.  The simplest variable
>name, in turn, is just another abbreviation for the state name --
>or, in places like Ohio and Iowa, the state name in full.
>
>I'd prefer to leave the fixed file with no quotes, no variable
>names, or similar extraneous matters.  If I do that, Euphoria
>says I didn't declare a variable name for the file data; when I
>declare a variable, Euphoria says I didn't assign a value to that
>variable.  I'm going around in circles, and getting dizzy.
>
>Also, where should "global" variables be defined?  I have put
>them at the top, after the list of 'include' files, and at the
>beginning of the main program after all procedures and functions,
>but Euphoria can't seem to handle them either place.
>

     Wally,

     A clarification question here: Are you including the 'fixed file' as
part of your source, i.e. "include fixedfile", or are you using file
commands to open the fixed file and read data from it?


Craig

new topic     » goto parent     » topic index » view message » categorize

3. Re: Variables

>I am trying to write a program in Euphoria that processes information
>about the various states of the United States.  I'm getting all tangled
up
>with Euphoria's rules for declaring variables, putting strings (which
are
>really sequences) in quotes, and other matters.  I'm also having trouble
with
>"global" variables.  Can somebody offer some suggestions?

We can at least try... ;)

>In my previous efforts, both the fixed file and the working file
>dealt with the U.S.Postal Service's official two-letter
>abbreviations for the various states.  In Euphoria, these two-
>letter abbreviations are strings, and they have to be enclosed in
>quotes to be used by Euphoria.  But Euphoria won't deal with the
>abbreviations themselves; they have to be assigned to variables
>that in turn have to be declared before they can be used.

>For example, suppose I want to get the contribution of the state
>of Pennsylvania to the population of the U.S.; add that number to
>the corresponding numbers for other states on the eastern
>seaboard; and file the total as the eastern seaboard's share of
>the total population.  I can't just get the population for PA
>from the fixed file and add it to the partial total population
>for NY, NJ, MD and DE; those states have to be identified as
>"PA", "NY", "NJ", "MD", and "DE", and each of them has to have a
>variable name identified as a sequence.  The simplest variable
>name, in turn, is just another abbreviation for the state name --
>or, in places like Ohio and Iowa, the state name in full.

Umm, try something like this:
constant VA = 1, NY = 2, etc.
sequence states
then input the data from the file into states.
(States will simply be one BIG sequence containing ALL the information)
Then call the data like this

printf(1, "%d", {states[TX][POPULATION]})

For input, perhaps you can use
constant state_names = {"VA", "NY", etc..
And find the data:
if find(input, state_names) then -- 'input' is keyboard input

Would this work?

new topic     » goto parent     » topic index » view message » categorize

4. Re: Variables

At 04:02 PM 8/18/97 -0400, you wrote:
>---------------------- Information from the mail header -----------------------
>Sender:       Euphoria Programming for MS-DOS <EUPHORIA at
>MIAMIU.ACS.MUOHIO.EDU>
>Poster:       Craig Gilbert <cgilbert at CENNET.MC.PEACHNET.EDU>
>Subject:      Re: Variables
>-------------------------------------------------------------------------------
>
>Wallace B. Riley wrote:
>> <STUFF SKIPPED>
>>I have an external file containing fixed information about the
>>various states, and my program will dip into that file, extract
>>information pertaining to the particular state or states that
>>concern it at the moment, apply that information to those states,
>>and go on to another state or group of states to repeat the
>>process.
>> <OTHER STUFF SKIPPED>
>>In my previous efforts, both the fixed file and the working file
>>dealt with the U.S.Postal Service's official two-letter
>>abbreviations for the various states.  In Euphoria, these two-
>>letter abbreviations are strings, and they have to be enclosed in
>>quotes to be used by Euphoria.  But Euphoria won't deal with the
>>abbreviations themselves; they have to be assigned to variables
>>that in turn have to be declared before they can be used.
>>
>>For example, suppose I want to get the contribution of the state
>>of Pennsylvania to the population of the U.S.; add that number to
>>the corresponding numbers for other states on the eastern
>>seaboard; and file the total as the eastern seaboard's share of
>>the total population.  I can't just get the population for PA
>>from the fixed file and add it to the partial total population
>>for NY, NJ, MD and DE; those states have to be identified as
>>"PA", "NY", "NJ", "MD", and "DE", and each of them has to have a
>>variable name identified as a sequence.  The simplest variable
>>name, in turn, is just another abbreviation for the state name --
>>or, in places like Ohio and Iowa, the state name in full.
>>
>>I'd prefer to leave the fixed file with no quotes, no variable
>>names, or similar extraneous matters.  If I do that, Euphoria
>>says I didn't declare a variable name for the file data; when I
>>declare a variable, Euphoria says I didn't assign a value to that
>>variable.  I'm going around in circles, and getting dizzy.
>>
>>Also, where should "global" variables be defined?  I have put
>>them at the top, after the list of 'include' files, and at the
>>beginning of the main program after all procedures and functions,
>>but Euphoria can't seem to handle them either place.
>>
>
>     Wally,
>
>     A clarification question here: Are you including the 'fixed file' as
>part of your source, i.e. "include fixedfile", or are you using file
>commands to open the fixed file and read data from it?
>
>
>Craig
Craig

The latter.  I haven't figured out 'include" files yet.

Wally
>

new topic     » goto parent     » topic index » view message » categorize

5. Re: Variables

Wallace B. Riley  wrote:
>I have an external file containing fixed information about the
>various states, and my program will dip into that file, extract
>information pertaining to the particular state or states that
>concern it at the moment, apply that information to those states,
>and go on to another state or group of states to repeat the
>process.

Wally,
     If you are reading from an external file, something like Robert
Pilkington's reply should work, where you have a predefined list of
abbreviations in one sequence, and use that for reference when scanning a
file for the information.
     If you are interested, I am within one or two routines of finishing a
module for handling pseudo-windows-ish initialization files, which might
make the type of referencing you are doing simpler.  You are welcome to it
if you would like to try it out.
     Here's how to tell if these routines would help you out or not; if your
data file is a text file arranged like this:
     <state abbrev> = <population><cr/lf>
     <state abbrev> = <population>
or if it can be arranged like that without too much trouble, these routines
would certainly work.



>Also, where should "global" variables be defined?  I have put
>them at the top, after the list of 'include' files, and at the
>beginning of the main program after all procedures and functions,
>but Euphoria can't seem to handle them either place.

     Global variables should work if declared almost anywhere outside of a
routine.  Maybe you could post a code sample to illustrate the problem?

Later,
Craig

new topic     » goto parent     » topic index » view message » categorize

6. Re: Variables

Craig (me) wrote:
>Wallace B. Riley wrote:
><SKIPPED>
>>Also, where should "global" variables be defined?  I have put
>>them at the top, after the list of 'include' files, and at the
>>beginning of the main program after all procedures and functions,
>>but Euphoria can't seem to handle them either place.
>
>     Global variables should work if declared almost anywhere outside of a
>routine.  Maybe you could post a code sample to illustrate the problem?
>
>Later,
>Craig

     I just reread and noticed that my answer left a rather large (and
incorrect) loophole.  A global will certainly *not* work if it is declared
*after* the routines referencing it.  It should have worked, however, when
they were declared at the top of the file.

Craig

new topic     » goto parent     » topic index » view message » categorize

7. Re: Variables

Wallace B. Riley wrote:

 I haven't figured out 'include" files yet.
>
Look on include files as an easy way to break your code up into neat
(easier to read/understand/manage) packages.

You can include anything from a single variable declaration to one or a hundred
functions and procedures in an include file rather than in your main program.

Also, this lets you write often-used routines and add them to program after
program without having to re-type. Another advantage is that these routines
are pre-tested, you don't have to worry about testing all over again when
you re-use them.

Irv

new topic     » goto parent     » topic index » view message » categorize

8. Variables

Robert Pilkington offered some suggestions in reply to my inquiry about
variables in Euphoria (as did half a dozen others so far -- thanks,
everybody!)  I'm not sure I can use Pilkington's suggestions.  I don't want
to print the data that my program creates; I just want to add it to an
output file.  Maybe tomorrow or next month or next year I'll want to print
the file, or some part of it; but not now.

Wally Riley
wryly at mindspring.com

new topic     » goto parent     » topic index » view message » categorize

9. Re: Variables

>Robert Pilkington offered some suggestions in reply to my inquiry
>about variables in Euphoria (as did half a dozen others so far --
thanks,
>everybody!)  I'm not sure I can use Pilkington's suggestions.  I don't
>want to print the data that my program creates; I just want to add it to
an
>output file.  Maybe tomorrow or next month or next year I'll want to
>print the file, or some part of it; but not now.

Well you can use the same idea, but instead of printing to screen or
printer, you just send the data to a file. (fn = filenumber)
printf(fn,"%s",{whatever})

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu