Commit Graph
3380 Commits
Author SHA1 Message Date
Pietro Cerutti f39447a4ee Clarify semantics 2026-08-28 18:19:30 +00:00
Pietro Cerutti 5c45e611a8 Extend the scope of truthy if-let bindings to the fal branch
The `if-let` construct - together with the fact that only `nil` and `false` are falsey - is very handy to express monadic chains over maybe/optional values:

```janet
(if-let [resp (make-http-request)       # is nil on failure
         {:status stat :body body} resp # always truthy, binds `stat` and `body`
         check (= 200 stat)             # continue only on 200 OK
         json (json/decode body true)   # is nil on failure
         {:foo foo} json]
  foo)
```

However, none of the bindings are available in the false branch, which
could be helpful to have for error reporting or fallback logic:

```janet
(if-let [resp (make-http-request)
         {:status stat :body body} resp
         check (= 200 stat)
         json (json/decode body true)
         {:foo foo} json]
  foo
  (if (= 401 stat) # unauthorized, refresh the token
    (try-again)
    nil))
```

This PR makes all symbols introduced by the bindings of an `if-let` available in all branches.
2026-08-27 11:36:22 +00:00
Calvin Rose cea6dd2261 Handle degnerate range case gracefully. 2026-08-23 13:25:54 -05:00
Calvin Rose 021a17cda1 Fix stack overflow in deeply nested destructuring.
Instead, do a recursion depth check and give a normal compile error.
2026-08-23 13:14:47 -05:00
Calvin Rose d177131c84 Handle empty tuple as lhs in def/var without fatal error.
While an odd construct, this should not cause an abort in the
interpeter. Instead, we should just create no bindings and compile as
normal.
2026-08-23 13:14:47 -05:00
Calvin Rose 5b07408181 Undefined shift (literal 1 should be unsigned) 2026-08-23 13:14:47 -05:00
sogaiuandsogaiu d63d952bc4 Improve docstring for length (#1828)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-23 11:05:24 -05:00
sogaiuandsogaiu 96e07aab36 Improve docstring for last (#1829)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-23 11:05:00 -05:00
sogaiuandsogaiu 4815812827 Improve docstring for loop (#1830)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-23 11:04:49 -05:00
sogaiuandsogaiu 284990a043 Improve docstring for update (#1827)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-22 15:00:40 -05:00
sogaiuandsogaiu 92580fd453 Improve docstring for describe (#1826)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-22 15:00:27 -05:00
sogaiuandsogaiu f545c91581 Improve docstring for interleave (#1825)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-22 15:00:11 -05:00
sogaiuandsogaiu 2c630e0f5c Improve docstrings for sum and friends (#1824)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-21 08:26:26 -05:00
Calvin Rose 2c3995eb33 Make order of path resolution from JANET_PATH more intuitive.
Also match shell convention, with strict searching from left to right
instead of right to left by default. The _first_ element will be bound
to (dyn *syspath*), not the last.

Potentially breaking change for complicated, custom setups
2026-08-21 07:21:24 -05:00
Calvin Rose f47c7b9dce Remove more extra function stubs from float checking. 2026-08-20 17:27:49 -05:00
Calvin Rose ec48673f7c Revert float interface - #1822
It is superfluous since we have the double interface. Users can manually
cast and be aware they are losing precision.
2026-08-20 17:26:30 -05:00
sogaiuandsogaiu 3251197477 Improve docstrings for keep, map, and mapcat (#1821)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-20 09:39:48 -05:00
sogaiuandsogaiu 83558579ce Improve docstrings for all, some, and count (#1820)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-20 08:48:05 -05:00
sogaiuandsogaiu ef07dc347f Improve docstrings of every? and any? (#1819)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-20 08:47:54 -05:00
sogaiuandsogaiu 36db9988b0 Improve docstrings for reverse and reverse! (#1818)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-19 09:56:20 -05:00
sogaiuandsogaiu f9f7a529b2 Improve docstrings of reduce and friends (#1817)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-19 09:56:07 -05:00
sogaiuandsogaiu 16c6bb5fda Improve docstrings for each and friends (#1816)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-19 09:55:43 -05:00
Calvin Rose 5fb06039f3 Correct flags in fiber.h and add comments!
Flag collisions was causing some unexpected behavior in some situations.
Removing the source of collisions resolve odd cancelation behavior in
the ev/ module where multiple calls to ev/cancel on the same fiber would
mess with the internal fiber flags and cause bad behavior and the wrong
error message return (but still otherwise behave correctly, so unless
you were parsing the returned error messages, things likely worked).

Also leave comments and test to avoid regressions.
2026-08-18 16:03:46 -05:00
sogaiuandsogaiu 59b72ba072 Improve docstrings of filter and friends (#1815)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-18 08:17:16 -05:00
sogaiuandsogaiu 04b48de8b4 Align find* and index-of details (#1811)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-17 20:24:24 -05:00
Calvin Rose b09aec83a2 Add t-switch to allow easily using libraries as CLI tools.
Rather than needing to create wrapper scripts for utilities, `janet -t
mylib <args...>` can be a simple, if somewhat awkward, alternative for
portable command line tooling. Also use spork/fmt on boot.janet.
2026-08-17 15:43:38 -05:00
Calvin Rose 65745d0237 Fix some fuzzing bugs and add asserts.
Passing in the wrong number of keyword arguments could be problematic
and cause compialtion issues. Handle that more gracefully and at least
be clean in valgrind.
2026-08-17 11:05:18 -05:00
sogaiuandsogaiu 3d03d083c7 Improve index-of docstring (#1809)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-17 07:56:24 -05:00
sogaiuandsogaiu 5229244a1b Improve completeness of *-in docstrings (#1805)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-16 14:12:26 -05:00
sogaiuandsogaiu 5b438d9440 Tweak frequencies and group-by (#1806)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-16 14:12:18 -05:00
sogaiuandsogaiu 4aa21c0591 Tweak flatten* docstrings (#1804)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-16 09:22:16 -05:00
sogaiuandsogaiu 66be6fbf2b Tweak type docstring (#1802)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-16 09:22:03 -05:00
sogaiuandsogaiu 291e2222bb Improve clarity of some docstrings (#1800)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-15 14:38:33 -05:00
sogaiuandsogaiu f6fd6bdc29 Improve completeness of sort* docstrings (#1798)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-15 12:27:36 -05:00
sogaiuandsogaiu 1e91591c19 Improve completeness of some docstrings (#1791)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-15 12:06:05 -05:00
sogaiuandsogaiu 3f1b31a528 Improve consistency of some docstrings (#1794)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-15 12:05:39 -05:00
Dmitry Solomennikov 23e4ad4bd3 Add int8_t, uint8_t and float getters for consistency (#1799)
Signed-off-by: Dmitry Solomennikov <dmitrys99@mail.ru>
2026-08-15 11:55:09 -05:00
Calvin Rose e3c6893080 whitespace 2026-08-15 11:36:34 -05:00
Calvin Rose 27000deed5 Address #1790 - limit number of automatic parameters.
This also improves the error behavior of malformed automatic parameters
so that the error conditions are better defined. Previously, large
indices like 88888888888888 would actually simply be converted to
symbols and fail later. This change puts strict limitations on this
conversion process - If a symbol is of the form "$<str>" and
(scan-number str) returns non-nil, the result must be a valid index. In
this way, symbols like `$1.1` will result in an immediate macro expansion error
rather than (usually) and unknown binding error.
2026-08-15 11:35:15 -05:00
Calvin Rose ef69c89221 Initial support for GNU Hurd.
Simply stubs out the operating system keywords. Many ifdefs for Linux
can likely be adapted for GNU Hurd.
2026-08-14 08:35:23 -05:00
Calvin Rose 4370ae8acc Address #1792 - Allow janet_collect to be called outside interpreter
loop.
2026-08-08 09:32:26 -05:00
sogaiuandsogaiu 331e8544bc Simplify frequencies implementation (#1793)
* Add tests for frequencies

* Simplify frequencies implementation

---------

Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-08 09:30:20 -05:00
sogaiuandsogaiu f362e8f0fa Improve comprehensiveness of first docstring (#1789)
Co-authored-by: sogaiu <983021772@users.noreply.github.com>
2026-08-02 16:56:20 -05:00
Samuel Martineau c0b32d4e37 Possible fix for #1772 (#1773) 2026-07-01 08:44:11 -05:00
Calvin Rose b070f95180 Fix poll implementation. 2026-06-28 16:58:49 -05:00
Calvin Rose 9eae852ab6 Add JANET_STREAM_NODUPS optimization for net code.
Saves a lot of syscalls in most cases. Also, remove janet_panic call
from inside ev code.
2026-06-28 16:38:35 -05:00
Calvin Rose cbb6a912d1 Avoid panics in thread setup.
Move validation to the parent thread as much as possible.
2026-06-28 15:49:55 -05:00
Calvin Rose 604545a198 Try tweaks to go_thread_subr for mingw 2026-06-28 15:49:55 -05:00
Samuel Martineau 0773444faa Unregister stream from EV upon closure (#1770)
* Prototype fix for #1769

* Add fix for kqueue

* Refactor to fix compilation error on macOS/BSD
2026-06-28 15:44:55 -05:00
Jacob Mealey 54411dc536 Fix typos in boot.janet (#1774) 2026-06-28 08:51:27 -05:00