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:

----

<ul>

  <li>Name: [[tFirstName]]</li>

  <li>Surname: [[tSurname]]</li>

  <li>Email: [[tEmail]]</li>

</ul>

---

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:

---

<p>The current time is: [[the long english date]]</p>

---

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

Reply via email to