Enhanced "combine" command
Moderator: Klaus
Enhanced "combine" command
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
Or deeper yet.
QCC #20443, hopefully will be implemented soon. I would have great use for this.
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Enhanced "combine" command
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?
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Enhanced "combine" command
Richard.
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:
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:
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
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.commonly-used forms, JSON and XML.
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
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"]
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
Re: Enhanced "combine" command
Hi Craig,dunbarx wrote: This can all be done right now, but not in one line.
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
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
Thierrya - 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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Enhanced "combine" command
Thierry.
Lovely, and a good lesson in recursion.
But a bit more than one line.
Craig
Lovely, and a good lesson in recursion.
But a bit more than one line.

Craig
Re: Enhanced "combine" command
Hi Craig,dunbarx wrote: Lovely, and a good lesson in recursion.
But a bit more than one line.![]()
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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Enhanced "combine" command
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.dunbarx wrote:Thierry.
Lovely, and a good lesson in recursion.
But a bit more than one line.![]()

Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Enhanced "combine" command
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
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
Re: Enhanced "combine" command
gadget?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.

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
Thierry
Last edited by Thierry on Thu Sep 28, 2017 9:35 am, edited 1 time in total.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Enhanced "combine" command
Thierry.
"Gadget" is anything (not anyone) that is small, beautiful, and has class and character.
Craig
"Gadget" is anything (not anyone) that is small, beautiful, and has class and character.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Enhanced "combine" command
True, coding requires code. But a quick copy-n-paste is all Thierry's handler needs.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.
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.
Thierry does good work.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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Enhanced "combine" command
Oops, another word so-called 'false friends'dunbarx wrote: "Gadget" is anything (not anyone) that is small, beautiful, and has class and character.

in French:
As you might see, this have a 'useless' meaning in my country.qui séduit par son caractère nouveau et original, mais qui n'est pas d'une grande utilité
@Richard, thanks for your words, feeling as it's my birthday and Christmas time all together

@Craig, you do not like my second version?
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Enhanced "combine" command
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.
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.
Re: Enhanced "combine" command
Glad that you find it useful.dunbarx wrote: I do like your solution. A lot.
No worries.And "gadget", as I define it, is strictly my own definition.
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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Enhanced "combine" command
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.
I respect practically everybody. I admire Thierry.