1. double slicing possible?

I was wondering if it was possible to slice two dimensions of a sequence in a
single statement.  Example:

--begin code
include file.e

procedure testprint(sequence text)
    for i=1 to length(text) do
    puts(1,text[i])
    end for
end procedure

sequence text1
text1 = {
        "Hi there",
        "Are you ",
        "New to E",
        "uphoria?"
    }

procedure Main()
    testprint(text1[1..3][3..7])  --the interpreter seems to end the
statement after the
end procedure               --[1..3] in this line and it stops
--end code
Is there any way to do this in a single statement?

TIA,
CHARN

new topic     » topic index » view message » categorize

2. Re: double slicing possible?

I don't think there is any way to do it with built-in commands, but you could
write a function:
function multiSlice(sequence s, sequence slices)
    sequence t
    integer l
    l = length(slices)
    s = s[slices[1][1]..slices[1][2]]
    if l > 1 then
        t = slices[2..l]
        for i = 1 to length(s) do
            s[i] = multiSlice(s[i],t)
        end for
    end if
    return s
end function

Jeffrey Fielding
JJProg at cyberbury.net
http://members.tripod.com/~JJProg/

CHARN1407 at AOL.COM wrote:

> I was wondering if it was possible to slice two dimensions of a sequence in a
> single statement.  Example:
>
> --begin code
> include file.e
>
> procedure testprint(sequence text)
>     for i=1 to length(text) do
>     puts(1,text[i])
>     end for
> end procedure
>
> sequence text1
> text1 = {
>         "Hi there",
>         "Are you ",
>         "New to E",
>         "uphoria?"
>     }
>
> procedure Main()
>     testprint(text1[1..3][3..7])  --the interpreter seems to end the
> statement after the
> end procedure               --[1..3] in this line and it stops
> --end code
> Is there any way to do this in a single statement?
>
> TIA,
> CHARN

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu