Re: Split, combine ok but where's extract?

2005-02-13 Thread David Vaughan
On 14/02/2005, at 4:00, Alex Tweedly [EMAIL PROTECTED] wrote:
snip
If you take the case of
  put 1,2 into myArray[a,b]
  put 1,3 into myarray[c,d]
snip
Nope. It will actually give
v1 = a,c
v2 = b,d
v3 = 1
v4 = 3  the other value got lost in the split immediately 
before the assignment to v3; I don't know if it's theoretically 
guaranteed which of the values it will give, but in practice, with few 
entries, it will give the latter one.

Alex
Perhaps I have misunderstood the depth of the problem. I do not appear 
to have the described difficulty with the example data.
Here is code (assume a couple of testing fields, f1 and f2) and the 
results using your actual example data.

  put 1,2 into myArray[a,b]
  put 1,3 into myarray[c,d]
  put the keys of myArray into field f1
  combine myArray with return
  put myArray into field f2
splits the keys from the data, preserving all components, while (using 
data from the fields as created above)

  put field f1 into tData -- the a,b \r c,d data
  put field f2 into tKeys -- the 1,2 \r 1,3 data
  split tData with return
  put 1 into i
  repeat for each line x in tKeys
put tData[i] into myArray[x]
add 1 to i
  end repeat
-- and to prove it happened
  combine myArray with return and #
  put myArray into field f2
puts them back in an array. The only relevant possibility of 
duplication appears to be with the keys of the original array, which by 
definition were not duplicated anyway.

I receive the digest so discussions may be slow.
regards
David
--
Alex Tweedly   http://www.tweedly.net
___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-13 Thread David Vaughan
Xavier, Alex and all.
The principal difficulty with the split/combine code I have suggested 
for extract/merge is that key order is not preserved in relation to the 
data when you get the keys. If you wish to re-merge after an extract 
then you must know what is the correct key order (e.g. a simple sort).

Oh, and I also reversed the data and keys in the second code block 
(first two lines) compared with the extract. Mechanical error.

regards
David
___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-13 Thread Alex Tweedly
David Vaughan wrote:
Perhaps I have misunderstood the depth of the problem. I do not appear 
to have the described difficulty with the example data.
The problem (as I understand it) was to split out the columns of the 
keys and/or the data of an array.

That's what the code you first proposed did (or tried to do); the 
fragment shown in this (tonight's) email is only the first half of the 
code - and therefore doesn't get far enough into it to demonstrate the 
problem.

Here is code (assume a couple of testing fields, f1 and f2) and 
the results using your actual example data.

  put 1,2 into myArray[a,b]
  put 1,3 into myarray[c,d]
  put the keys of myArray into field f1
  combine myArray with return
  put myArray into field f2
Indeed, there's no problem there - it would be the next part which 
dissected the columns of the data that shows the problem.

Here's the complete section of code as you first sent it (with a couple 
of with returns added as you suggested)

put the keys of myArray into tKeys
split tKeys with return and comma
put the keys of tKeys into v1
combine tKeys  with return   -- discards the keys
put tKeys into v2
combine myArray  with return  -- discards the keys
split myArray with return and comma
put the keys of myArray into v3
combine myArray  with return
put myArray into v4
Now, v1=a, v2=b, v3=n1, v4=n2
(or close enough if I made a coding error)
i.e. v1 is the first column (of the keys), v2 is the second, v3 is the 
first column from the data and v4 is the second column from the data.

Now if you take my data
  put 1,2 into myArray[a,b]
 put 1,3 into myarray[c,d]
then run the above algorithm, what you get is
v1 = a \r b
v2 = c \r d
v3 = 1
v4 = 3
which is not what we need - the duplicate item 1 in column 3 (col 1 of 
the data) caused a problem.

snip
puts them back in an array. The only relevant possibility of 
duplication appears to be with the keys of the original array, which 
by definition were not duplicated anyway.

Not really.  By definition, the *complete* keys of the original array 
are not duplicated; but the problem arises because items within any 
particular column CAN be duplicates.   Here's your second code fragment 
- but with different values to demonstrate the problem

 put field f1 into tData -- the a,b \r c,d data -- LET's make f1 
contain   3,4 \r3,5
 put field f2 into tKeys -- the 1,2 \r 1,3 data
 split tData with return   -- 
causes a problem
 put 1 into i
 repeat for each line x in tKeys
   put tData[i] into myArray[x]
   add 1 to i
 end repeat
-- and to prove it happened
 combine myArray with return and #
 put myArray into field f2

And this shows the problem. The 3rd line split tData with return 
results in a single array entry, tData[3] = 5, because of the 
duplication of the 3 - even though 3,4 didn't duplicate 3,5

I receive the digest so discussions may be slow.
In some ways this discussion is more complex than it need be - Xavier's 
second example (including the code he posted) was simply separating out 
the columns (and merging the columns) of a single columnar table.

So the problem is :  given a table
1,2,3,4
5,6,7,8
9,10,11,12
generate separate lists of the columns
v1 = 1 \r 5 \r 9 (spaces for readability only)
v2 = 2 \r 6 \r 10
v3 = 3 \r 7 \r 11
v4 = 4 \r 8 \r 12
This is (in effect) what your initial code proposal would do (adjusting 
for a table instead of an array), and is also what Xavier's code would do.

But given different input
1,2,3,4
5,2,7,8
9,10,11,12
his would give
v1 = 1 \r 5 \r 9 (spaces for readability only)
v2 = 2 \r 2 \r 10
v3 = 3 \r 7 \r 11
v4 = 4 \r 8 \r 12
and re-merging would get back the original input value.
However, your's would give
v1 = 1 \r 5 \r 9 (spaces for readability only)
v2 = 2 \r 10
v3 = 7 \r 11
v4 = 8 \r 12
and there would be no way to recover the initial value.
--
Alex Tweedly   http://www.tweedly.net
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005
___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-13 Thread Alex Tweedly
David Vaughan wrote:
Oh, and I also reversed the data and keys in the second code block 
(first two lines) compared with the extract. Mechanical error.
I didn't even notice that :-)
Well - that makes it even clearer . here's your second code 
fragment, with the reversal un-reversed.

 put field f1 into tKeys -- the a,b \r c,d data(reversal restored)
 put field f2 into tData -- the 1,2 \r 1,3 data
 split tData with return
(and already there is a problem - tData has a single entry tData[1] = 3 )
 put 1 into i
 repeat for each line x in tKeys
   put tData[i] into myArray[x]
   add 1 to i
 end repeat
-- and to prove it happened
 combine myArray with return and #
 put myArray into field f2
puts them back in an array.
--
Alex Tweedly   http://www.tweedly.net
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005
___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-12 Thread Alex Tweedly
MisterX wrote:
Mark,
I did say I already wrote a function to extract these
but is there no split combination that does this without
a slow loop?
Here's the two functions I used
function MergeColumns
end MergeColumns
I'm still trying to understand just what that one does (in all cases) so 
I'll start with the simpler one.

function ExtractItems tabl,column,adelimiter
 if adelimiter is not empty then
   set the itemdelimiter to adelimiter
 end if
 
 local a
 put  into a
 local x=1
 repeat for each line L in tabl
   put (item column of l) into line x of a
   add 1 to x
 end repeat
 return a
end ExtractItems
 

x is used only to count the number of lines,and changed only when a new 
line is added the end - so just use put after

function ExtractItems tabl,column,adelimiter
 local a
 if adelimiter is not empty then
   set the itemdelimiter to adelimiter
 end if
 
 repeat for each line L in tabl
   put (item column of L)  cr after a
 end repeat
 delete the last char of a 
 return a
end ExtractItems


Of which the MergeColumn could use lots of optimizing ;)
But they're slow functions compared to split or combine.
 

I can't see a way to use split/combine (except for the special case of 
first col).

--
Alex Tweedly   http://www.tweedly.net

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005
___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-12 Thread Alex Tweedly
MisterX wrote:
I can't see any radically different approach - but you can certainly 
optimize the details

function MergeColumns
 local xp,y,linecount,z,c
 put the paramcount into xp
 
 put empty into y
 put empty into linecount
 repeat with x = 1 to xp
   put the number of lines in param(x)  comma after linecount
 end repeat
 delete last char of linecount
 put max(linecount) into linecount
 

Then either
 repeat with x = 1 to linecount
   repeat with y = 1 to xp
 put line x of param(y)  comma after line x of c
   end repeat
   delete last char of c
 end repeat
 

or (probably better)
 repeat with x = 1 to linecount
   repeat with y = 1 to xp
 put line x of param(y) comma after c
   end repeat
   delete last char of c
   put cr after c
 end repeat
 

It would be worth experimenting with turning the loop inside out
  repeat with x = 1 to xp
put param(x) into theLine
repeat with y = 1 to linecount
  put line y of theLine  comma after line y of c
end repeat
  end repeat
  repeat with y = 1 to linecount
 delete the last char of line y of c
  end repeat
but I don't think that will be faster.
--
Alex Tweedly   http://www.tweedly.net

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005
___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-12 Thread Richard Gaskin
Alex Tweedly wrote:
MisterX wrote:
or (probably better)
 repeat with x = 1 to linecount
   repeat with y = 1 to xp
 put line x of param(y) comma after c
   end repeat
   delete last char of c
   put cr after c
 end repeat
It would be worth experimenting with turning the loop inside out
  repeat with x = 1 to xp
put param(x) into theLine
repeat with y = 1 to linecount
  put line y of theLine  comma after line y of c
end repeat
  end repeat
  repeat with y = 1 to linecount
 delete the last char of line y of c
  end repeat
but I don't think that will be faster.
Darn, Alex, I got so used to being amazed with your nifty use of arrays 
I was betting on you coming up with a one-liner for this. :)

--
 Richard Gaskin
 Fourth World Media Corporation
 ___
 [EMAIL PROTECTED]   http://www.FourthWorld.com
___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-12 Thread David Vaughan
On 13/02/2005, at 4:00, MisterX [EMAIL PROTECTED] wrote:
Xavier
I have not searched back to your original request, but if I understand 
it correctly then you wish to be able to de-merge columns from an 
array, and that these columns may be of the data or of the keys. Let us 
assume you have an array where an element is defined by:
put n1,n2 into myArray[a,b]

Here, you can extract anything from the keys or the element using split 
and combine. For example, this code places all four columns in separate 
variables  v1-v4 (untested)

put the keys of myArray into tKeys
split tKeys with return and comma
put the keys of tKeys into v1
combine tKeys   -- discards the keys
put tKeys into v2
combine myArray  -- discards the keys
split myArray with return and comma
put the keys of myArray into v3
combine myArray
put myArray into v4
Now, v1=a, v2=b, v3=n1, v4=n2
(or close enough if I made a coding error)
I have a column merge function somewhere. I will look it up to see if 
it is any improvement over what you have.

regards
David
___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-12 Thread David Vaughan
Moron me! Doing some edits from my test script I omitted the line add 
1 to i just before  end repeat

On 13/02/2005, at 10:43, David Vaughan wrote:
Xavier
This is the merge part
Assume you have the following two variables:
v1 contains a
v2 contains b
  split v2 with return
  put 1 into i
  repeat for each line x in v1
put v2[i] into myArray[x]
  end repeat
  combine myArray with return and comma
myArray is now a list whose first line is a,b
This code avoids any repeat with i = 1 to n loops and is thus fairly 
linear in time taken with longer lists.

Incidentally, I left with return off a couple of lines in the 
previous extract code.

I have not done any speed tests.
Hope this is relevant.
regards
David
___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


RE: Split, combine ok but where's extract?

2005-02-12 Thread MisterX

Just sweet! I'll test it monday (or before) on my 2k lines tables ;)

Surely will be shocking and you'll be famous!

Gza

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of 
 David Vaughan
 Sent: Sunday, February 13, 2005 00:46
 To: use-revolution@lists.runrev.com
 Subject: Re: Split, combine ok but where's extract? 
 
 Moron me! Doing some edits from my test script I omitted the line add
 1 to i just before  end repeat
 
 On 13/02/2005, at 10:43, David Vaughan wrote:
 
  Xavier
 
  This is the merge part
  Assume you have the following two variables:
  v1 contains a
  v2 contains b
 
split v2 with return
put 1 into i
repeat for each line x in v1
  put v2[i] into myArray[x]
end repeat
combine myArray with return and comma
 
  myArray is now a list whose first line is a,b
 
  This code avoids any repeat with i = 1 to n loops and is 
 thus fairly 
  linear in time taken with longer lists.
 
  Incidentally, I left with return off a couple of lines in the 
  previous extract code.
 
  I have not done any speed tests.
 
  Hope this is relevant.
 
  regards
  David
 ___
 use-revolution mailing list
 use-revolution@lists.runrev.com
 http://lists.runrev.com/mailman/listinfo/use-revolution
 

___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-12 Thread Alex Tweedly
David Vaughan wrote:
On 13/02/2005, at 4:00, MisterX [EMAIL PROTECTED] wrote:
Xavier
I have not searched back to your original request, but if I understand 
it correctly then you wish to be able to de-merge columns from an 
array, and that these columns may be of the data or of the keys. Let 
us assume you have an array where an element is defined by:
put n1,n2 into myArray[a,b]

Here, you can extract anything from the keys or the element using 
split and combine. For example, this code places all four columns in 
separate variables  v1-v4 (untested)

put the keys of myArray into tKeys
split tKeys with return and comma
put the keys of tKeys into v1
combine tKeys   -- discards the keys
put tKeys into v2
combine myArray  -- discards the keys
split myArray with return and comma
put the keys of myArray into v3
combine myArray
put myArray into v4
Now, v1=a, v2=b, v3=n1, v4=n2
(or close enough if I made a coding error)
I have a column merge function somewhere. I will look it up to see if 
it is any improvement over what you have.
David,
I may have missed something in the original problem description, but I 
think there's a problem with this scheme.

If you take the case of
  put 1,2 into myArray[a,b]
  put 1,3 into myarray[c,d]
I believe what Xavier wants (at least, what his posted code gives - 
though it used a simple table not keys) is
v1 = a,c
v2 = b,d
v3 = 1,1
v4 = 2,3

Note particularly v3 - using the various repeat forms, it has each 
item from the column.

split/combine will remove duplicates - and hence give
v1 = a,c
v2 = b,d
v3 = 1
v4 = 2,3
There's a similar problem with the merge code - repeated values in a 
column cause loss of data.

--
Alex Tweedly   http://www.tweedly.net

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005
___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Split, combine ok but where's extract?

2005-02-11 Thread MisterX
Just wondering if there is a simple way to extract the list of the second
key of an array

I have an array like

array[x]=text1,text2 

I need to get either the list of text1 or text 2...

I could create more variables but that's not clean in this design of mine.

I have an extract function that repeat for each line but is there a better
way to extract columns from a table using split, combine or ???

TIA guys!

Wish ya'll a great weekend!

Xavier
--
MonsieurX.com - working on that GUI translator!

___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-11 Thread Mark Wieder
MisterX-

Friday, February 11, 2005, 9:07:06 AM, you wrote:

M Just wondering if there is a simple way to extract the list of the second
M key of an array

repeat for each line theItem in the keys of array
  put item 2 of array[theItem] after field myField
end repeat

-- same obviously for item 1

-- 
-Mark Wieder
 [EMAIL PROTECTED]

___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Split, combine ok but where's extract?

2005-02-11 Thread Dick Kriesel
On 2/11/05 5:53 PM, Mark Wieder [EMAIL PROTECTED] wrote:

 MisterX-
 
 Friday, February 11, 2005, 9:07:06 AM, you wrote:
 
 M Just wondering if there is a simple way to extract the list of the second
 M key of an array
 
 repeat for each line theItem in the keys of array
   put item 2 of array[theItem] after field myField
 end repeat
 
 -- same obviously for item 1

if you don't want duplicates you could try

repeat for each line theItem in the keys of array
  put 1 into uniqueSecondItems[item 2 of theItem]
end repeat
put the keys of uniqueSecondItems after field myField


___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


RE: Split, combine ok but where's extract?

2005-02-11 Thread MisterX
doesn't

combine array with comma,return
split array with comma,return

do somethign like that too?

According to the help docs, the split command strips duplicates and should
be faster than a loop... 

This is worth a bit of investigating and testing...


 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of 
 Dick Kriesel
 Sent: Saturday, February 12, 2005 03:51
 To: How to use Revolution
 Subject: Re: Split, combine ok but where's extract?
 
 On 2/11/05 5:53 PM, Mark Wieder [EMAIL PROTECTED] wrote:
 
  MisterX-
  
  Friday, February 11, 2005, 9:07:06 AM, you wrote:
  
  M Just wondering if there is a simple way to extract the 
 list of the 
  M second key of an array
  
  repeat for each line theItem in the keys of array
put item 2 of array[theItem] after field myField
  end repeat
  
  -- same obviously for item 1
 
 if you don't want duplicates you could try
 
 repeat for each line theItem in the keys of array
   put 1 into uniqueSecondItems[item 2 of theItem] end repeat 
 put the keys of uniqueSecondItems after field myField
 
 
 ___
 use-revolution mailing list
 use-revolution@lists.runrev.com
 http://lists.runrev.com/mailman/listinfo/use-revolution
 

___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution


RE: Split, combine ok but where's extract?

2005-02-11 Thread MisterX
Mark,

I did say I already wrote a function to extract these
but is there no split combination that does this without
a slow loop?

Here's the two functions I used

 function MergeColumns
  local xp,y,linecount,z,c
  put the paramcount into xp
  
  put empty into y
  put empty into linecount
  repeat with x = 1 to xp
get param(x)
get the number of lines in it
put it  comma after linecount
  end repeat
  delete last char of linecount
  put max(linecount) into linecount
  
  repeat with x = 1 to linecount
repeat with y = 1 to xp
  put line x of param(y) into z
  put z  comma after line x of c
end repeat
delete last char of c
  end repeat
  return c
end MergeColumns

function ExtractItems tabl,column,adelimiter
  if adelimiter is not empty then
set the itemdelimiter to adelimiter
  end if
  
  local a
  put  into a
  local x=1
  repeat for each line L in tabl
put (item column of l) into line x of a
add 1 to x
  end repeat
  return a
end ExtractItems

Of which the MergeColumn could use lots of optimizing ;)
But they're slow functions compared to split or combine.

If you extract the keys from a double array the problem
remains in the case of a second key name like

array[a,b]

where, for example, the b keys have to be extracted.
That's why I was wondering if there was a faster function...

Cheers
Xavier
--
http://MonsieurX.com

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of 
 Mark Wieder
 Sent: Saturday, February 12, 2005 02:54
 To: 'How to use Revolution'
 Subject: Re: Split, combine ok but where's extract?
 
 MisterX-
 
 Friday, February 11, 2005, 9:07:06 AM, you wrote:
 
 M Just wondering if there is a simple way to extract the list of the 
 M second key of an array
 
 repeat for each line theItem in the keys of array
   put item 2 of array[theItem] after field myField
 end repeat
 
 -- same obviously for item 1
 
 --
 -Mark Wieder
  [EMAIL PROTECTED]
 
 ___
 use-revolution mailing list
 use-revolution@lists.runrev.com
 http://lists.runrev.com/mailman/listinfo/use-revolution
 

___
use-revolution mailing list
use-revolution@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution