It may also be helpful to remember that lineDel and itemDel are purely
arbitrary; that is, they needn't be limited to use only on what we might
think of as lines and items.
The only general rule governing them is that the engine will insist that
"lines" be a larger chunk type than "items" (you can get item 2 of line
1, but you can't get line 2 of item 1) - but beyond that you're free to
use whatever delimiters you like.
For example, the original handler was:
set the itemDel to vtab
repeat for each item theDat in theData
set the itemDel to tab
do something
set the itemDel to vtab
end repeat
Here rewritten to use both delimiters:
set the lineDel to vtab
set the itemDel to tab
repeat for each line theDat in theData
do something
end repeat
--
Richard Gaskin
Fourth World
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
Follow me on Twitter: http://twitter.com/FourthWorldSys
> repeat . . . delimit by
Alex Tweedly alex at tweedly.net
Mon Sep 16 01:32:46 CEST 2013
Previous message: repeat . . . delimit by
Next message: quickly wiping a card
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I do like the idea of " repeat for each ... DELIMITED BY ..."
But, in the meantime there might be some alternatives to help your code
be nicer.
Do you use lines (i.e. process based on CRs) in these loops ?
If not, would it help your current code to use the fact that you can
change the linedelimiter ?
set the lineDel to vTab
repeat for each line tDat in theData
do something to tDat (i.e. using tab as item delimiter)
end repeat
set the lineDel to CR
Note it's OK to *have* Crs in the data, so long as you aren't processing
based on them.
If that's not an option, then (less efficiently) you could do
split theData by vtabs -- gives a numerically indexed array
repeat with I = 1 to the number of lines in the keys theData
put theData[I] into tData
do something with tData
end repeat
If you need the data back as a string, rather than simply combine it -
take a copy initially and split the copy.
-- Alex.
On 15/09/2013 00:10, Dr. Hawkins wrote:
While we're asking for modest syntax changes . . .
Being able to state DELIMIT BY in a REPEAT, and having it stick (as opposed
to using the current value of the itemdelimiter) would be a huge help.
It would avoid ugliness like
set the itemDel to vtab
repeat for each item theDat in theData
set the itemDel to tab
do something
set the itemDel to vtab
end repeat
While missing the last reset to vtab is a programming error, mu code is
kind of
littered with these (constant db accesses)
code would be much easier to follow (and maintain) with
repeat for each item theDat in theData DELIMTED BY vtab
do something
end repeat
And while I'm at it, it's been mentioned before, but a Fortran-style
optional tying of the end repeat to the repeat with a constant would be
really helpful (same for switch, and so forth)
[Fortran 90+, not FORTRAN IV!!!!]
_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode