1. LENGTH OF SEQUENCES

I tried looking around for a solution to my problem, but I haven't found
one yet, so please bare with me on this one if it's been explained before.

The length function is sometimes not sufficient for me, as I might want to
determin the TRUE length of a sequence. Let's say i have a sequence 'Stuff'
that has the following structure;

{
 {"Data1.1", 0, 0}, 
 {"Data2.1", "Data2.2"}, 
 {"Data3.1", {"Data3.2.1", "Data3.2.2"}}
}

Now, if I'm not mistaking, the length of 'stuff' - length(stuff) - would
in this case result in 3 as it counts only the upper levels of the sequence.
And, as you can see, the data structure is inconsistent and it might (afaik)
take some programming to determin the true structure of 'stuff'. What I
want is to have a function that returns the whole content of a structure
in a one level sequence, eg. for 'stuff' this would be;
{"Data1.1", 0, 0, "Data2.1", "Data2.2", "Data3.1", "Data3.2.1", "Data3.2.2"}
or in other words; the whole structure of 'stuff' converted into a string.

I'm gonna use this to display the content sequences in a readable format 
for message_box. (Where I will ofcourse exchange non-printable char's into
a "." - or what ever char i decide to use.)

Hope I haven't misunderstood the foundation of sequences and made an ass of
myself! :D

PS! I'm a w32True noob in Euphoria, but I've had alot of experience with
programming on a hobby basis. (Made a few app's for my colleages at work
to ease their pains, but not in Euphoria YET.)

Regards Kenneth aka ZNorQ

new topic     » topic index » view message » categorize

2. Re: LENGTH OF SEQUENCES

I hope this one is useful...


global function flatten(object st)
        object hs
        
        if atom(st) then
                return st
        else
                for i = 1 to length(st) do
                        if not atom(st[i]) then
                                hs = {}
                                for j = 1 to length(st) do
                                        hs &= flatten(st[j])
                                end for
                                return hs
                        end if
                end for
                return {st}
        end if
end function





Z> posted by: ZNorQ <znorq at holhaug.com>

Z> I tried looking around for a solution to my problem, but I haven't found
Z> one yet, so please bare with me on this one if it's been explained before.

Z> The length function is sometimes not sufficient for me, as I might want to
Z> determin the TRUE length of a sequence. Let's say i have a sequence 'Stuff'
Z> that has the following structure;

Z> {
Z>  {"Data1.1", 0, 0}, 
Z>  {"Data2.1", "Data2.2"}, 
Z>  {"Data3.1", {"Data3.2.1", "Data3.2.2"}}
Z> }

Z> Now, if I'm not mistaking, the length of 'stuff' - length(stuff) - would
Z> in this case result in 3 as it counts only the upper levels of the sequence.
Z> And, as you can see, the data structure is inconsistent and it might (afaik)
Z> take some programming to determin the true structure of 'stuff'. What I
Z> want is to have a function that returns the whole content of a structure
Z> in a one level sequence, eg. for 'stuff' this would be;
Z> {"Data1.1", 0, 0, "Data2.1", "Data2.2", "Data3.1", "Data3.2.1", "Data3.2.2"}
Z> or in other words; the whole structure of 'stuff' converted into a string.

Z> I'm gonna use this to display the content sequences in a readable format
Z> for message_box. (Where I will ofcourse exchange non-printable char's into
Z> a "." - or what ever char i decide to use.)

Z> Hope I haven't misunderstood the foundation of sequences and made an ass of
Z> myself! :D

Z> PS! I'm a w32True noob in Euphoria, but I've had alot of experience with
Z> programming on a hobby basis. (Made a few app's for my colleages at work
Z> to ease their pains, but not in Euphoria YET.)

Z> Regards Kenneth aka ZNorQ

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

3. Re: LENGTH OF SEQUENCES

ZNorQ wrote:
> 
> I tried looking around for a solution to my problem, but I haven't found
> one yet, so please bare with me on this one if it's been explained before.
> 
> The length function is sometimes not sufficient for me, as I might want to
> determin the TRUE length of a sequence. Let's say i have a sequence 'Stuff'
> that has the following structure;
> 
> {
>  {"Data1.1", 0, 0}, 
>  {"Data2.1", "Data2.2"}, 
>  {"Data3.1", {"Data3.2.1", "Data3.2.2"}}
> }
> 
> Now, if I'm not mistaking, the length of 'stuff' - length(stuff) - would
> in this case result in 3 as it counts only the upper levels of the sequence.
> And, as you can see, the data structure is inconsistent and it might (afaik)
> take some programming to determin the true structure of 'stuff'. What I
> want is to have a function that returns the whole content of a structure
> in a one level sequence, eg. for 'stuff' this would be;
> {"Data1.1", 0, 0, "Data2.1", "Data2.2", "Data3.1", "Data3.2.1", "Data3.2.2"}
> or in other words; the whole structure of 'stuff' converted into a string.
> 
> I'm gonna use this to display the content sequences in a readable format 
> for message_box. (Where I will ofcourse exchange non-printable char's into
> a "." - or what ever char i decide to use.)
> 

I use a modified version of Gabriel Boehme's print.e, which I've called
sprint.e.   You can get the file from several sources: EDB, EuSQL, matheval,
all in the RDS User Contributions.

Matt Lewis

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

4. Re: LENGTH OF SEQUENCES

> Subject: LENGTH OF SEQUENCES
> 
> 
> posted by: ZNorQ <znorq at holhaug.com>
> 
> I tried looking around for a solution to my problem, but I haven't found
> one yet, so please bare with me on this one if it's been explained before.
> 
> The length function is sometimes not sufficient for me, as I might want to
> determin the TRUE length of a sequence. Let's say i have a sequence 'Stuff'
> that has the following structure;
> 
> {
>  {"Data1.1", 0, 0}, 
>  {"Data2.1", "Data2.2"}, 
>  {"Data3.1", {"Data3.2.1", "Data3.2.2"}}
> }
> 
> Now, if I'm not mistaking, the length of 'stuff' - length(stuff) - would
> in this case result in 3 as it counts only the upper levels of the sequence..
> And, as you can see, the data structure is inconsistent and it might (afaik)
> take some programming to determin the true structure of 'stuff'. What I
> want is to have a function that returns the whole content of a structure
> in a one level sequence, eg. for 'stuff' this would be;
> {"Data1.1", 0, 0, "Data2.1", "Data2.2", "Data3.1", "Data3.2.1", "Data3.2.2"}
> or in other words; the whole structure of 'stuff' converted into a string.


> I'm gonna use this to display the content sequences in a readable format 
> for message_box. (Where I will ofcourse exchange non-printable char's into
> a "." - or what ever char i decide to use.)
> 
> Hope I haven't misunderstood the foundation of sequences and made an ass of
> myself! :D
> 
> PS! I'm a w32True noob in Euphoria, but I've had alot of experience with
> programming on a hobby basis. (Made a few app's for my colleages at work
> to ease their pains, but not in Euphoria YET.)
> 
> Regards Kenneth aka ZNorQ
> > > {
>  {"Data1.1", 0, 0}, 
>  {"Data2.1", "Data2.2"}, 
>  {"Data3.1", {"Data3.2.1", "Data3.2.2"}}
> }

A first approach would be to use sprint(), which turns any Eu object into a 
string you can get() later and transform in the meantime. sprint() hives you 
the string you posted, without the line breaks.

You could consider coding something like this:
type satom(object x)
--check for atom or string, ie sequence of atoms
if sequence(x) then
   for i=1 to length(x) do
     if sequence(x[i]) then return 0 end if
   end for
end if
return 1
end type

function flatten(sequence s)
--returns a flat sequence from one that has arbitrarily deeply nested elements
object x
sequence result result=""
for i=1 to length(s) do
   x=s[i]
   if satom(x) then result=append(result,x)
       --not sure if result&={x} is faster
   else result&=flatten(x)
   end if
end for
return result
end function


Your sequence would become like you wished.

For more advanced processing, look into the strtok library by Kat, which is 
very flexible in that particular area.

CChris

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

5. Re: LENGTH OF SEQUENCES

On Thu, 17 Feb 2005 02:29:31 -0800, ZNorQ <guest at RapidEuphoria.com>
wrote:

>What I
>want is to have a function that returns the whole content of a structure
>in a one level sequence, eg. for 'stuff' this would be;
>{"Data1.1", 0, 0, "Data2.1", "Data2.2", "Data3.1", "Data3.2.1", "Data3.2.2"}
>or in other words; the whole structure of 'stuff' converted into a string.
>
>I'm gonna use this to display the content sequences in a readable format 
>for message_box.
my pretty print should work for this, using:

	void = message_box( ppf( Stuff ), "Title",0)

You can also set the column wrap:

	void = message_box( ppExf( Stuff, {pp_Maxlen,120}), "Title", 0)

http://palacebuilders.pwp.blueyonder.co.uk/eppp.html

Try this:
sequence Stuff
Stuff=
{
 {"Data1.1", 0, 0}, 
 {"Data2.1", "Data2.2"}, 
 {"Data3.1", {"Data3.2.1", "Data3.2.2"}}
}
include msgbox.e
include ppp.e
object void
	void = message_box( ppf( Stuff ), "Title",0)
	void = message_box( ppExf( Stuff, {pp_Maxlen,120}), "Title", 0)
	void = message_box( ppExf( Stuff, {pp_Maxlen,20}), "Title", 0)


Regards,
Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu