Fork me on GitHub

Is there a css parser that can turn css into garden syntax?


@c.westrom I searched for such a thing a couple years ago and found nothing


I thought about trying to write such a thing and looked into it. The first step would be having a parser for CSS that we could use from Clojure. This might be a step in the right direction:


So far I’ve been using But this you just linked to me may just be what I need.


(ns wildwestrom.tailwind-garden
  (:require [clj-css.core :as parser]

(def preflight-url "")

(def tailwind-url "")

(slurp tailwind-url)

(defn css-to-data
  (parser/parse-css (slurp source)))

(def tw-preflight (css-to-data preflight-url))

(def tw-full (css-to-data tailwind-url))


I also found this: Netbeans seems pretty mature. I could probably rewrite the tests in clojure.


I feel like this would be a real game-changer for garden adoption


another option, use clojurescript to do the conversion, and leverage this JS parser


What would a proper -equiv look like for a bigdecimal-like type on cljs? This is broken because it fails if other is non-numeric I assume we want to be hosty and, unlike on the jvm, copy the fact that in js (= 1 1.0) ? If so .eq does this for us in this case. So does it have to be something like

(and (or (decimal? other) (number? other)) (.eq v other))
(where "decimal?" checks for our custom bigdecimal type ?


Although I guess it's important that this would work if the argument order to = were reversed, so I guess it must return false for other numbers that aren't our custom decimal type


Typically you would like -equiv to be reflexive, symmetric, and transitive, and if you want to be able to use the values as elements in sets or keys in maps, you want hash consistency, i.e. "if (-equiv x y) is true, then (= (hash x) (hash y)) is true". That last one can be difficult to implement, and I wouldn't be surprised if it was one of the reasons that (= 1 1.0) is false in Clojure.

👍 3

cljs makes some different choices there in the details, and I don't know all of the differences between clj and cljs here.

Alex Miller (Clojure team)15:02:29

in clj, = does not work between integer and floating point types, has nothing to do with hash consistency

Alex Miller (Clojure team)15:02:10

"The = operator (equality) tests equality. It compares values in a type-independent manner, but not between floating points and integer types. This allows numbers to be used as map keys with correct semantics. To check numerical equivalence between floating point and integer types, use the == (equivalence) operator."


@alexmiller The part that catches my attention in that line that may have to do with hash consistency is "This allows numbers to be used as map keys with correct semantics."


But it isn't necessarily clear to me precisely what "with correct semantics" is intended to mean there.

Alex Miller (Clojure team)15:02:46

keep in mind this is design stuff from the 1.3 overhaul of numerics so some of this may be vs the pre-1.3 world

Alex Miller (Clojure team)15:02:30

there are some other pages in that vicinity of the design archive with more info, and some old pages that I'm not sure are still available that were on the clojure web site back then too


The reason for my "I wouldn't be surprised if" (meaning, this is my guess), is that it would be really really difficult to make = behave like == for numbers, and also make hash consistent with such a different =, e.g. you would have to figure out how to make hash return the same value for 3/2, double 1.5, float 1.5, etc., even though clj at least tries to return different hash values for 1.51 and other only-slightly-different numeric values. cljs seems to convert all numeric values to the nearest integer before hashing, but clj definitely does not, so this might be easier to do in cljs, at the cost of all numeric value whose floor is the same integer colliding in their hash value.


For example, with Clojure 1.10.1 (and going back further for sure):

$ clj
Clojure 1.10.1
(hash 1.5)
(hash 1.51)
(hash 1.511)


In ClojureScript:

$ cljs
WARNING: When invoking clojure.main, use -M
ClojureScript 1.10.773
(hash 1.5)
(hash 1.51)
(hash 1.511)
(hash 1.01)
(hash 1.9)


hash consistency is much easier to achieve if you are willing to have lots of collisions 🙂

Alex Miller (Clojure team)15:02:23

I mean, if you're using floats as keys in a hashed coll, that's not ever really a good idea (but particularly bad in this case)


Sure, not recommending it. You know I can do angels-on-the-head-of-a-pin discussions with the best of them. I'm not worried about any of this stuff, but much more attuned to it after writing the Clojure guide article on equality.


How can I add props to the & children in a reagent component? I basically have a parent component that takes unknown child components, and I want to add certain props to these children. The React way seems to be calling React.cloneElement(child, {additionalProps: ..})


If you receive Hiccup, you can just modify it as a regular data structure before embedding it into a higher order component.