Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested map usage example #161

Closed
xvxx opened this issue Dec 3, 2019 · 2 comments
Closed

Nested map usage example #161

xvxx opened this issue Dec 3, 2019 · 2 comments

Comments

@xvxx
Copy link
Collaborator

xvxx commented Dec 3, 2019

I'm sure I'm just missing something, but I can't figure out how to get nested maps to work.

Here is the example from https://docs.ldpl-lang.org/data/:

data:
    listOfMaps is text map list
    listOfLists is text list list
procedure:
    push map to listOfMaps
    store "Hello!" in toListOfLists:0:"hi!"
    # Pushes a map to listOfMaps and then stores
    # the value "Hello!" in the key "hi!" of the pushed map
    push list to listOfLists
    push "Hello!" toListOfLists:0
    # Pushes a map to listOfLists and then pushes
    # the value "Hello!" at index 0 of the pushed list

Obviously there is a typo as toListOfLists doesn't exist. But if I change it to listOfMaps:

data:
    listOfMaps is text map list

procedure:
    store "Hello!" in listOfMaps:0:"hi!"

This compiles but produces a runtime error:

$ ./ldpl map.ldpl
* Loading map.ldpl
* Compiling map.ldpl
* Building map-bin
* Saved as map-bin
* File(s) compiled successfully.
$ ./map-bin
Runtime Error: LIST index 0 out of range [0, 0)

Am I missing a step here? The documentation for nested lists works for me when I test it.

@dgarroDC
Copy link
Collaborator

dgarroDC commented Dec 3, 2019

You need to add the push map to listOfMaps line, otherwise listOfMaps will be empty and you can´t access its first element (listOfMaps:0) because it doesn´t exist.

@xvxx
Copy link
Collaborator Author

xvxx commented Dec 3, 2019

Oh, I was literally missing a line! Ha, I knew it. Thank you.

@xvxx xvxx closed this as completed Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants