Add optional default value to get.

Also update CHANGELOG.md
This commit is contained in:
Calvin Rose 2019-08-06 18:10:48 -05:00
parent c84ddefc53
commit ab782d8896
2 changed files with 12 additions and 4 deletions

View File

@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file.
## Unreleased
- Add `take` and `drop` functions that are easier to use compared to the
existing slice functions.
- Add optional default value to `get`.
- Add function literal short-hand via `|` reader macro, which maps to the
`short-fn` macro.
- Add `int?` and `nat?` functions to the core.

View File

@ -882,7 +882,11 @@ static const uint32_t resume_asm[] = {
};
static const uint32_t get_asm[] = {
JOP_GET | (1 << 24),
JOP_RETURN
JOP_LOAD_NIL | (3 << 8),
JOP_EQUALS | (3 << 8) | (3 << 24),
JOP_JUMP_IF | (3 << 8) | (2 << 16),
JOP_RETURN,
JOP_RETURN | (2 << 8)
};
static const uint32_t put_asm[] = {
JOP_PUT | (1 << 16) | (2 << 24),
@ -937,13 +941,14 @@ JanetTable *janet_core_env(JanetTable *replacements) {
"the dispatch function in the case of a new fiber. Returns either the return result of "
"the fiber's dispatch function, or the value from the next yield call in fiber."));
janet_quick_asm(env, JANET_FUN_GET,
"get", 2, 2, 2, 2, get_asm, sizeof(get_asm),
JDOC("(get ds key)\n\n"
"get", 3, 2, 3, 4, get_asm, sizeof(get_asm),
JDOC("(get ds key &opt dflt)\n\n"
"Get a value from any associative data structure. Arrays, tuples, tables, structs, strings, "
"symbols, and buffers are all associative and can be used with get. Order structures, name "
"arrays, tuples, strings, buffers, and symbols must use integer keys. Structs and tables can "
"take any value as a key except nil and return a value except nil. Byte sequences will return "
"integer representations of bytes as result of a get call."));
"integer representations of bytes as result of a get call. If no values is found, will return "
"dflt or nil if no default is provided."));
janet_quick_asm(env, JANET_FUN_PUT,
"put", 3, 3, 3, 3, put_asm, sizeof(put_asm),
JDOC("(put ds key value)\n\n"