Re: Homogeneous sequence
- Posted by Bob Elia <bobelia200 at netzero.n??> Aug 12, 2007
- 665 views
Bob Elia (me) wrote: > > Juergen Luethje wrote: > > > > Ricardo Forno wrote: > > > > > Hi all. > > > While reading this thread, I browsed my General Functions package and saw > > > an obvious mistake in the example for the Structure function, which does > > > a very similar thing to one of the functions discussed here. > > > For now, I don't plan to post a correction, because the mistake is so > > > obvious. > > > Regards. > > > > Hello Ricardo, > > > > this reminds me ... > > When looking for the solution of a general problem, I actually should > > firstly look into your great General Functions package. > > > > Regards, > > Juergen > > Hi, Juergen > > This works, I think, though I'd rather have an iterative solution. > > }}} <eucode> > type seq_of_atom_or_empty(sequence s) > if equal(s, {}) then > return 1 > end if > for i = 1 to length(s) do > if sequence(s[i]) then > return 0 > end if > end for > return 1 > end type > > function object_structure_2(object x) > if atom(x) then > return 1 > elsif seq_of_atom_or_empty(x) then > return {} > end if > > for i = 1 to length(x) do > x[i] = object_structure_2(x[i]) > end for > return x > end function > > global type homogeneous_sequence_2 (object x) > object struc > > if atom(x) then > return 0 > end if > > if length(x) = 0 then > return 1 -- ? > end if > > struc = object_structure_2(x[1]) > for i = 2 to length(x) do > if not equal(struc, object_structure_2(x[i])) then > return 0 > end if > end for > > return 1 > end type > > > -- Demo: > object a, b, c > a = {3,{3 ,5,{5,2},4}} > b = {4,{5 ,1,{9,2},4}} > c = {4,{{},1,{9,2},4}} > > -- ? object_structure(a) > -- ? object_structure(b) > -- ? object_structure(c) > -- ? homogeneous_sequence({a,b}) > -- ? homogeneous_sequence({a,c}) > -- ? homogeneous_sequence({b,c}) > ? object_structure_2(a) > ? object_structure_2(b) > ? object_structure_2(c) > ? homogeneous_sequence_2({a,b}) > ? homogeneous_sequence_2({a,c}) > ? homogeneous_sequence_2({b,c}) > > </eucode> {{{ > > Bob Nope, that doesn't work. I was trying to account for strings of un-equal length but {65,66,67} might not be one. Oops. In what form is the user providing this data? As Euphoria objects? Or are you converting it? Bob