File tree Expand file tree Collapse file tree 4 files changed +21
-1
lines changed Expand file tree Collapse file tree 4 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20
20
* Fix an issue for executing Basilisp scripts via a shebang where certain platforms may not support more than one argument in the shebang line (#764 )
21
21
* Fix issue with keywords throwing ` TypeError ` when used as a function on vectors (#770 )
22
22
* Fix an issue where the constructors of types created by ` deftype ` and ` defrecord ` could not be called if they contained ` - ` characters (#777 )
23
+ * Fix issue with the variadic ampersand operator treated as a binding in macros (#772 )
23
24
24
25
## [ v0.1.0b0]
25
26
### Added
Original file line number Diff line number Diff line change @@ -948,7 +948,9 @@ def _read_sym(ctx: ReaderContext) -> MaybeSymbol:
948
948
If a symbol appears in a syntax quoted form, the reader will attempt
949
949
to resolve the symbol using the resolver in the ReaderContext `ctx`.
950
950
The resolver will look into the current namespace for an alias or
951
- namespace matching the symbol's namespace."""
951
+ namespace matching the symbol's namespace. If no namespace is specififed
952
+ for the symbol, it will be assigned to the current namespace, unless the
953
+ symbol is `&`."""
952
954
ns , name = _read_namespaced (ctx , allowed_suffix = "#" )
953
955
if not ctx .is_syntax_quoted and name .endswith ("#" ):
954
956
raise ctx .syntax_error ("Gensym may not appear outside syntax quote" )
@@ -967,6 +969,8 @@ def _read_sym(ctx: ReaderContext) -> MaybeSymbol:
967
969
return True
968
970
elif name == "false" :
969
971
return False
972
+ elif name == "&" :
973
+ return _AMPERSAND
970
974
if ctx .is_syntax_quoted and not name .endswith ("#" ):
971
975
return ctx .resolve (sym .symbol (name , ns ))
972
976
return sym .symbol (name , ns = ns )
Original file line number Diff line number Diff line change @@ -773,6 +773,14 @@ def complex_resolver(s: sym.Symbol) -> sym.Symbol:
773
773
),
774
774
) == read_str_first ("`(~'my-symbol)" ), "Do not resolve unquoted quoted syms"
775
775
776
+ assert llist .l (sym .symbol ("quote" ), sym .symbol ("&" )) == read_str_first (
777
+ "`&"
778
+ ), "do not resolve the not namespaced ampersand"
779
+
780
+ assert llist .l (
781
+ sym .symbol ("quote" ), sym .symbol ("&" , ns = "test-ns" )
782
+ ) == read_str_first ("`test-ns/&" ), "resolve fq namespaced ampersand"
783
+
776
784
777
785
def test_syntax_quote_gensym ():
778
786
resolver = lambda s : sym .symbol (s .name , ns = "test-ns" )
Original file line number Diff line number Diff line change 1456
1456
(conj coll m)
1457
1457
(conj accum a b))
1458
1458
[coll (apply str accum)]))))))
1459
+
1460
+ (defmacro ^:private variadic-fn []
1461
+ `(fn [& r#] r#))
1462
+
1463
+ (deftest macro-variadic-fn
1464
+ (testing "defining variadic fn with ampersand"
1465
+ (is (= '(2 3 4) ((variadic-fn) 2 3 4)))))
You can’t perform that action at this time.
0 commit comments