Fork me on GitHub

is there a way to use macros to change the way syntax is parsed? let’s say i wanted to write css in clojure within a macro…

[.class-name { :padding 1em 2em 1.5em 2.5em }]
is it possible to write a macro that can actually handle 1em without barfing? The easiest solution is just to wrap that in text: ”1em 2em 1.5em 2.5em”, but I don’t want easy, I want convenient 😛.


I can think of a lot of alternatives such as def-ing each and every potential property .. (def flex “flex”) for example, but that sounds like a maintainability nightmare


> is it possible to write a macro that can actually handle 1em without barfing? no.


macros are given forms which have already been read. the reader will not read symbols starting with numbers


you could try to do something crazy with tagged literals, like #em 1... but strings seem fine to me


Thanks @tomjack . I have read through a couple of macro tutorials but none of them touched on anything like changing the way tokens are parsed, so I wasn’t sure if that’s an impossibility or just rare.


you can look for discussion about "reader macros"


sounds like that's what you're asking for, and clojure doesn't have it


@danielpcox Reagent patterns are described here: D3 links towards the end, under "Further Examples"


Thank you @isak !


why is there the .- javascript property accessor in clojurescript when it breaks under advanced compilation?


Hello I have a question on defrecord and how clojurescript compile it in javascript


The code in javascript is:


I don't understand the line 15


what is "_" ? how can I enter in this case?


why we don't have something like this


@raphael: that's for (extend-type default Fly (fly [this] ...))


what is default?


OOkkkkkkk I understand! thank you @tomjack thank you very much!! 😀😀😀


html* is also a macro


did you mean that?


@dm3: Yes. Doesn't it have to be if it needs to be called from CLJS?


html has to generate code that cljs compiler can then compile


And it can't compile code that refers to another macro?


it can, but html* being a macro means that gensymmed prefix# symbol is passed in, instead of its value


Oh, yeah. That makes sense. Any idea how to avoid or to eval that?


you have to generate the prefix at compile time in order to make use of its value in a macro


for some reason I think you don't want html* to be a macro


Yeah. But then it has to be a CLJS function, right? Which should work...


Oh, yes, done.


That works.


I had it like that in the beginning but changed it to a macro for testing it using macroexpand. If html* is a function I can't test how it transforms its input because it'll evaluate it's body - and I need it unevaluated. All I want to achieve is annotate the data before I pass it down to sablono.


Ah, yes, and that's why html* being a function still doesn't work.


CLJS will evaluate the generated code (including for loops etc.) and will pass the evaluated data to html*. I need the unevaluated data.


But I also can't generate prefix at compile time as it depends on js/this.


@lwhorton: look for inspiration here[1], I’m using Garden[2] with some sugary macros[3] on top of it. Instead of 1em I would write (em 1) - brain can adapt easily simple_smile [1] [2] [3]


@darwin: could you explain the >> macro vs default garden declarations?


@dm3: haven’t touched it for more than a year, so I don’t remember the details, here is the code:


the goal was to make it more “DRY”, see my css files and usage of that macro


yeah, thanks


was looking for the motivation on doing things that way instead of the vanilla garden


seems like a few characters less to type


also vectors maintain order


so it behaves like css, not randomly when you re-declare some property within one block


Anyone who uses planck? How do I do to preload it with all my libraries in .m2? I tried planck -c ”~/.m2/repository” and then (require …) but it couldn’t find it.


@vikeri: Planck supports classpath semantics, so you'd have to provide a colon-delimited list of all jar files (same would be true for ClojureScript, I believe)


@mfikes: Alright, so when I go in to find the reagent jar and start it, I would also have to include every dep that reagent has?


Starting it with planck -c reagent-0.5.1.jar works but gives me this error when trying to require reagent.core: No such namespace: cljsjs.react, could not locate cljsjs/react.cljs, cljsjs/react.cljc, or Closure namespace ”cljsjs.react"


@vikeri: Right. One approach is to use lein to generate the classpath to feed to Planck. (Having said that, I'd be surprised if Reagent works in self-hosted ClojureScript).


Alright, well my use case that I want to go in and fiddle with functions in different libraries without starting a project with them. Maybe this is not intended use for planck?


Speaking of fiddling, I suppose that works with Reagent with self-hosted ClojureScript so… with Planck the issue would be the lack of browser capabilities (perhaps top-level window object etc.)


@vikeri: Sure, you should be able to use Planck to explore functions in libraries—the trick would be loading them. Planck doesn’t attempt to solve the dependency problem and just supports classpath.


@mfikes: Hmm ok, if I get time I might look at doing something to more easily browse the libraries already loaded in ~/.m2 would be awesome to have something like planck —libraries=reagent:foo:bar:doo where those libs have to be present in your ~/.m2 folder.


@vikeri I was toying playing with the same ideas wrt planck and project-files


One could imagine using lein the first time just to download the deps and generate the classpath, and then apply magic to make subsequent planck startups quick


Right, you could use Planck itself to form the classpath via something like


@slipset: Would be great!


@vikeri: This might get you by for now, if you want to just fool around and not use lein and project.clj:


(It uses Planck to form its own classpath from JARs in the local Maven repo.)


I created a #C0Y3CSPHQ channel so chats like the above can occur in there for people who are interested in Planck.


Wishing there was a native-JS port of partition that included stepping and padding…


thanks @darwin. I did write a 3-arity version of ems to support num, topbottom left right, and t r b l like normal css. those sugar macros look nice, though.


I have an app using sablono that throws react key warnings only the first time a certain component is mounted and then never again regardless of how many times it’s mounted/unmounted. Any ideas?


Yesterday I was asking about reading a file in cljs ( ), and I realize now that there was some confusion in my understanding of some of the help I was getting. I was asked if the value I was passing to a macro was known at compile time, and I said yes, but that was wrong. For testing purposes that value currently is hardcoded at compile time, but at some point I will be moving to building the filepath string at runtime, since it will always follow the same pattern and there will be a lot of them. Sorry about that misunderstanding :P So is there a way to pass variables at runtime to a macro from cljs?


@numberq: macro expands at compile time, it has no chance to know what value the symbol will have at runtime, so you cannot slurp file at compile time with a path taken from the runtime-value of passed-in symbol


in other words: macro can just rewrite code using information known at compile time


Hmm I was afraid of that. So my only bet is to either hardcode every filepath or to use Node.js like you suggested yesterday?


you can still “compute” file paths, if that computation can be performed at compile time


so the question is, if you will be building file paths at runtime, does it really need to be at runtime? don’t you have all inputs known at compile time?


I have all inputs known at compile time, but I don't know when they'll be used. Essentially, when an event is triggered, a random map will be loaded. The filepath will look something like "/assets/maps/map#.txt", where # identifies which map it is.


So load-map could be called with whatever map is randomly chosen, and I was hoping to do that in one or two lines with something like (def map-file "whatever/map.txt") (load-map map-file)


Or rather I should say, I'd rather not have all inputs known at compile time. Unless I'm mistaken, wouldn't that mean having a separate call to (load-map) for everything single map there is?


Let’s see if I understand your problem: You have quite small set of map files in some folder. And you want to use those files dynamically during runtime (in reaction to some events). You cannot access filesystem during runtime. My solution would be: 1) write a macro load-maps which lists all maps in the folder and slurps them into a clojure map key-ed by their filenames (when called this happens during compile-time executed by clojure) 2) in cljs (def maps-in-memory-cache (load-maps)) 3) in cljs write a function, which can lookup a requested map in the cache, something like (defn load-map [name] (get maps-in-memory-cache name))


you can try serving the maps over http where the network becomes your filesystem


long-story-short: load-map is dynamic, load-maps is static macro which runs at compile-time and builds a static map of file contents for you


That sounds like a good idea. The number of maps will be a bit larger than "quite small" eventually, but I don't think it will get into performance or memory affecting numbers. Thanks! parrot


if it is “too big to embed into js source” then you have to come up with some dynamic method how to retrieve those files on demand at runtime


I'll keep that in mind, but based on current plans I don't think it should get to that point. You never know, though