"do" statements and value function

Mike Bonner bonnmike at gmail.com
Sun Jun 19 09:08:34 CDT 2011

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

More information about the use-livecode mailing list