Skip to content

Commit

Permalink
Update short-fn to fix #1123
Browse files Browse the repository at this point in the history
Symbols are renamed on expansion to avoid the issue.
  • Loading branch information
bakpakin committed May 13, 2023
1 parent d42afd2 commit fba1fda
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file.

## Unreleased - ???
- Various bug fixes
- Make nested short-fn's behave a bit more predictably (it is still not recommended to nest short-fns).
- Add `os/strftime` for date formatting.
- Fix `ev/select` on threaded channels sometimes live-locking.
- Support the `NO_COLOR` environment variable to turn off VT100 color codes in repl (and in scripts).
Expand Down
15 changes: 9 additions & 6 deletions src/boot/boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -2209,29 +2209,32 @@
(defn saw-special-arg
[num]
(set max-param-seen (max max-param-seen num)))
(def prefix (gensym))
(defn on-binding
[x]
(if (string/has-prefix? '$ x)
(cond
(= '$ x)
(do
(saw-special-arg 0)
'$0)
(symbol prefix '$0))
(= '$& x)
(do
(set vararg true)
x)
(symbol prefix x))
:else
(do
(def num (scan-number (string/slice x 1)))
(if (nat? num)
(saw-special-arg num))
x))
(do
(saw-special-arg num)
(symbol prefix x))
x)))
x))
(def expanded (macex arg on-binding))
(def name-splice (if name [name] []))
(def fn-args (seq [i :range [0 (+ 1 max-param-seen)]] (symbol '$ i)))
~(fn ,;name-splice [,;fn-args ,;(if vararg ['& '$&] [])] ,expanded))
(def fn-args (seq [i :range [0 (+ 1 max-param-seen)]] (symbol prefix '$ i)))
~(fn ,;name-splice [,;fn-args ,;(if vararg ['& (symbol prefix '$&)] [])] ,expanded))

###
###
Expand Down

0 comments on commit fba1fda

Please sign in to comment.