LiveCode 10 - what are your thoughts on the new features?

Andre Garzia andre at andregarzia.com
Wed Sep 8 06:35:00 EDT 2021


Hi Alex,

> On 8 Sep 2021, at 01:33, Alex Tweedly via use-livecode <use-livecode at 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 “andre at example.com <mailto:andre at example.com>” into tDataA[1]
  put “Andre Garzia” into tDataA[2]

  sendEmail …tDataA

Is syntactically equivalent to:


  put “andre at example.com <mailto:andre at 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.


More information about the use-livecode mailing list