1. slicing of sequences
- Posted by James Powell <Wizard at DJO.COM> Apr 26, 1997
- 828 views
Im at a loss as how to proceed here. I know I can build a routine that will do the following code, but I would rather use a built in Euphoria statement than build my own, since it will be called often. ( I think that a built in routine dealing with slicing sequences would be faster than any loop I create to do the same thing.) Anyway, here's a piece of sample code demonstrating what I would like to do, Euphoria's responce, and an explanation of the result I think I should get. -- Program Test.ex -- sequence a, b a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} b = a[1..3][3] -- End Test.ex -- When run, Euphoria responds with: b = a[1..3][3] ^Unknown Command What I am trying to do is get the 3rd element of all the sequences in a. So theoretically, b should contain {3, 6, 9}, ie. b = {a[1][3], a[2][3], a[3][3]}. The reason I did this short test program is because I would like to write a routine that contains the following code: -- Code -- function Numof3in(sequence a) atom numfound, done numfound = 0 done = 0 while not done do if find(3, a) then a = a[(find(3, a) + 1)..length(a)] numfound = numfound + 1 else done = 1 end if end while return numfound end function for Da_Loop = 1 to Numof3in(Da_Seq[1..(length(Da_Seq))][4]) end for -- End Code -- NOTE: No attempt has yet been made to see if the function Numof3in() actually works. Hopefully, you get the idea of what I am trying to do with this code. Any ideas as how to procede using the built in slicing functions? Could this be added to a future version of Euphoria, or am I asking to much? Just a little question/idea I had. James Powell PS. Here's a little tip for other programmers. ; ) There are 2 ways to write bug free code, and only the 3rd way works!
2. slicing of sequences
- Posted by Mike Fowler <stoner at NELSUN.GEN.NZ> Apr 26, 1997
- 824 views
- Last edited Apr 27, 1997
<SNIP> -> Anyway, here's a piece of sample code demonstrating what I would like -> to do, Euphoria's responce, and an explanation of the result I think -> I should get. -> -- Program Test.ex -- -> sequence a, b -> a = {{1, 2, 3}, -> {4, 5, 6}, -> {7, 8, 9}} -> b = a[1..3][3] -> -- End Test.ex -- well heres the fix :) -- Start Test.ex -- sequence a, b b = {} -- added a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} --b = a[1..3][3] -- removed for c = 1 to length(a) do -- added b = append(b, (a[c][3])) -- added end for -- added print(1, b) -- added -- End Test.ex -- -> When run, Euphoria responds with: -> b = a[1..3][3] -> ^Unknown Command i dont know why that is, but someone else will :) Hope thats a help Mike Fowler - mike.fowler at nelsun.gen.nz o__ --- _,>/'_ --- (_) \(_) --- Tips for the month: Bill your dentist for your time in surgery.
3. slicing of sequences
- Posted by Robert Craig <robert_craig at COMPUSERVE.COM> Apr 26, 1997
- 818 views
- Last edited Apr 27, 1997
James Powell writes: > Could this be added to a future version of Euphoria, or am I asking to much? I would recommend that you write your own Euphoria function to do this "column" slice operation. I do not expect that this feature will be added to Euphoria for the following reasons: 1. I can't do the operation *that* much faster than you can. 2. I don't think the operation would be used in that many programs, and when it was, speed would not necessarily be critical. Regards, Rob Craig Rapid Deployment Software
4. Re: slicing of sequences
- Posted by Marcel Kollenaar <M.Kollenaar at SLO.NL> Apr 27, 1997
- 805 views
James Powell wrote: > > -- Program Test.ex -- > > sequence a, b > > a = {{1, 2, 3}, > {4, 5, 6}, > {7, 8, 9}} > b = a[1..3][3] > > -- End Test.ex -- > > When run, Euphoria responds with: > > b = a[1..3][3] > ^Unknown Command > b = a[1..3] is the same as a, a = {{1,2,3},{4,5,6},{7,8,9}} and the last index [3] doesn't exist so Euphoria complains. So a[1] = {{1,2,3}}, a[2] = {{4,5,6}} etc. You need to write b[1] = a[1][3]. Put it in a loop. for i = 1 to length(a) do b[i] = a[i][3] end for b = {3,6,9} Marcel Kollenaar