1. Re: Variable naming in Euphoria

On 11 Aug 2000, at 12:53, futures8 wrote:

> I'm new to Euphoria, so my question will seem very basic to those on the
> list.
> Hope some kind soul will offer some suggestions.
>
> Some languages have the capability to programatically create variable
> names; the following example from Foxpro demonstrates what I'm hoping
> can somehow be done in Euphoria. I have checked the Euphoria docs and
> various other Euphoria programs submitted to the archives by others, but
> haven't found and examples of what I'm looking for;
> .
> -----------------------------------------------------------------------------
>
> if reccount() - recno() < 10
>      k = reccount() - recno()
> else
>      k = 10
> endif
>
> for i = 1 to k
>       j = alltrim(str(i))           -- makes j a character
> respresentation of the  integer i
>       store val(CLOSE) to Price&j
>       skip
> next i
>
> ---------------------------------------------------------------------------------
>
> the loop iteratively creates variables  Price1, Price2 ...Price10 and
> assigns them a value.
> The concatenation operator in Euphoria will catenate the contents of
> sequences, but not variable names.
>
> Is there a way to similarly create (declare) and assign variable names
> on the fly in Euphoria?

I've asked for this several times, i do this a lot in mirc, it's really handy at
times. You'd
think an interpreted  LISPy language could do this inately. But what you can do
to get
around this lack in Eu by using two sequences, one to hold the new name you have
made, and one to hold it's value. It works, but it does get slow with lots of
lookups.

pseudocode:
nameseq = {"myVar1","nickaddy","phonenum.12"}
dataseq = {"45.6789","ChanServ!wizard at sorcery.net","305-234-0987"}

The location of the name in nameseq = the location in dataseq of the value of
that var.

function GetVarVal(sequence WhatiLookFor)
for loop = 1 to length(nameseq) do
 if ( nameseq[loop] = WhatiLookFor ) then
  return dataseq[loop]
 end if
end for

Kat

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu