1. Transforming a Sequence from a Pattern

I need help duplicating a sequence structure... here's what I mean:

I've got two sequences:

fields = {{{},{}},{},{}} 
ftypes = ",.E+" 

The 4 total "bottom-level" elements in fields correspond to the 4 total elements in ftypes, though the structure for each sequence is different.

What I'd like to do is transform ftypes into the same structure as fields, so that

ftypes = {{',','.'},'E','+'} 

Is that clear? Who's got a function for this that works with 4.0? smile

new topic     » topic index » view message » categorize

2. Re: Transforming a Sequence from a Pattern

euphoric said...

I need help duplicating a sequence structure... here's what I mean:

I've got two sequences:

fields = {{{},{}},{},{}} 
ftypes = ",.E+" 

The 4 total "bottom-level" elements in fields correspond to the 4 total elements in ftypes, though the structure for each sequence is different.

What I'd like to do is transform ftypes into the same structure as fields, so that

ftypes = {{',','.'},'E','+'} 

Is that clear? Who's got a function for this that works with 4.0? smile

Since I know what you're up to* smile I'll give you a hint. Take a look at INFO.INDICES in TABLEDEF. Then you can use either the seq_store() in eusql or the equivalent (IIRC) in std/sequence.e

Matt

* Enhancing eusql to deal with possibly damaged records

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

3. Re: Transforming a Sequence from a Pattern

mattlewis said...
euphoric said...

I need help duplicating a sequence structure...

Take a look at INFO.INDICES in TABLEDEF. Then you can use either the seq_store() in eusql or the equivalent (IIRC) in std/sequence.e

I got that far (stumbled upon seq_store() in std/sequence.e while looking for helpful sequence functionality) but couldn't get any further, so I threw my hands in the air and reverted. grin

Maybe I'll give it a go tomorrow. Looks like I'll need a recursive function, but then I saw seq_store and it doesn't use recursion! I'm like, what the hey?!?!

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

4. Re: Transforming a Sequence from a Pattern

integer crash 
crash = 1000 
function ckmerger(sequence fields, sequence ftypes) 
	sequence ff 
	sequence result 
 
	crash -= 1 
	if (crash = 0) then 
		print(1, "ERROR: function is corrupt.\n") 
		abort(0) 
	end if 
	if length(fields) then 
		for i = 1 to length(fields) do 
			ff = ckmerger(fields[i], ftypes) 
			fields[i] = ff[1] 
			ftypes = ff[2] 
		end for 
		result = {fields, ftypes} 
	else 
		result = {ftypes[1], ftypes[2..length(ftypes)]} 
	end if 
 
	crash += 1 
	return result 
end function 
 
sequence fields, ftypes 
 
fields = {{{},{}},{},{}} 
ftypes = ",.E+" 
 
ftypes = ckmerger(fields, ftypes) 
ftypes = ftypes[1] 
 
include misc.e 
pretty_print(1, ftypes, {}) 
puts(1, "\n") 

Unkmar tested. Someone else should approve. :P

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

5. Re: Transforming a Sequence from a Pattern

Thank you so much! Awesome! grin

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

Search



Quick Links

User menu

Not signed in.

Misc Menu