Hi Alex,

> On 8 Sep 2021, at 01:33, Alex Tweedly via use-livecode 
> <use-livecode@lists.runrev.com> wrote:
> 
> I just don't understand this one, so no comment.


As I understand, this is LC version of the “spread operator”.  It allows you to 
spread the elements of an array as the arguments to a handler.

The code:

  put “an...@example.com <mailto:an...@example.com>” into tDataA[1]
  put “Andre Garzia” into tDataA[2]

  sendEmail …tDataA

Is syntactically equivalent to:


  put “an...@example.com <mailto:an...@example.com>” into tDataA[1]
  put “Andre Garzia” into tDataA[2]

  sendEmail tDataA[1], tDataA[2]

Which means that you can code the “sendEmail” command to have two string 
arguments instead of an array, as shown below:

  command sendEmail pEmail, pFullName
    // send your email
  end sendEmail

The spread operator will pass every array element as an argument to the 
handler. 

It would be beneficial if this feature would also come paired a “rest operator” 
that collected extra arguments in an array, so that we could declare the 
“sendEmail” handler as

  command sendEmail pEmail, pFullName, …pMoreArgumentsA
    // stuff
  end sendEmail

This way, if the call uses an array that contains more than two elements, the 
remaining parameters are collected in the final “pMoreArgumentsA” array. That 
if what I would like to have, LC didn’t say anything about this but it is very 
common in other languages to implement both operators at the same time.

In the case of LiveCode there is an alternative though. We can use “paramCount” 
and “param()” to grab the extra parameters, but that requires us coding it 
while something like a “rest operator” do that for us automatically.
_______________________________________________
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