Enhanced "combine" command

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5314
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Enhanced "combine" command

Post by dunbarx » Tue Sep 26, 2017 4:22 pm

It has been well received by the team that the "combine" command be enhanced by allowing it to contain any number of delimiters, as opposed to the current 2. In this way an array of any depth, that is, when the keys of an array are associated with another array.

Or deeper yet.

QCC #20443, hopefully will be implemented soon. I would have great use for this.

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5935
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Enhanced "combine" command

Post by FourthWorld » Tue Sep 26, 2017 5:52 pm

Except in the singular case where the plain-text representation would be transformed into an array where each end node contains only one element, columnar data is problematic for such expression.

Most arrays are hierarchical collections, which require something beyond simple delimiters.

For plain-text representations of hierarchical data LC already supports the two most commonly-used forms, JSON and XML.

What are some of the use-cases where those common formats would be less effective for representing hierarchical data than columnar formats?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5314
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Enhanced "combine" command

Post by dunbarx » Tue Sep 26, 2017 9:32 pm

Richard.
commonly-used forms, JSON and XML.
In my own work, I never import or read such data from external sources. I create and store my own. I use arrays often, because of their compactness and intrinsic power.

But since all my arrays are built by myself, deconstructing either requires that I "read" them in the debugger, often setting a breakpoint just for the purpose, or changing them into an ordinary variable with the "combine" command.

If you have:

Code: Select all

on mouseUp
   put "10" into myArray["a"]["b"]["c"]["d"]["e"]
   answer myArray["a"]["b"]["c"]["d"]["e"]
end mouseUp
Well, that gets the "10" out.

What the enhanced combine command would do is allow me to transform "deeply nested" array variables into ordinary ones in one line:

Code: Select all

put 10 into myArray["a"]["w"]
put 20 into myArray["a"]["x"]
put 30 into myArray["a"]["y"]
put 40 into myArray["a"]["z"]
The new: "combine myArray with return and comma and comma" would yield:

a,w,10
a,x,20
a,y,30
a,z,40

This can all be done right now, but not in one line.

Craig

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 583
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Enhanced "combine" command

Post by Thierry » Wed Sep 27, 2017 12:18 am

dunbarx wrote: This can all be done right now, but not in one line.
Hi Craig,

you could try this little piece of pure livecode
and might be that you'll like it and use it before your request will be honored?

Code: Select all

function flattenArray A , T,  X
   if A is not an array then return T  & X & A & d1
   repeat for each key K in A
      put flattenArray( A[K],  T,  X & K & d2 )  into T
   end repeat
end flattenArray
and I test it this way:

Code: Select all

local  d1 -- primary delimiter
local d2  -- secondary delimiter

on mouseup
   local myArray
   put 10 into myArray["a"]["o"]
   put 30 into myArray["b"]["p"]
   put 40 into myArray["b"]["w"]
   put 20 into myArray["c"]["q"]
   put 50 into myArray["c"]["r"]
   put 60 into myArray["b"]["s"]
   put 70 into myArray["d"]
   put 42 into myArray["s"]["u"]["n"]["n"]["y"]
   
   put cr into d1
   put " - " into d2
   put flattenArray( myArray )
end mouseup
which should give you:
a - o - 10
b - w - 40
b - s - 60
b - p - 30
c - r - 50
c - q - 20
d - 70
s - u - n - n - y - 42
Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5314
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Enhanced "combine" command

Post by dunbarx » Wed Sep 27, 2017 6:02 pm

Thierry.

Lovely, and a good lesson in recursion.

But a bit more than one line. :wink:

Craig

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 583
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Enhanced "combine" command

Post by Thierry » Wed Sep 27, 2017 6:09 pm

dunbarx wrote: Lovely, and a good lesson in recursion.

But a bit more than one line. :wink:
Hi Craig,

Sorry, I'm getting old :)

If you ever use it and want to change some behavior,
I'll be happy to give a hand...

Regards,

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5935
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Enhanced "combine" command

Post by FourthWorld » Wed Sep 27, 2017 6:31 pm

dunbarx wrote:Thierry.

Lovely, and a good lesson in recursion.

But a bit more than one line. :wink:
If implemented in the engine it would be far more lines. Either option can be called with one line. And Thierry's solution can be used today. :)
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5314
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Enhanced "combine" command

Post by dunbarx » Wed Sep 27, 2017 10:00 pm

All this is doable. No argument.

But it surely has to be admitted that the enhanced command is cleaner and more accessible. The delimiters live in that single line. There is a bit more work required to set them up in Thierry's gadget.

Because of its recursion, though, it does handle the "depth" issue nicely, escaping when there is no more "array" left to process. I like that a lot.

Craig

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 583
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Enhanced "combine" command

Post by Thierry » Wed Sep 27, 2017 10:55 pm

dunbarx wrote:All this is doable. No argument.

But it surely has to be admitted that the enhanced command is cleaner and more accessible.
The delimiters live in that single line.
There is a bit more work required to set them up in Thierry's gadget.
gadget? :shock:

So here is a variant, where you can call the function in 3 ways:

Code: Select all

-- use implicit delimiters settings ( d1 and d2)
put flattenArray( myArray)

-- or set primaryDelimiter (d1) and use default's secondaryDelimiter
put flattenArray( myArray, return )

-- or set both delimiters
put flattenArray( myArray, return , " - ")

Code: Select all

function flattenArray A , d1, d2, T,  X
   if T is empty then
      if d1 is empty then put cr into d1
      if d2 is empty then put tab into d2
   end if
   if A is not an array then return T  & X & A & d1
   repeat for each key K in A
      put flattenArray( A[K],  d1, d2, T,  X & K & d2 )  into T
   end repeat
end flattenArray

Regards,

Thierry
Last edited by Thierry on Thu Sep 28, 2017 9:35 am, edited 1 time in total.
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5314
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Enhanced "combine" command

Post by dunbarx » Wed Sep 27, 2017 11:34 pm

Thierry.

"Gadget" is anything (not anyone) that is small, beautiful, and has class and character.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5935
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Enhanced "combine" command

Post by FourthWorld » Thu Sep 28, 2017 12:07 am

dunbarx wrote:All this is doable. No argument.

But it surely has to be admitted that the enhanced command is cleaner and more accessible. The delimiters live in that single line. There is a bit more work required to set them up in Thierry's gadget.
True, coding requires code. But a quick copy-n-paste is all Thierry's handler needs.

The request for an engine version has been submitted, IIRC. There's a long queue ahead of it. In the meantime, what Thierry has kindly provided seems a nice solution that can be used today.
Because of its recursion, though, it does handle the "depth" issue nicely, escaping when there is no more "array" left to process. I like that a lot.
Thierry does good work.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 583
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Enhanced "combine" command

Post by Thierry » Thu Sep 28, 2017 7:10 am

dunbarx wrote: "Gadget" is anything (not anyone) that is small, beautiful, and has class and character.
Oops, another word so-called 'false friends' :oops:
in French:
qui séduit par son caractère nouveau et original, mais qui n'est pas d'une grande utilité
As you might see, this have a 'useless' meaning in my country.


@Richard, thanks for your words, feeling as it's my birthday and Christmas time all together :roll:

@Craig, you do not like my second version?

Regards,

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5314
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Enhanced "combine" command

Post by dunbarx » Thu Sep 28, 2017 1:49 pm

Thierry.

I do like your solution. A lot.

And "gadget", as I define it, is strictly my own definition. In the rest of the world, it is a small, often ad hoc machine or machine component that does some sort of task.

Craig.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 583
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Enhanced "combine" command

Post by Thierry » Thu Sep 28, 2017 2:53 pm

dunbarx wrote: I do like your solution. A lot.
Glad that you find it useful.

And "gadget", as I define it, is strictly my own definition.
No worries.
As a non native English speaker,
I could tell you so many little stories which were a bit embarrassing for me
and funny afterwards :)

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

SparkOut
Posts: 1725
Joined: Sun Sep 23, 2007 4:58 pm

Re: Enhanced "combine" command

Post by SparkOut » Sat Sep 30, 2017 7:46 am

Thierry once told me I should respect him because he is older than me. (Not sure by how much but it can't be that many years.)
I respect practically everybody. I admire Thierry.

Post Reply

Return to “Feature Requests”