1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-07 11:03:04 +00:00

Add generator expressions for easier iteration.

Similar to python generator, but with the same
syntax as the loop macro.
This commit is contained in:
Calvin Rose
2018-11-20 21:48:06 -05:00
parent 1e87b01e02
commit 184fe31e0c
4 changed files with 62 additions and 23 deletions

View File

@@ -25,11 +25,12 @@
int main() {
JanetTable *t1;
JanetTable *t1, *t2;
janet_init();
t1 = janet_table(10);
t2 = janet_table(0);
janet_table_put(t1, janet_cstringv("hello"), janet_wrap_integer(2));
janet_table_put(t1, janet_cstringv("akey"), janet_wrap_integer(5));
@@ -52,6 +53,14 @@ int main() {
assert(janet_equals(janet_table_get(t1, janet_cstringv("hello")), janet_wrap_nil()));
assert(janet_equals(janet_table_get(t1, janet_cstringv("box")), janet_wrap_nil()));
janet_table_put(t2, janet_csymbolv("t2key1"), janet_wrap_integer(10));
janet_table_put(t2, janet_csymbolv("t2key2"), janet_wrap_integer(100));
janet_table_put(t2, janet_csymbolv("some key "), janet_wrap_integer(-2));
janet_table_put(t2, janet_csymbolv("a thing"), janet_wrap_integer(10));
assert(janet_equals(janet_table_get(t2, janet_csymbolv("t2key1")), janet_wrap_integer(10)));
assert(janet_equals(janet_table_get(t2, janet_csymbolv("t2key2")), janet_wrap_integer(100)));
janet_deinit();
return 0;