Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)

Hello! I'm discovering Lil and setting myself some little challenges. While I'm used to a lot of other languages, I'm wondering if there is a simple way to declare lists of lists. 

My intuition would be

(0,1), (2, 3)

but this actually is the same as (0, 1, 2, 3). I guess that while () is the empty list, parenthesis aren't lists delimiters as [] in other languages. I understand that comma is the concatenator for lists and that the correct solution to my problem would be

(list 0 1), (list 2,3)

but I'm wondering if there's a more elegant solution.

Thank you!

(1 edit)

Lil doesn't have a per se list literal syntax. Your example is one straightforward way of making nested lists:

(list 0,1),(list 2,3)

Another fairly general way of declaring static data is to use "parse" on a string of JSON/LOVE:

"%J" parse "[[1,2,3],[4,5],[6,7,8,9]]"
# ((1,2,3),(4,5),(6,7,8,9))

Within Decker it's often a good idea to store lengthy static data in a Field widget (where it can be encoded/decoded to/from LOVE via the .data attribute), or as a table stored in a Grid widget, where it can be viewed and directly manipulated. Modules (Lil libraries for Decker) don't have direct access to a deck, so they have a dedicated mechanism called a KeyStore.

If the sublists are of equal size, you could turn a flat list into a nested one using a primitive like "window":

2 window range 6
# ((0,1),(2,3),(4,5))

You could also construct a nested list piecemeal by index in a named variable:

a[0]:1,2,3
a[1]:4,5
a
# ((1,2,3),(4,5))

This last approach is particularly handy for nested dictionaries; see the code examples in the reference manual entry for the Array Interface.

Does any of that help?

(+2)

Thank you! Yes all of these help and are very interesting. I had noticed the JSON parsing style too (with which I would feel at home) and SQL-like tables but was interested to learn more about the other native options. I really like window! The other tips are very welcome as well! 

Thanks again!