Generating Variables in a Repeat loop

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: heatherlaine, Klaus, FourthWorld, kevinmiller

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Generating Variables in a Repeat loop

Post by dunbarx » Tue Jun 12, 2018 3:54 pm

Richard.

"Works" means it works. I was just commenting on how loose and forgiving LC can be interpreting its own syntax.

If there is no "find", there is no foundChunk, which means there is no target chunk, and you get an error.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6173
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Generating Variables in a Repeat loop

Post by FourthWorld » Tue Jun 12, 2018 4:30 pm

dunbarx wrote:
Tue Jun 12, 2018 3:54 pm
Richard.

"Works" means it works.
I may not be as smart as you, since as helpful as that description is I still don't understand what useful outcome that syntax produces.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4660
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Generating Variables in a Repeat loop

Post by jacque » Tue Jun 12, 2018 5:15 pm

SparkOut wrote:
Mon Jun 11, 2018 9:32 pm
Just to add more mud to the water, value() is a useful* sidestep/hybrid/tweenstep twixt direct native syntax and the "do" construct.

* in appropriate circumstances
Just for reference, "value" has the same overhead and speed hit as "do". I almost never need "do" but I find I need "value" slightly more often. I try to avoid both though, ever since I found out they need to load the whole compiler into RAM on each use.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Generating Variables in a Repeat loop

Post by dunbarx » Tue Jun 12, 2018 5:28 pm

Richard.

I was not being flip with you.

LC allows one to include both "the" and "()" in the same line:

Code: Select all

 put "25" into the foundChunk()
That is all I meant. I am constantly surprised at how LC seems to be even more forgiving than HC, almost to a fault. I am thinking of two "lines" of code being allowed to live in a single physical line, without a semicolon. That sort of thing. It allows sloppy code to run. I shudder whenever I see such a thing.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6173
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Generating Variables in a Repeat loop

Post by FourthWorld » Tue Jun 12, 2018 5:40 pm

dunbarx wrote:
Tue Jun 12, 2018 5:28 pm
Richard.

I was not being flip with you.

LC allows one to include both "the" and "()" in the same line:

Code: Select all

 put "25" into the foundChunk()
That is all I meant. I am constantly surprised at how LC seems to be even more forgiving than HC, almost to a fault. I am thinking of two "lines" of code being allowed to live in a single physical line, without a semicolon. That sort of thing. It allows sloppy code to run.
What does "run" mean there? What happens when that statement is executed?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Generating Variables in a Repeat loop

Post by dunbarx » Tue Jun 12, 2018 6:35 pm

Richard.

LC runs the following line of code:

Code: Select all

 put "25" into the foundChunk()
without issue.

It allows both "the" and "()", that is, both synonym forms together.

Anyway,

None of that matters anymore. I just don't know what to do. All of a sudden, this works fine:

Code: Select all

on mouseUp
   find "xyz" in fld 1
   put "AHA!" into the foundChunk
end mouseUp
It did not before, and by before, I mean forever.

And to boot, if I run this:

Code: Select all

find "xyz" in fld 1
do "put AHA! into" && the foundChunk
I get an error:
do: error in source expression) near "put AHA! into char 9 to 11 of field 1"!
This is exactly what "do" was supposed to do. Reads fine, no?

I am depressed.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4660
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Generating Variables in a Repeat loop

Post by jacque » Tue Jun 12, 2018 8:55 pm

Maybe it now needs the quotes around the literal, along with all the ampersand concatenation. That's another reason I don't like doing do.

Code: Select all

do "put" && quote & "AHA!" & quote && "into" && the foundChunk
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6173
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Generating Variables in a Repeat loop

Post by FourthWorld » Tue Jun 12, 2018 8:57 pm

dunbarx wrote:
Tue Jun 12, 2018 6:35 pm
LC runs the following line of code:

Code: Select all

 put "25" into the foundChunk()
without issue.

It allows both "the" and "()", that is, both synonym forms together.
Ah, thanks. If I understand correctly, the concern is that it's possible to come up with certain syntactic sequences which produce no adverse results but are not flagged as errors.

I suppose you could submit a bug report for more thorough error-checking for that specific sequence.
None of that matters anymore. I just don't know what to do. All of a sudden, this works fine:

Code: Select all

on mouseUp
   find "xyz" in fld 1
   put "AHA!" into the foundChunk
end mouseUp
It did not before, and by before, I mean forever.
I apologize if I seemed dense before, but I had not previously considered "works" to mean "it does no work"; helpful to know that it as used here it simply means "does no work and produces no result, but merely isn't flagged as invalid syntax".

Given all the possible ways one can imagine putting statements and symbols together in LiveCode, I suspect that error-checking sufficient to account for the combinatorial explosion of all possible cases would bump engine size up quite a lot. If we see a good many others having their work stopped by trying to put values into functions I'm sure the team will prioritize it appropriately.

For myself, it would seem simpler for the team and more useful to scripters to just flag the use of property syntax for function calls as deprecated. Not to remove support, but just stop telling new users to do that, and over time the code containing such unnecessary ambiguity will get ever smaller organically without further effort.
And to boot, if I run this:

Code: Select all

find "xyz" in fld 1
do "put AHA! into" && the foundChunk
I get an error:
do: error in source expression) near "put AHA! into char 9 to 11 of field 1"!
This is exactly what "do" was supposed to do. Reads fine, no?
Yep, it seems the concatenation requirements for using "do" definitely increase cognitive load.

When in doubt, try parentheses. This isn't a case where it's worth trying, of course, since this whole exercise seems focused on parser exploration more than any actual task needed to produce software. But should we come across something we actually care about, sometimes evaluation can be nudged toward what we want when we make it super-explicit with parens.
I am depressed.
Why?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Generating Variables in a Repeat loop

Post by dunbarx » Tue Jun 12, 2018 9:26 pm

I am depressed because all of a sudden I do not know how this stuff works.

I made a button handler that performed as I originally posted. That performed the way it always did, as I said, back to Danny Goodman. I tested it just to be sure. Yep. just as advertised.

Then I tried it again today, and the functionality reversed itself. The straight "put" line works flawlessly, the "do" line will not run.

I, like everyone else, often comes up against seemingly impossible or absurd situations where the issue cannot possibly be with us. It has to be a gremlin. Always, it is us. Of course it is.

This one is a gremlin, and I am not sure I like it. That is depressing. :wink:

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6173
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Generating Variables in a Repeat loop

Post by FourthWorld » Wed Jun 13, 2018 1:53 am

dunbarx wrote:
Tue Jun 12, 2018 9:26 pm
I am depressed because all of a sudden I do not know how this stuff works.

I made a button handler that performed as I originally posted. That performed the way it always did, as I said, back to Danny Goodman. I tested it just to be sure. Yep. just as advertised.

Then I tried it again today, and the functionality reversed itself. The straight "put" line works flawlessly, the "do" line will not run.
What did the line do previously?

And what changed between the working and non-working states?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Der-Schredder
Posts: 6
Joined: Mon Jun 11, 2018 12:20 pm

Re: Generating Variables in a Repeat loop

Post by Der-Schredder » Wed Jun 13, 2018 6:05 am

Wow, that was a lot more input then I expected :) You are an awesome community, thanks a lot!
Even though I dind't understand everything I think I got the quint essence: Try to use something else than "Do", e.g. arrays.
And an array makes a lot more sence in my case, the variables will contain timesptamps in the end. I just dind't think about using an array.

Best regards,
Leo

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Generating Variables in a Repeat loop

Post by dunbarx » Wed Jun 13, 2018 4:20 pm

I feel like I ought to start a new thread.

Today, both these work:

Code: Select all

  put "AHA" into the foundChunk
 do "put AHA into" && the foundChunk
the "do" construction did not yesterday.

The day before, the whole point of my earlier post, only the "do" worked.

Apparently, the problem is which day of the week one is programming. I will monitor this situation and report back.

@Jacque. The fully "expanded" do construction worked, as it ought to, but I do not know if this is only for Wednesdays.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4660
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Generating Variables in a Repeat loop

Post by jacque » Wed Jun 13, 2018 8:12 pm

No problem, just have your script check the day of the week and run the appropriate line of script. :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 10385
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Generating Variables in a Repeat loop

Post by Klaus » Wed Jun 13, 2018 8:21 pm

Hi Craig,

yesterday you wrote:
...
do "put AHA! into" && the foundChunk
...
But today you wrote:
...
do "put AHA into" && the foundChunk
...
Obviously we can use strings WITHOUT quotes as long as certain characters are not part of the string, and the exclamation mark is obviously one of them.
...
put AHA into tAha
put tAha
## -> AHA
...
put AHA! into tAha
...
Script compile error:
Error description: Expression: bad factor

So this has nothing to do with DO apparently, so there is no reason to be depressed. :D


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4660
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Generating Variables in a Repeat loop

Post by jacque » Wed Jun 13, 2018 8:41 pm

I was just about to write the same thing, but Klaus beat me to it. Removing the exclamation point fixes it. Otherwise you need the quotes.

And not quoting literals is a no-no anyway.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”