Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+2)

Having a lot of fun with Decker and Lil.
Thank you.

Is this expected behaviour for joining arrays?

a1:("aa","bb","cc","dd")
a2:("x")
show[ a1 join a2 ]
--> (("aa","x"),("bb","x"),("cc","x"),("dd","x"))
show[ a2 join a1 ]
--> (("x","aa"))

Lil Playground

(+1)

From the lil reference manual:

If join is applied to non-table arguments, it produces a list by pairing adjacent elements from x and y. If either argument is a number, it is considered "range" of that argument, and otherwise it is interpreted as a list. For example, "ABC" join 3 gives (("A",0),("B",1),("C",2)).

As you can see, it has a preference for preserving the length of the left argument if they don't match. Some functional languages call this operation on lists "zip()". Applying "join" to tables performs a natural join.

If you simply want to concatenate lists and atoms, use the comma operator (,):

 a1,a2
# ("aa","bb","cc","dd","x")

(Lil doesn't have list literals per se, just atom literals and the comma operator.)

Does that make sense?

(+1)

Is there a way to get  

(("x","aa"),("x","bb"),("x","cc"),("x","dd"))

from a1 and a2 without using each?

(+1)
 ((count a1) take a2) join a1
 
# (("x","aa"),("x","bb"),("x","cc"),("x","dd"))
(+1)

nice, thanks  🙂