1. wildcard usage
- Posted by Norm Goundry <bonk1000 at HOTMAIL.COM> Apr 10, 1999
- 396 views
got a bit of a thing that has been driving me slowly insane since I first started using EU. I have tried every permutation of code to create a 'wildcard' method to substitute for many lines of branching to strings of data; question: is it possible to turn this...? --string 1 a1={"cat","dog","mouse"} --string 2 a2={"chicken","duck","cow"} input=x string_to_fetch="a" & x --where string_to_fetch is executable in the same way --that either string_to_fetch=a1 or string_to_fetch=a2 is -- I know that this isn't legal code, but perhaps you get the idea. I am polishing up some of the code of a huge database written in EU and this would be extremely useful if it is possible to do such a thing. I could do it on my old Amiga when using AMOS Basic. Any ideas that I haven't thought of yet?, any thing that works?, any help and suggestions for this will be mightly appreciated. Note: I don't wish to hear any lecturing about this bringing on the nightmare of 'speghetti-code'... if it is doable it can be usable. thanks Norm
2. Re: wildcard usage
- Posted by Lucius Hilley III <lhilley at CDC.NET> Apr 10, 1999
- 385 views
On Sat, 10 Apr 1999 13:37:26 -0400, Norm Goundry <bonk1000 at HOTMAIL.COM> wrote: >got a bit of a thing that has been driving me slowly insane since I first >started using EU. I have tried every permutation of code to create a >'wildcard' method to substitute for many lines of branching to strings of >data; question: is it possible to turn this...? > > --string 1 > a1={"cat","dog","mouse"} > --string 2 > a2={"chicken","duck","cow"} > > input=x string_to_fetch="a" & x > --where string_to_fetch is executable in the same way > --that either string_to_fetch=a1 or string_to_fetch=a2 is > >-- I know that this isn't legal code, but perhaps you get the idea. I am >polishing up some of the code of a huge database written in EU and this >would be extremely useful if it is possible to do such a thing. I could do >it on my old Amiga when using AMOS Basic. Any ideas that I haven't thought >of yet?, any thing that works?, any help and suggestions for this will be >mightly appreciated. Note: I don't wish to hear any lecturing about this >bringing on the nightmare of 'speghetti-code'... if it is doable it can be >usable. >thanks Norm I'm not really sure what you are trying to do here. but from what I see. You are wanting to use match(). something like. function fetch_strings(sequence search_for, sequence search_in) integer found sequence temp temp = {} for A = 1 to length(search_in) do found = match(search_for, search_in[A]) if found then temp = append(temp, search_in[A]) end if end for return temp end function sequence a1, a2, f1, f2, f3 a1 = {"cat", "bird", "rabbit"} a2 = {"frog", "dog", "snake"} f1 = fetch_strings("a", a1) --f1 now equals {"cat", "rabbit"} f2 = fetch_strings("og", a2) --f2 now equals {"frog", "dog"} f3 = fetch_strings("a", a2) --f3 now equals {"snake"} I hope this helps. Lucius L. Hilley III http://www.cdc.net/~lhilley -- a member of the Euphoria webring.
3. Re: wildcard usage
- Posted by Scott Murray <FaIkon1313 at AOL.COM> Apr 10, 1999
- 403 views
- Last edited Apr 11, 1999
>got a bit of a thing that has been driving me slowly insane since I first >started using EU. I have tried every permutation of code to create a '>wildcard' method to substitute for many lines of branching to strings of >data; question: is it possible to turn this...? > --string 1 > a1={"cat","dog","mouse"} > --string 2 > a2={"chicken","duck","cow"} > input=x string_to_fetch="a" & x > --where string_to_fetch is executable in the same way > --that either string_to_fetch=a1 or string_to_fetch=a2 is If I guess correctly, you're wanting the user to be able to specify a variable by name. The only ways I know of to do that is to store the name as part of the variable, or to use a parallel sequence: strings = { { "a1", "cat","dog","mouse"}, --string 1 { "a2", "chicken","duck","cow"} } --string 2 x = input() string_to_fetch = {} for c = 1 to length( strings ) do if not compare( strings[c][1], "a" & x ) then string_to_fetch = strings[c][2..length( strings[c] )] exit --for loop end if end for --if x was 1, then string_to_fetch would now be {"cat","dog","mouse"} if not compare( string_to_fetch, {} ) then --user entered number of nonexistant string end if Note that if you use real names (rather than a letter+number combination), that method makes more sense, if you just need a number you could just use the sequence subscript (after checking that it exists). The other method: strings = { { "cat","dog","mouse" }, --string 1 { "chicken","duck","cow" } } --string 2 names = { "a1", "a2" } x = input() string_to_fetch = {} temp_int = find( "a" & x, names ) if temp_int then string_to_fetch = strings[temp_int] else --user entered number of nonexistant string end if --if x was 1, then string_to_fetch would now be {"cat","dog","mouse"} Of course, this is more impressive when using real names too. ( "pets" and "livestock" instead of "a1" and "a2", maybe...) Either way requires storing all the variables in question in one big sequence. This is one of the things that dynamic sequences are especially good for.
4. Re: wildcard usage
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Apr 13, 1999
- 407 views
On Sat, 10 Apr 1999, Scott Murray wrote: ] >got a bit of a thing that has been driving me slowly insane since I first ] >started using EU. I have tried every permutation of code to create a ] '>wildcard' method to substitute for many lines of branching to strings of ] >data; question: is it possible to turn this...? ] ] > --string 1 ] > a1={"cat","dog","mouse"} ] > --string 2 ] > a2={"chicken","duck","cow"} ] ] > input=x string_to_fetch="a" & x ] > --where string_to_fetch is executable in the same way ] > --that either string_to_fetch=a1 or string_to_fetch=a2 is ] ] If I guess correctly, you're wanting the user to be able to specify a ] variable by name. The only ways I know of to do that is to store the ] name as part of the variable, or to use a parallel sequence: ] ] strings = { { "a1", "cat", "dog", "mouse"}, --string 1 ] { "a2", "chicken","duck","cow" } --string 2 ] } Or the simplest solution of all: sequence a integer x a = repeat({},2) a[1] = {"cat", "dog", "mouse"} a[2] = {"chicken", "duck", "cow" } x = 0 while x < 1 or x > 2 do x = input(x, "Which set of animals? 1 = House, 2 = Farm: ") -- one of my many input() ideas ;) end while animals = a[x] -- Carl R White -- cyrek- at -bigfoot.com -- http://www.bigfoot.com/~cyrek aka Cyrek -- No hyphens :) -- Bigfoot URL Alias