slicing of sequences
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!
|
Not Categorized, Please Help
|
|