Skip to content

Add dicts and lists - #2

Merged
healeycodes merged 1 commit into
mainfrom
more-data-structs
Jul 29, 2023
Merged

healeycodes merged 1 commit into
mainfrom
more-data-structs

Conversation

@healeycodes

@healeycodes healeycodes commented Mar 3, 2023 •

Copy link
Copy Markdown
Owner

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.

1 participant