A little syntactic sugar

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

A little syntactic sugar

Post by massung » Tue Jan 26, 2010 7:41 am

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.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: A little syntactic sugar

Post by Klaus » Tue Jan 26, 2010 11:29 am

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

massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Re: A little syntactic sugar

Post by massung » Tue Jan 26, 2010 4:57 pm

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: A little syntactic sugar

Post by FourthWorld » Tue Jan 26, 2010 5:59 pm

If the lines are just going into variables, would an array provide what you need?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Re: A little syntactic sugar

Post by massung » Wed Jan 27, 2010 3:56 pm

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: A little syntactic sugar

Post by FourthWorld » Wed Jan 27, 2010 4:01 pm

See the split command which lets you put a delimited chunk into separate array elements, e.g.:

split tData by cr
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Re: A little syntactic sugar

Post by massung » Wed Jan 27, 2010 5:56 pm

See, don't ya just love when your feature request is added just that quickly? :mrgreen:

Jeff M.

Post Reply