[ClojureScript] Re: Including a cljs namespace automatically apon use of clj macro
Ah this is just what I was looking for. I will need to rearrange some of the namespaces but this looks like a perfect way of implementing it. Thanks Thomas! Crispin On Tuesday, July 18, 2017 at 3:19:38 PM UTC+8, Thomas Heller wrote: > > You can easily achieve this by creating a CLJS namespace that > self-requires the macros. Having dedicated .macros namespaces is generally > not recommended. > > pixi/something.cljs > (ns pixi.something > (:require-macros [pixi.something])) > > pixi/something.clj > (ns pixi.something) > > (defmacro foo [..] ..) > > > user/code.cljs > (ns user.code > (:require [pixi.something :refer (foo))) > > (foo) > > The user code does not need to worry about whether foo is a macro or not, > it is handled transparently by the compiler. You never need to > :refer-macros or :require-macros in the user code this way. And you can > manage dependent CLJS namespaces that only the macro uses by requiring them > in the .cljs companion file. > > HTH, > /thomas > > On Monday, July 17, 2017 at 4:54:38 PM UTC+2, cri...@procrustes.net wrote: >> >> Hi there, >> >> I have a macro for use in cljs that injects code to make a function call >> to a function in a cljs namespace. Now when I use that macro I have to >> :require the corresponding cljs namespace or during compilation I am >> flooded with superfluous: "WARNING: Use of undeclared Var >> mycljsnamespace/func at line " messages. >> >> Is there a way to make the use of the macro in a cljs namespace add the >> cljs require statement to ensure that these warnings are suppressed? >> >> The function call in the macro is here: >> https://github.com/infinitelives/infinitelives.pixi/blob/master/src/clj/infinitelives/pixi/macros.clj#L36 >> >> and when using it, the compilation looks like: >> >> WARNING: Use of undeclared Var >> infinitelives.pixi.canvas/get-default-canvas at line 15 src/cljs/... >> WARNING: Use of undeclared Var >> infinitelives.pixi.canvas/get-default-canvas at line 15 src/cljs/... >> WARNING: Use of undeclared Var >> infinitelives.pixi.canvas/get-default-canvas at line 11 src/cljs/... >> ... >> >> at this stage in my present project its at least 50 lines of these. >> >> if I require that name space in the client code that warning disappears >> but that requires the user of the macro to know that in advance, and be >> disciplined enough to do it. >> >> How do I *auto require* the namespace, when the macro is used? >> >> I found this thread from 2013: >> https://groups.google.com/forum/#!searchin/clojurescript/require$20in$20macro%7Csort:relevance/clojurescript/FNwwN87B2EE/lLF-Tel977AJ >> >> In it, Jozef Wagner states: "AFAIK there is no way to do this >> automatically" >> >> Is this still the case? >> >> I see CLJS has supported since 1.9.293 : CLJS-1346: Support require >> outside of ns >> >> Can I make the macro inject the require into its output code so the >> "WARNING: Use of undeclared Var" is not emmitted? >> >> I have experimented with this but have been unable to make it work. >> >> Is this possible to do? If so, how can this be done? >> >> Regards >> >> Crispin >> > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at https://groups.google.com/group/clojurescript.
Re: [ClojureScript] secure cljs eval of user generated code
Thanks wow I had no idea it was possible to securely sandbox a browser from javascript like that. I can't even imagine how that is done reliably but I will explore it. My use case is two fold: an Excel like formula language, and React.js expression. Both only need pure functions. React itself doesn't need to run securely, just the user expressions. -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at https://groups.google.com/group/clojurescript.
[ClojureScript] Re: Including a cljs namespace automatically apon use of clj macro
You can easily achieve this by creating a CLJS namespace that self-requires the macros. Having dedicated .macros namespaces is generally not recommended. pixi/something.cljs (ns pixi.something (:require-macros [pixi.something])) pixi/something.clj (ns pixi.something) (defmacro foo [..] ..) user/code.cljs (ns user.code (:require [pixi.something :refer (foo))) (foo) The user code does not need to worry about whether foo is a macro or not, it is handled transparently by the compiler. You never need to :refer-macros or :require-macros in the user code this way. And you can manage dependent CLJS namespaces that only the macro uses by requiring them in the .cljs companion file. HTH, /thomas On Monday, July 17, 2017 at 4:54:38 PM UTC+2, cri...@procrustes.net wrote: > > Hi there, > > I have a macro for use in cljs that injects code to make a function call > to a function in a cljs namespace. Now when I use that macro I have to > :require the corresponding cljs namespace or during compilation I am > flooded with superfluous: "WARNING: Use of undeclared Var > mycljsnamespace/func at line " messages. > > Is there a way to make the use of the macro in a cljs namespace add the > cljs require statement to ensure that these warnings are suppressed? > > The function call in the macro is here: > https://github.com/infinitelives/infinitelives.pixi/blob/master/src/clj/infinitelives/pixi/macros.clj#L36 > > and when using it, the compilation looks like: > > WARNING: Use of undeclared Var > infinitelives.pixi.canvas/get-default-canvas at line 15 src/cljs/... > WARNING: Use of undeclared Var > infinitelives.pixi.canvas/get-default-canvas at line 15 src/cljs/... > WARNING: Use of undeclared Var > infinitelives.pixi.canvas/get-default-canvas at line 11 src/cljs/... > ... > > at this stage in my present project its at least 50 lines of these. > > if I require that name space in the client code that warning disappears > but that requires the user of the macro to know that in advance, and be > disciplined enough to do it. > > How do I *auto require* the namespace, when the macro is used? > > I found this thread from 2013: > https://groups.google.com/forum/#!searchin/clojurescript/require$20in$20macro%7Csort:relevance/clojurescript/FNwwN87B2EE/lLF-Tel977AJ > > In it, Jozef Wagner states: "AFAIK there is no way to do this > automatically" > > Is this still the case? > > I see CLJS has supported since 1.9.293 : CLJS-1346: Support require > outside of ns > > Can I make the macro inject the require into its output code so the > "WARNING: Use of undeclared Var" is not emmitted? > > I have experimented with this but have been unable to make it work. > > Is this possible to do? If so, how can this be done? > > Regards > > Crispin > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at https://groups.google.com/group/clojurescript.