Upvalues are stored in the symbol slots structure as well, but
since they are always live, we repurpose the death_pc field to
refer to the environment index that we want to look at at runtime.
Allow more easily importing modules from custom directories
without jumping through too many hoops. Technically, this was
possible before but required circumventing the built-in module/paths
and was just a hassle.
Also add entries to module/path (and module/add-path) to allow code
like the following.
(setdyn :my-libs "/home/me/janet-stuff/")
(import @my-libs/toolbox)
Intended for things like test harnesses where code might not
be installed to the usual directories.
Three reasons:
1. This same behavior is not documented on the `next` function
2. This function does not throw the error directly,
it only throws an error because `next` does.
3. Following the same idea as the previous commit, this behavior is
more or less implementation-defined for nonsensical types
> In dynamic languages, the usual idea is garbage in, garbage out.
Various other documentation cleanup.
> Remove the try. In dynamic languages, the usual idea is garbage in, garbage out. You misunderstood my point about the type error. “Test” functions are not special in that regard.
> - @bakpakin
This is just documentation of existing behavior, it does not change anything.
The reason index-of throws a type error on non-iterable types is because `next` does.
This is hardcoded into the JOP_NEXT opcode (see src/core/value.c:janet_next_impl).
Unfortunately, there is currently no corresponding `iterable?` check.
Note this actually changes behavior from a thin wrapper over `index-of`.
This is because `(index-of 3 3)` throws "error: expected iterable type, got 3"
This is significantly clearer than using (not (nil? (index-of col val)))
Most major programming languages offer some sort of contains function (Python, Java, C, Rust).
The only exception I know of is C.
Should make janet a bit easier to use. Also changes the
header to not expose the size of native mutexes and rwlocks, except
with janet_os_mutex_size and janet_os_rwlock_size.
Using keywords for the names of dynamic bindings emphasized their
dynamic nature and how they actually work, but is opaque when it comes
to documentation and error detection. Janet uses early binding for name
resolution by default in most places, dyns should be no different.
The `defdyn` macro allows one to create aliases for keywords that can
have docstrings, be imported and exported, etc. The aliases _must_
follow the usual lisp convention of earmuffs - this is not
restricting since the underlying keyword lookup mechanism is still
completely accessible to users.
Example:
(defdyn *my-dynamic-binding* "Sends the plumbus to the thingamizer when
enabled")
The above creates a normal binding (as created with `def`) for
`*my-dynamic-binding*` that is bound to the keyword
`:my-dynamic-binding`.
There is an optional prefix for defdyns that can be used to avoid name
collisions - *defdyn-prefix*
Example:
(setdyn *defdyn-prefix* "mylib/")
(defdyn *my-dynamic-binding* "Plumbus thingamizer")
(pp *my-dynamic-binding*)
> :mylib/my-dynamic-binding
This commit adds support for using & _ syntax to bind the remaining
values in an array in the match macro.
The commit also adds a few tests for the new syntax in suite0008
- Change the global binding name from :redefs to :redef
- Simplify internal representation of "redefinable bindings"
- Store "redefinable bindings in :ref rather than :value inside the
environment entries. This makes such bindings more like vars that
can't be set rather than defs.
Some pointer casting with abstract types was incorrect, resulting
in strange behavior when trying to use supervisor channels that were
threaded. This fix also adds the ability to supply a supervisor channel
directly when creating a thread.