mirror of
https://github.com/janet-lang/janet
synced 2025-02-02 10:19:10 +00:00
Update short-fn to fix #1123
Symbols are renamed on expansion to avoid the issue.
This commit is contained in:
parent
d42afd21e5
commit
fba1fdabe4
@ -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).
|
||||
|
@ -2209,6 +2209,7 @@
|
||||
(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)
|
||||
@ -2216,22 +2217,24 @@
|
||||
(= '$ 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))
|
||||
|
||||
###
|
||||
###
|
||||
|
Loading…
Reference in New Issue
Block a user