Page 1 of 1
A little syntactic sugar
Posted: Tue Jan 26, 2010 7:41 am
by massung
I don't want to bastardize the simplicity that is the Rev scripting language, but I often find myself extracting the same data repeatedly in the same ways. For example:
Code: Select all
get someFuncThatReturnsFourLines()
put line 1 of it into tLine1
put line 2 of it into tLine2
put line 3 of it into tLine3
put line 4 of it into tLine4
Instead, I think it would be far more efficient (and just as readable) to do the following:
Code: Select all
put the lines of someFunc() into tLine1, tLine2, tLine3, tLine4
Or something similar.. perhaps a new command ("extract" comes to mind, but I'm sure there's plenty of good ideas out there). If there's already a way to do something similar (using chunks and not regex) then I await to be amazed by someone.
Jeff M.
Re: A little syntactic sugar
Posted: Tue Jan 26, 2010 11:29 am
by Klaus
Hi Jeff,
when it comes to concatenating names of variables, which IS possible, you need to use the "do" statement like this:
Code: Select all
...
put someFuncThatReturnsLotsOfLines() into tVariable
put 0 into tCounter
repeat for each line k in tVariable
add 1 to tCounter
do "put k into" && (tLine & tCounter)
end repeat
...
Tested and works
Best
Klaus
Re: A little syntactic sugar
Posted: Tue Jan 26, 2010 4:57 pm
by massung
Ya, I know. I'm just hoping for something with a little brevity that also doesn't compromise readability and the expressiveness of Rev.
Thanks, though.
Jeff M.
Re: A little syntactic sugar
Posted: Tue Jan 26, 2010 5:59 pm
by FourthWorld
If the lines are just going into variables, would an array provide what you need?
Re: A little syntactic sugar
Posted: Wed Jan 27, 2010 3:56 pm
by massung
FourthWorld wrote:If the lines are just going into variables, would an array provide what you need?
I'd be fine with that, as long as the array was keyed by the chunk type described:
Code: Select all
put the lines of fld "txt" into tMyArray # or item, char, word, etc.
-- tMyArray[1] = line 1 of fld "txt"
-- tMyArray[2] = line 2 of fld "txt"
-- etc.
Obviously, this is trivial to do in a loop. As the post title suggests, this is just the hope for a little syntactic sugar.
Jeff M.
Re: A little syntactic sugar
Posted: Wed Jan 27, 2010 4:01 pm
by FourthWorld
See the split command which lets you put a delimited chunk into separate array elements, e.g.:
split tData by cr
Re: A little syntactic sugar
Posted: Wed Jan 27, 2010 5:56 pm
by massung
See, don't ya just love when your feature request is added just that quickly?
Jeff M.