Skip to content

Conversation

@healeycodes
Copy link
Owner

@healeycodes healeycodes commented Mar 3, 2023

Let's add dicts and lists to nodots! This is just an idea/draft for now.

There are no grammar changes in this PR because dicts and lists are built using the existing grammar. They are special functions.

  • Lists turn arguments into list items.

  • Dicts turn arguments into key/value pairs (the number of arguments must be even).

To get values out of lists and dicts, we use at.

To mutate dicts and lists, we use mut as in mutate.

# lists!
some_list = list(-1, 3, 4);
at(some_list, 0); # -1
mut(some_list, 0, -2); # as in _mutate_
at(some_list, 0); # -2

# dictionaries!
some_dict = dict("a", 2);
mut(some_dict, "a", "hi!");
at(some_dict, "a"); # "hi!"

# (also)
keys(some_dict);
vals(some_dict);

Tests added for all new functions, and some error message tests too.

@healeycodes healeycodes merged commit d7932af into main Jul 29, 2023
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

Successfully merging this pull request may close these issues.

2 participants