Re: The merge function is awesome!

2019-01-18 Thread Geoff Canyon via use-livecode
On Fri, Jan 18, 2019 at 3:23 AM Mark Waddingham via use-livecode <
use-livecode@lists.runrev.com> wrote:

> On 2019-01-18 06:48, Geoff Canyon via use-livecode wrote:
> > I was in the same position with merge(). If you haven't seen it
> > already,
> > format() has some pretty amazing capabilities as well.
>
> To answer your question about escaping - yes there is:
>
>[[[]] -> [
>[[]]] -> ]
>

Ha, so my string ends up as:

[[the name of tID]] - [[[]][[the id of tID]][[]]]

That's a lot of square brackets!


> Also the merge function has another feature (which I think was actually
> undocumented for a long time - although, for once, it is there now!):
>
>1) "[[ 1 + 2 ]]" -> 3 (function / expression evaluation)
>2) "" ->
> (command / statement evaluation)
>
> Basically (1) does the equivalent of 'value()' on the string enclosed in
> [[ / ]]; whilst (2) does the equivalent of 'do 

Re: The merge function is awesome!

2019-01-18 Thread Mark Waddingham via use-livecode

On 2019-01-18 06:48, Geoff Canyon via use-livecode wrote:
I was in the same position with merge(). If you haven't seen it 
already,

format() has some pretty amazing capabilities as well.


To answer your question about escaping - yes there is:

  [[[]] -> [
  [[]]] -> ]

Also the merge function has another feature (which I think was actually 
undocumented for a long time - although, for once, it is there now!):


  1) "[[ 1 + 2 ]]" -> 3 (function / expression evaluation)
  2) "" -> 
(command / statement evaluation)


Basically (1) does the equivalent of 'value()' on the string enclosed in 
[[ / ]]; whilst (2) does the equivalent of 'do 

Re: The merge function is awesome!

2019-01-17 Thread Geoff Canyon via use-livecode
On Thu, Jan 17, 2019 at 2:27 PM Tom Glod via use-livecode <
use-livecode@lists.runrev.com> wrote:

> 6 years with LC...never used the value or merge commands . never even
> came across them.
>
> mind blown.
>

I was in the same position with merge(). If you haven't seen it already,
format() has some pretty amazing capabilities as well.
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: The merge function is awesome!

2019-01-17 Thread Tom Glod via use-livecode
6 years with LC...never used the value or merge commands . never even
came across them.

mind blown.

On Thu, Jan 17, 2019 at 3:46 PM Geoff Canyon via use-livecode <
use-livecode@lists.runrev.com> wrote:

> On Thu, Jan 17, 2019 at 11:01 AM hh via use-livecode <
> use-livecode@lists.runrev.com> wrote:
>
> > > Geoff wrote:
> > > ... you've just given me an idea how to handle things like font/styling
> > > tags. Something like:
> > > function ifTag b,o,s,c
> > > if b then return o & s & c else return s
> > > end ifTag
> >
> > Allow me two remarks.
> >
> > 1. You could use, in order to avoid the check:
> >
> > function tag s,o,c
> > return o & s & c
> > end tag
> >
> > And both, tag("inner") and tag("inner","left-","-right") work.
> >
>
> I'm thinking about situations where the tags are optional, so something
> like:
>
> ifTag(word 1 of tID is "group","",the name of tID,"")
>
> I'd have to do a timing test to see whether it's more costly to do the
> function call or perform the test twice. And of course in this instance it
> would be easy enough to simply use:
>
> ", & the name of tID & ""
> else return the name of tID?>
>
> But it would become unwieldy for more complex strings.
>
> >
> > 2. Also array-things work with merge, like [[a[1]]].
> >
>
> Yep, definitely planning to take advantage of this if possible:
> https://github.com/gcanyon/navigator/issues/21
> ___
> use-livecode mailing list
> use-livecode@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: The merge function is awesome!

2019-01-17 Thread Geoff Canyon via use-livecode
On Thu, Jan 17, 2019 at 11:01 AM hh via use-livecode <
use-livecode@lists.runrev.com> wrote:

> > Geoff wrote:
> > ... you've just given me an idea how to handle things like font/styling
> > tags. Something like:
> > function ifTag b,o,s,c
> > if b then return o & s & c else return s
> > end ifTag
>
> Allow me two remarks.
>
> 1. You could use, in order to avoid the check:
>
> function tag s,o,c
> return o & s & c
> end tag
>
> And both, tag("inner") and tag("inner","left-","-right") work.
>

I'm thinking about situations where the tags are optional, so something
like:

ifTag(word 1 of tID is "group","",the name of tID,"")

I'd have to do a timing test to see whether it's more costly to do the
function call or perform the test twice. And of course in this instance it
would be easy enough to simply use:

", & the name of tID & ""
else return the name of tID?>

But it would become unwieldy for more complex strings.

>
> 2. Also array-things work with merge, like [[a[1]]].
>

Yep, definitely planning to take advantage of this if possible:
https://github.com/gcanyon/navigator/issues/21
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: The merge function is awesome!

2019-01-17 Thread hh via use-livecode
> Geoff wrote:
> ... you've just given me an idea how to handle things like font/styling
> tags. Something like:
> function ifTag b,o,s,c
> if b then return o & s & c else return s
> end ifTag

Allow me two remarks.

1. You could use, in order to avoid the check:

function tag s,o,c
return o & s & c
end tag

And both, tag("inner") and tag("inner","left-","-right") work.

2. Also array-things work with merge, like [[a[1]]].


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: The merge function is awesome!

2019-01-17 Thread Geoff Canyon via use-livecode
On Thu, Jan 17, 2019 at 4:36 AM hh via use-livecode <
use-livecode@lists.runrev.com> wrote:

> > Geoff wrote:
> > using value():
> > the name of tID && "[" & the id of tID & "]"
> > using merge():
> > [[the name of tID]] - ([[the id of tID]])
> > (is there a way to escape the "["?)
>
> You could use with merge not only variables but also functions
> that are available for the script that calls merge:
>
> [[br(the id of tID)]]
>
> function br x
>   return "[" & x & "]"
> end br
>

True, and you've just given me an idea how to handle things like
font/styling tags. Something like:

function ifTag b,o,s,c
if b then return o & s & c else return s
end ifTag
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: The merge function is awesome!

2019-01-17 Thread hh via use-livecode
> Geoff wrote:
> using value():
> the name of tID && "[" & the id of tID & "]"
> using merge():
> [[the name of tID]] - ([[the id of tID]])
> (is there a way to escape the "["?)

You could use with merge not only variables but also functions
that are available for the script that calls merge:

[[br(the id of tID)]]

function br x
  return "[" & x & "]"
end br


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


The merge function is awesome!

2019-01-16 Thread Geoff Canyon via use-livecode
In Navigator I use the value() function in several ways. In particular, I
use it as a way for users to customize Navigator's list display. For some
reason I've managed to go all these years blissfully unaware of the merge()
function, which is seemingly superior to value() for this purpose in pretty
much every way. A few examples:

Using value() I use the string "tID" to represent the long id of the
control being represented. In retrospect I should have used value(,) which would allow the user to use "me". But I didn't
think of that when I first created the functionality, or really until just
a few minutes ago, but even so, the most basic displays are about
equivalent:

To display:
button "Cancel" - [1150]

using value():
the name of tID && "[" & the id of tID & "]"

using merge():
[[the name of tID]] - ([[the id of tID]])
(is there a way to escape the "["?)

The merge() call is cleaner, because it inherently has access to the tID
variable; for value() I have to replace "tID" with the long id before using
value().

For value(), I implemented a special iff() function, so I could do
conditionals inline. The drawback is that both of the return values get
implemented before being handed to the function, so this will fail:

get iff(1+1=2,"true",3/0) -- fails even though the value 3/0 isn't needed.

To work around that, I came up with the function iffv(), which takes
strings and then returns the value of only the necessary string. So this
will work:

get iffv("1+1=2","true","3/0") -- succeeds because the function does not
perform value("3/0")

But the syntax for that quickly becomes unwieldy. Instead, merge() supports
executing arbitrary code within it, so to display a control and its
behavior:

button "Cancel" | stack "rev_b_Cancel 5"

using value():
the name of tID & iffv(the behavior of tID is not empty,Q(" | ") && "&" &&
"the name of the behavior of" && the long id of tID,"")

using merge():
[[the name of tID]]

That's a lot simpler!

Merge is also possibly going to allow me to pre-calculate a single large
merge string and then use that to generate the entire HTMLtext for
Navigator's display.
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode