"do" statements and value function

Mike Bonner bonnmike at gmail.com
Sun Jun 19 17:52:11 EDT 2011


I don't know much about *do*, (I have been able to mostly avoid it so far)
but there are cases where it does seem to be the right tool for the job.

The example of one of the more useful possibilities with do would be the
creation incremented variable names.  The example in the dictionary though,
seems to be slightly incorrect.

*do "put" && x && "into tNumberOfRecords" & x -- might become "put 3 into
tNumberOfRecords"*
*
*
This would actually become* "put 3 into tNumberOfRecords3"* I believe. So in
a loop you can create variable names on the fly using this method. In
addition, you can have a fullblown multi-line script executed by *do* as
long as you don't exceed the scriptlimits. It is true though, that *do* can
be sidestepped in quite a few instances.

Don't know enough about uses of do to venture much more.

On Sun, Jun 19, 2011 at 3:10 PM, Timothy Miller <
gandalf at doctortimothymiller.com> wrote:

> Aha! Didn't know about the merge function. Useful information. Thanks,
> Mike.
>
> I'm still wondering about the question at the top of my original message.
> I'm trying to understand the "do" command better.
>
> Is it true that the "do" command and the "value" function perform about the
> same tasks in different ways? I.e., is it true that you can avoid "do" by
> judicious use of "value"?
>
> Cheers,
>
>
> Tim
>
>
> On Jun 19, 2011, at 7:08 AM, Mike Bonner wrote:
>
> > This might be easier to do with merge.
> >
> > As an example:
> >
> > *function resolveValue mySillyVar*
> > *   repeat until mySillyVar contains "[[" -- when merge can't replace the
> > value inside brackets they are left*
> > *      put mySillyVar into mySillyTmp -- mySillytmp is the working var*
> > *      put "[[" before mySillyTmp -- bracketize mySillyTmp so merge can
> try
> > it out.*
> > *      put "]]" after mySillyTmp*
> > *      put mySillyVar & ":" & merge(mySillyTmp) & return after tOut --
> > putput mySillyVar string followed by merged mySillyTmp*
> > *      put merge(mySillyTmp) into mySillyVar -- setup the next loop. If
> the
> > merge failed, brackets are left in string so loop exits*
> > *   end repeat*
> > *   replace "[[" with empty in tOut -- remove extraneous brackets*
> > *   replace "]]" with empty in tOut*
> > *   return tOut*
> > *end resolveValue*
> >
> > The following handler:
> > *on mouseUp*
> > *   put merge("line 2 of field [[quote]]inField[[quote]]") into myVar --
> > just sets up the string*
> > *   put empty -- empty message box*
> > *   put resolveValue(myVar)*
> > *end mouseUp*
> >
> > Will return evaluated pairs like so:
> > *line 2 of field "inField":the short name of this card*
> > *the short name of this card:hi mom*
> > *hi mom:hi mom *
> > *
> > *
> > No deep testing done, so problems might crop up. Does seem to work ok.
> >
> > Just realized that if the merge resolves to a string containing brackets
> the
> > loop will exit, so some checks will be needed for that possibility.
> >
> > On Sat, Jun 18, 2011 at 8:21 PM, Timothy Miller <
> > gandalf at doctortimothymiller.com> wrote:
> >
> >> In the process of getting a slightly tricky script to work, I've been
> >> pondering the "do" command and the native value function.
> >>
> >> I've made an inference. I suspect one could get along without the "do"
> >> command by judiciously employing the value function, e.g., value(foo) or
> >> "the value of foo"
> >>
> >> I haven't tested this thoroughly yet. Is it true? If it's true, it helps
> me
> >> understand "do" a little better. If not, there's something I'm not
> getting.
> >>
> >> While on the topic of the value function...
> >>
> >> Lets say value(mySillyVar) = line 2 of field "foo"
> >>
> >> And then value(line 2 of field "foo") resolves to "the short name of
> this
> >> card"
> >>
> >> And the short name of this card = Hi Mom
> >>
> >> Will value(foo) resolve to "Hi Mom" ?
> >>
> >> I tried it in a test stack. After some trial and error, it seems that
> >> value(mySillyVar) forces only one evaluation. It produces line 2 of
> field
> >> "foo"
> >>
> >> Further experimentation reveals, to my surprise, that
> >>
> >> value(value(mySillyVar))
> >>
> >> actually does resolve to "Hi Mom"
> >>
> >> How many times can you nest the value function? I did look in the
> >> documentation, couldn't find the answer.
> >>
> >> I haven't tried this in a "do" statement. If I wanted to resolve a
> nested
> >> value "all the way down" would one "do" statement work, or would I have
> to
> >> put value functions inside the do statement?
> >>
> >> I understand that if I ever actually need
> >> value(value(value(value(mySillyVar)))) I'm probably doing it the hard
> way.
> >> One might suffer a brain aneurysm while trying to maintain a script like
> >> that.
> >>
> >> You've heard of visual learners, tactile learners and olfactory
> learners?
> >> I've always been a learn-by-messing-around-learner. (It's also called
> >> "ADHD")
> >>
> >> Thanks in advance,
> >>
> >>
> >> Tim
> >> _______________________________________________
> >> use-livecode mailing list
> >> use-livecode at lists.runrev.com
> >> Please visit this url to subscribe, unsubscribe and manage your
> >> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> >>
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list