repeat . . . delimit by

Alex Tweedly alex at
Sun Sep 15 19:32:46 EDT 2013

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!!!!]

More information about the Use-livecode mailing list