This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-03
Channels
- # aleph (3)
- # announcements (1)
- # beginners (116)
- # boot (8)
- # braveandtrue (4)
- # cider (40)
- # cljdoc (120)
- # cljsrn (10)
- # clojure (29)
- # clojure-austin (4)
- # clojure-dev (43)
- # clojure-germany (1)
- # clojure-italy (4)
- # clojure-nl (17)
- # clojure-russia (19)
- # clojure-uk (76)
- # clojurescript (118)
- # cursive (13)
- # datascript (11)
- # datomic (73)
- # emacs (24)
- # figwheel-main (176)
- # fulcro (40)
- # hyperfiddle (4)
- # leiningen (3)
- # off-topic (1)
- # pedestal (4)
- # re-frame (6)
- # reagent (22)
- # reitit (1)
- # ring (3)
- # rum (8)
- # shadow-cljs (41)
- # spacemacs (11)
- # specter (19)
- # unrepl (1)
Hi. I'm trying to define a macro from within a top-level let
inside a defn
. Then I hope to be able to use the macro within the let
's body. However I'm getting the following strange behavior:
So it looks like eval
understand the-macro indeed is a macro but it seems it "forgets" to pass the invisible &form
and &env
parameters when it macroexpands it.
Now this might look strange, but I'm actually doing something artsy à-là let-over-lambda, experimenting with pertinently non-hygienic macros. This strange configuration is my starting point.
I don't think it's working as well as you think
my guess is it's not really "macroexpanding", it's pretending your macro is a function
try replacing line 14 with (the-macro-2 (not valid code))
to tell the difference
I guess you'd have to add more args on line 11 as well
(defmacro the-macro-2 [& unused])
yes it's not considering "the-macro" as a macro
I don't think defmacro
is meant to be usable this way
line 14 gets compiled before the defmacro even "runs"
I would need reader-macros (Common Lisp provides thoses)
Sorry, I was actually referring to compiler-macros : https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node101.html
clojure doesn't have a separate notion of interpretation
it's all compiled
@tristefigure you can't let a macro like that
your the-macro-3
Var is not a macro yet by the time your invocation of it is analysed and compiled
clojure doesn't have CL-style compiler-macros either although you can use inlines to emulate them
@bronsa @tristefigure there is a macrolet
in https://github.com/clojure/tools.macro, never used it though
yeah that's a bit scary as it doesn't really respects the same semantics as normal clojure, although probably for 96% of the cases it doesn't matter
so good call! it's probably what @tristefigure needs
thanks, but macrolet is something I decided to avoid ... for now. Actually, i'm experimenting with the idea of a closure that receives its context not when it is created, but when it is called. And since I need to fiddle with the passed arguments in the dark, these special closures need to be macros. @bronsa: In clojure.lang.Compiler source code there is a comment about "//no local macros for now".` https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L6822 Do you know what's the rationale behind this ?
> And since I need to fiddle with the passed arguments in the dark what does this mean?
you might be able to do that by making special-fn
capture the &env
, and then read it at runtime from a dynamic var
I mean, I know you could do that, I just can't tell for sure that it'd fit what you want
I guess special-fn
would need to identify b
somehow, which is tricky
Well I actually have something that almost work
if you required it to be listed that'd be easier: (special-fn [a] [b] (+ a b))
(sorry for the comments being in french)
My only problem being that macro-related problem from above
And to get the list of the free variables, I deep walk the code looking for symbols whilst keeping track of let-bound variables.
which is error-prone 😕
I think tools.analyzer would be the most accurate way to do that
Ahaha, I'd like to have something that works as a joke before turning it into ... a serious library 😄
definitely do the code-walking thing then; I recommend tree-seq
if you aren't already using it