Re: The merge function is redundant?

2019-01-18 Thread prothero--- via use-livecode
Folks:
I’m looking at Jan Schenkel’s posting on the “Power of Merge”.

I can’t make any of the examples work.
Obviously, there is some code or some very basic thing that everybody (but me) 
knows, but ??

Please illuminate me. I see the " placeholder in some of the lessons. The 
dictionary is no help.

BTW: No search in the dictionary’s user guide?

Thanks,
Bill

e.g.
on mouseUp

put "Testing" into Foobar

put merge("[[quote]]Foobar[[quote]] [[the short name of \

this stack]]") & return & \

merge("[[the layer of this card]] / [[the short ID \

of me]]") into tVariable

end mouseUp


Bill

William A. Prothero, Ph.D.University of California, Santa Barbara Dept. of 
Earth Sciences (Emeritus)Santa Barbara, CA. 93105

http://earthlearningsolutions.org/

> On Jan 18, 2019, at 2:35 PM, kee nethery via use-livecode 
>  wrote:
> 
> Thanks everyone. Templates makes sense.
> 
> Just for grins, perhaps the dictionary entry could be enhanced with Jacque’s 
> example. 
> 
> It makes sense to me now.
> 
> Kee
> 
> ___
> 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 redundant?

2019-01-18 Thread kee nethery via use-livecode
Thanks everyone. Templates makes sense.

Just for grins, perhaps the dictionary entry could be enhanced with Jacque’s 
example. 

It makes sense to me now.

Kee

___
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 redundant?

2019-01-18 Thread Andre Alves Garzia via use-livecode

Kee,

I can spend hours on why merge is useful and underappreciated but I will 
boil it down to one use case only: templates.


Merge is crucial if you're assembling some textual template that is not 
LiveCode but want to generate parts of it in LiveCode. For example, the 
first step in understanding the power of merge is "variable 
interpolation" in which we use merge to place values inside our text, 
for example, consider the following HTML snippet:






  Name: [[tFirstName]]

  Surname: [[tSurname]]

  Email: [[tEmail]]



---

Calling merge and having those variables filled with the data you want 
will get you the HTML you want. You can extrapolate it further by 
calling functions from merge such as:


---

The current time is: [[the long english date]]

---

You can even do loops and assemble more stuff. This is way better than 
error prone string concatenation. It is good for generating all sorts of 
textual formats, from HTML/XML to  more niche stuff such as scripts to 
run in another language or even in LC itself.



Cheers

andre


On 18/01/2019 18:33, kee nethery via use-livecode wrote:

I’m confused. Can someone explain why merge function exists when the put 
function works just as well?

merge( [[ 1 + 2 ]] = 3)
vs
put 1 + 2 && “= 3”

What is it that merge can do that a put cannot do? Just asking because I don’t 
want LiveCode to end up like Perl where there are so many completely different 
ways to do the exact same thing that one person’s perl code can be unreadable 
to another equally talented Perl coder.

Kee
  



___
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 redundant?

2019-01-18 Thread hh via use-livecode
> Kee N. wrote:
> I’m confused. Can someone explain why merge function exists when
> the put function works just as well?
> merge([[ 1 + 2 ]] = 3) vs put 1 + 2 && “= 3”

merge([[ 1 + 2 ]] = 3) produces a script error,
this should read merge("[[ 1 + 2 ]] = 3").

Merge is the one and only function to do *multiple* replacements in
large strings in *one* shot. This is especially *very* important when
setting wordy strings like htmltext (or emails, as JLG denoted).
___
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 redundant?

2019-01-18 Thread Richard Gaskin via use-livecode

kee nethery wrote:

> I’m confused. Can someone explain why merge function exists when the
> put function works just as well?
>
> merge( [[ 1 + 2 ]] = 3)
> vs
> put 1 + 2 && “= 3”
>
> What is it that merge can do that a put cannot do? Just asking because
> I don’t want LiveCode to end up like Perl where there are so many
> completely different ways to do the exact same thing that one person’s
> perl code can be unreadable to another equally talented Perl coder.

Not to worry about new things in the language stinking up the place.  
Merge has been in the xTalk family of languages for a long time, and 
serves a distinct purpose.  A little history may be helpful:


Gary Poppitz of the SuperCard team introduced the merge function to the 
xTalk world in the mid-90s, to support a server-side version of 
SuperCard called Flamethrower.


The goal was to provide a convenient way to sprinkle xTalk evaluations 
and statements throughout text that isn't xTalk -- in that use-case, HTML.


In short: templating.

Without a merge function you'd need to write your own parse to walk 
through the text to find whatever delimiters you're using, then run the 
found substring through "do" or "value".  Possible, but tedious and 
error-prone.  Indeed there were some HyperCard stacks back in the day 
with similar functionality done in script (Bob McBurney's Arachnid comes 
to mind), so one could deliver dynamic web pages from a Mac server in 
our favorite language.  But it was no speed demon compared to what LC 
does by handling that robustly in the engine.


Some time around MetaCard v2.0 Scott Raney added it to the engine we now 
call LiveCode, so it's been around for more than 20 years.  Mark 
Waddingham has enhanced it since then, and the core functionality is 
similar in many respects to how LC Server processes .lc files, so it's 
not going away any time soon.


And considering its utility, I'm grateful for it.  While I use it most 
often with HTML templates, I've used it with other formats as well for a 
wide range of tasks.  The ability to quickly and conveniently process 
any number of LC Script placeholders within a body of non-LC text has 
many applications once you get the hang of it.



Bonus:

A sort of logical inverse to using LC expressions in the middle of 
non-LC text is to put non-LC text in the middle of LC Scripts.  In bash 
this is done with heredoc, and some other languages offer such 
functionality as well.  I've proposed it in the LC request queue:


https://quality.livecode.com/show_bug.cgi?id=17471

Comment #5 there from Brian Milby shows existing syntax used in another 
xTalk, SenseTalk, that could conceivably be adopted, perhaps less useful 
for compatibility with that dialect than simply having proven design 
work already done.


Used with the merge function, a heredoc-like implementation would make 
short work of many tasks we currently write 
"complicated"&space&"and"&space&"difficult-to-read"&space&"concatenation" 
for.


--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.com

___
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 redundant?

2019-01-18 Thread J. Landman Gay via use-livecode

On 1/18/19 12:33 PM, kee nethery via use-livecode wrote:

I’m confused. Can someone explain why merge function exists when the put 
function works just as well?

merge( [[ 1 + 2 ]] = 3)
vs
put 1 + 2 && “= 3”

What is it that merge can do that a put cannot do? 


For me, it's convenience, precision, and readability (no need for all 
those ampersands and quote marks.) I use it mostly for reports, 
auto-generated emails from my server, and sometimes dynamic HTML 
construction. It also eliminates the need for multiple "replace" commands.


For example, imagine a text template in a custom property named "cText":

Dear [[username]],
  Thank you for your interest in [[productname]]. [[productname]] is 
available for download at [[productURL]].


And the script:

put "John Doe" into username
put "Zygodact" into productname
put "http://mydomain.com//zygodact.html"; into productURL
put merge(the cText of me) into tResponse


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
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 redundant?

2019-01-18 Thread prothero--- via use-livecode
Folks,
I’ve been following this discussion, barely. I don’t use merge, but when I need 
to form a command from several variables, I create the command as a text string 
and use do to execute it. 

So, when I look it up in the dictionary, I see a fairly simplistic description 
with nothing resembling the code being discussed in this thread. 

So I’m thinking: “What’s with the square brackets?”

I haven’t looked at the link that Kee posted, (I’m having breakfast at the 
beach)  but would like to make a request for the dictionary entry to be 
expanded. 

Best,
Bill

William Prothero
http://ed.earthednet.org

> On Jan 18, 2019, at 10:33 AM, kee nethery via use-livecode 
>  wrote:
> 
> I’m confused. Can someone explain why merge function exists when the put 
> function works just as well?
> 
> merge( [[ 1 + 2 ]] = 3)
> vs
> put 1 + 2 && “= 3”
> 
> What is it that merge can do that a put cannot do? Just asking because I 
> don’t want LiveCode to end up like Perl where there are so many completely 
> different ways to do the exact same thing that one person’s perl code can be 
> unreadable to another equally talented Perl coder.
> 
> Kee
> 
> 
> 
> ___
> 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 redundant?

2019-01-18 Thread Geoff Canyon via use-livecode
There's some overlap, but merge has (at least) one feature that put
doesn't: the ability to run code within its statement. A simple example:

put merge("The coin came up .")

The equivalent might be:

put "The coin came up" && item random(2) of "heads,tails" & "."

But consider this:

   put 10 into myVar
   put merge("The sum of the numbers from 1 to [[myVar]] is .")

There is no way to do that with a simple "put". You could unroll the code,
but for instances like what I'm planning to do with Navigator, that would
be totally unworkable.
___
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 redundant?

2019-01-18 Thread kee nethery via use-livecode
I’m confused. Can someone explain why merge function exists when the put 
function works just as well?

merge( [[ 1 + 2 ]] = 3)
vs
put 1 + 2 && “= 3”

What is it that merge can do that a put cannot do? Just asking because I don’t 
want LiveCode to end up like Perl where there are so many completely different 
ways to do the exact same thing that one person’s perl code can be unreadable 
to another equally talented Perl coder.

Kee
 


___
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