M anticompiler.fnl => anticompiler.fnl +6 -5
@@ 1,4 1,4 @@
-(local {: list : sym} (require :fennel))
+(local {: list : sym : sym?} (require :fennel))
(local view (require :fennelview))
(fn map [tbl f with-last?]
@@ 101,10 101,11 @@
(list (compile scope callee) (unpack (map arguments (partial compile scope)))))
(fn send [compile scope {: receiver : method : arguments}]
- (list (sym ":")
- (compile scope receiver)
- method.name
- (unpack (map arguments (partial compile scope)))))
+ (let [target (compile scope receiver)
+ args (map arguments (partial compile scope))]
+ (if (sym? target)
+ (list (sym (.. (tostring target) ":" method.name)) (unpack args))
+ (list (sym ":") target method.name (unpack args)))))
(fn any-computed? [ast]
(or ast.computed (and ast.object
M changelog.md => changelog.md +2 -1
@@ 2,7 2,8 @@
## 0.2.0 / ???
-* Upgrade to Fennel 0.7.0.
+* Emit method calls as foo:bar where appropriate.
+* Upgrade to Fennel 0.7.1-dev.
* Use `let` where appropriate to replace `do+local` or directly inside `fn`.
* Emit identifiers using kebab-case instead of camelCase or snake_case.
* Compile `local f = function()` to `fn` idiomatically.
M test.lua => test.lua +3 -0
@@ 8,6 8,9 @@ SCREAMING_SNAKE = true
string:match("abc")
+local t = {t2={f=function(x) return x end}}
+(t["t2"]):f()
+
for k,v in pairs({a=1}) do k="c" end
print((base or '') .. '_' .. append .. '_')
M test_expected.fnl => test_expected.fnl +7 -2
@@ 6,11 6,16 @@
(global foo bar)
-(tset ids k (: ast "var_declare" (. vlist k)))
+(tset ids k (ast:var_declare (. vlist k)))
(global SCREAMING_SNAKE true)
-(: string "match" "abc")
+(string:match "abc")
+
+(local t {:t2 {:f (fn [x]
+ x)}})
+
+(: (. t "t2") "f")
(each [k v (pairs {:a 1})]
(set-forcibly! k "c"))