Page 1 of 1

Something like "do" in python?

Posted: Wed Sep 21, 2022 7:39 pm
by danielrr
I find livecode's "do" command something like magic.
Is there something like it in Python, or JavaScript?

Re: Something like "do" in python?

Posted: Wed Sep 21, 2022 7:51 pm
by stam
what's magic for me is the [each] iterator... don't think there's anything like it in other languages and it makes such easy work of it...

Re: Something like "do" in python?

Posted: Wed Sep 21, 2022 9:29 pm
by dunbarx
Stam.

And FAST, if you mean in the "Repeat for each..." form.

But just as cool is the "each" local variable, which allows one to, say:

Code: Select all

sort lines of myHugeList by word 3 of each & item 5 of each
Magic, as you say. :wink:

Craig

Re: Something like "do" in python?

Posted: Wed Sep 21, 2022 9:39 pm
by stam
dunbarx wrote:
Wed Sep 21, 2022 9:29 pm
Stam.

And FAST, if you mean in the "Repeat for each..." form.

But just as cool is the "each" local variable, which allows one to, say:

Code: Select all

sort lines of myHugeList by word 3 and item 5 of each
Magic, as you say. :wink:

Craig
Actually repeat for each is a common pattern across several languages... (and until we get compiled scripts, all of these are faster...)

i meant the second form you mention - also when filtering arrays, so versatile 8)

Code: Select all

filter elements of tArray where each["someKey"] = "xyz"

Re: Something like "do" in python?

Posted: Wed Sep 21, 2022 9:48 pm
by SparkOut
In both javascript and python the "do" equivalent is

Code: Select all

eval()
In both javascript and python this function is discouraged because it can enable arbitrary code to run, which may be a big security risk. The same risk is applicable in LiveCode but I dare say there is a smaller possibility of attack through this vector.