1. A better way to do this?
- Posted by Brent W. Hughes <bwh566 at yahoo.com> Feb 25, 2005
- 483 views
- Last edited Feb 26, 2005
Consider the following code which does not do what I want: --**************************************** procedure Sub2(sequence MyList) MyList[900] = 5 end procedure ----------------------------------------- procedure Sub1() sequence List List = repeat(0,10000) Sub2(List) -- Here, I would like List[900] to be 5. -- But, of course, it's not; it's 0. end procedure ------------------------------------------ Sub1() --**************************************** I really wanted Sub2 to change the 900th element of List. Here are a couple of solutions that I don't like: --**************************************** function Sub2(sequence MyList) MyList[900] = 5 return MyList end function ----------------------------------------- procedure Sub1() sequence List List = repeat(0,10000) List = Sub2(List) end procedure ------------------------------------------ Sub1() --**************************************** This has to copy 10000 elements to make one little change. Here's the other solution: --**************************************** sequence List ------------------------------------------ procedure Sub2() List[900] = 5 end procedure ------------------------------------------ procedure Sub1() List = repeat(0,10000) Sub2() end procedure ------------------------------------------ Sub1() --**************************************** I don't really like giving List such a wide scope in this way. Is there another, more elegant, solution to this problem?
2. Re: A better way to do this?
- Posted by Al Getz <Xaxo at aol.com> Feb 25, 2005
- 444 views
- Last edited Feb 26, 2005
Brent W. Hughes wrote: > Here are a couple of solutions that I don't like: > --**************************************** > function Sub2(sequence MyList) > MyList[900] = 5 > return MyList > end function > ----------------------------------------- > sequence List > List = repeat(0,10000) > List = Sub2(List) > ------------------------------------------ Hi there, I've used this technique myself many times, but mainly with small sequences. You could ask Rob how he implements function calls that declare privates that are also returned, but i think in order for the function to be truely recursive it has to create a new sequence (if the function calls itself). This is one of the reasons i was pushing for "re-includes"... that is, you can include a file several times in the same ew file and each time it creates a separate 'instance' of that include file. Like: include MyList.ew as ML1 include MyList.ew as ML2 now you have two lists: ML1:MyList and ML2:MyList so depending on which list you want to read/write to, you just use that one's name space qualifier, ML1 or ML2 in this case. Without that feature, you could copy the file MyList.ew and past it and rename it to MyList1.ew and the copy as MyList2.ew and include them both like: include MyList1.ew as ML1 include MyList2.ew as ML2 You then end up with the same functionality. Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
3. Re: A better way to do this?
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Feb 26, 2005
- 463 views
On Fri, 25 Feb 2005 14:52:37 -0800, "Brent W. Hughes" <guest at RapidEuphoria.com> wrote: <snip> >This has to copy 10000 elements to make one little change. obviously unacceptable, but the performance of option two should point you in the right direction. How about a new include file: >Here's the other solution: >--**************************************** >sequence List >------------------------------------------ global >procedure Sub2() > List[900] = 5 >end procedure >------------------------------------------ global >procedure Sub1() > List = repeat(0,10000) > Sub2() >end procedure >------------------------------------------ >Sub1() >--**************************************** >I don't really like giving List such a wide scope in this way. Then List is private, but Sub1 & Sub2 are not. Regards, Pete
4. Re: A better way to do this?
- Posted by Al Getz <Xaxo at aol.com> Feb 26, 2005
- 468 views
Brent W. Hughes wrote: > > Here's the other solution: > --**************************************** > sequence List > ------------------------------------------ > procedure Sub2() > List[900] = 5 > end procedure > ------------------------------------------ > procedure Sub1() > List = repeat(0,10000) > Sub2() > end procedure > ------------------------------------------ > Sub1() > --**************************************** > I don't really like giving List such a wide scope in this way. > > Is there another, more elegant, solution to this problem? > Hi again, Another idea is to put multiple lists within the same sequence, although it's still not as good... constant LIST1=1,LIST2=2,..etc. constant LASTLIST=LIST2 sequence List List=repeat("",LASTLIST) procedure Sub2(integer ListID) List[ListID][900]=5 end procedure List[LIST1]=repeat(0,10000) List[LIST2]=repeat(0,10000) Sub2(LIST1) Still bites Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
5. Re: A better way to do this?
- Posted by D. Newhall <derek_newhall at yahoo.com> Feb 26, 2005
- 442 views
Al Getz wrote: > > This is one of the reasons i was pushing for "re-includes"... > that is, you can include a file several times in the same ew file > and each time it creates a separate 'instance' of that include file. > Like: > include MyList.ew as ML1 > include MyList.ew as ML2 > > now you have two lists: > ML1:MyList > and > ML2:MyList > so depending on which list you want to read/write to, you > just use that one's name space qualifier, ML1 or ML2 in this case. > > Without that feature, you could copy the file MyList.ew and past it > and rename it to MyList1.ew and the copy as MyList2.ew and include them > both like: > include MyList1.ew as ML1 > include MyList2.ew as ML2 > > You then end up with the same functionality. Wow, I always assumed that was how Euphoria did things since in my tests building libraries to handle data structures it seemed to work (turns out I was calling the functions in such an order that it seemed to match up). Now, however, I find that it isn't like this. Well, that REALLY sucks. I guess I'm now going to have to rescind my statement on Euphoria's include statement being decent enough to do what you need. Without re-includes I can't do 70% of the projects I have planned but haven't gotten around to implementing yet. Also, I tried changing the path of the include to see if it'd load in the two DIFFERENT include files (test.e and test_dir\test.e) but sadly it didn't do that either killing off any hope of implementing many of my projects. Seriously Rob, you really, REALLY need to do something addressing these include/namespace issues that everyone keeps bringing up. Now I really love Euphoria (it's practically the best language ever) but in light of these glaring flaws in handling modularity I don't see a reason to keep Euphoria on my computer since I can't make managable and well-defined programs using the way the include statement is implemented now. Please, please, PLEASE try to adress some of these issues because I don't want to stop using this lovely language.
6. Re: A better way to do this?
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Feb 26, 2005
- 475 views
On Fri, 25 Feb 2005 22:10:46 -0800, "D. Newhall" <guest at RapidEuphoria.com> wrote: >Without re-includes I can't do 70% of the projects I have planned but >haven't gotten around to implementing yet. Nonsense. Write test.e. Write a batch file: copy test.e test2.e copy test.e test3.e ... and run it every time you amend test.e. Then you can include to your hearts content. Pete
7. Re: A better way to do this?
- Posted by D. Newhall <derek_newhall at yahoo.com> Feb 26, 2005
- 556 views
- Last edited Feb 27, 2005
Pete Lomax wrote: > Nonsense. Write test.e. Write a batch file: > copy test.e test2.e > copy test.e test3.e > ... > and run it every time you amend test.e. > Then you can include to your hearts content. True, but why should we have to do this? To have to manual copy include files and rename them or to run a script that does it before we can run our code is way too much work. If I add another "include foo as bar" then I need to run the script again to be able to test my program and clutter up my HD even more. Lack of re-includes I could probably tolerate but having two include files in different places on the harddrive with the same filename and only have one be included is just idiotic.
8. Re: A better way to do this?
- Posted by Alexander Toresson <alexander.toresson at gmail.com> Feb 26, 2005
- 448 views
- Last edited Feb 27, 2005
Brent W. Hughes wrote: > Consider the following code which does not do what I want: > --**************************************** > procedure Sub2(sequence MyList) > MyList[900] = 5 > end procedure > ----------------------------------------- > procedure Sub1() > sequence List > List = repeat(0,10000) > Sub2(List) > -- Here, I would like List[900] to be 5. > -- But, of course, it's not; it's 0. > end procedure > ------------------------------------------ > Sub1() > --**************************************** > I really wanted Sub2 to change the 900th element of List. > Here are a couple of solutions that I don't like: > --**************************************** > function Sub2(sequence MyList) > MyList[900] = 5 > return MyList > end function > ----------------------------------------- > procedure Sub1() > sequence List > List = repeat(0,10000) > List = Sub2(List) > end procedure > ------------------------------------------ > Sub1() > --**************************************** > This has to copy 10000 elements to make one little change. > Here's the other solution: > --**************************************** > sequence List > ------------------------------------------ > procedure Sub2() > List[900] = 5 > end procedure > ------------------------------------------ > procedure Sub1() > List = repeat(0,10000) > Sub2() > end procedure > ------------------------------------------ > Sub1() > --**************************************** > I don't really like giving List such a wide scope in this way. > > Is there another, more elegant, solution to this problem? > Unfortunately, no. I've also noticed the problem. If you could do pass-by-reference in euphoria, this would have been solved. I used the same solution as you in an app of mine, however, I had 6 big sequences. This means I had to duplicate the *same* code 6 times, and I had to fix bugs 6 times, add features 6 times etc, which was *very* unelegant. However, this sped up the program by at least 100x. So if pass-by-reference would be implemented, we'd get this advantage without this ugly hack. Regards, Alexander Toresson
9. Re: A better way to do this?
- Posted by Alexander Toresson <alexander.toresson at gmail.com> Feb 26, 2005
- 454 views
- Last edited Feb 27, 2005
Pete Lomax wrote: > > > On Fri, 25 Feb 2005 22:10:46 -0800, "D. Newhall" > <guest at RapidEuphoria.com> wrote: > > >Without re-includes I can't do 70% of the projects I have planned but > >haven't gotten around to implementing yet. > Nonsense. Write test.e. Write a batch file: > copy test.e test2.e > copy test.e test3.e > ... > and run it every time you amend test.e. > Then you can include to your hearts content. > > Pete > Duplicating code is really silly, and this particular solution has even more flaws. It's not platform-independent. Yeah, I know that you could make it to run on every platform currently supported by euphoria simply by using "cp" instead of "copy" on linux and freebsd, but I'm talking about platforms still waiting for being taken over by euphoria. For example, you can't expect an embedded system to even be able to change the files it has in its memory. And this means that programs that are generally portable, will have to be changed before being run on a new platform. Regards, Alexander Toresson And yes, I advocate for an open source euphoria.