This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-31
Channels
- # aws (18)
- # babashka (35)
- # beginners (7)
- # cider (3)
- # clara (2)
- # clj-kondo (15)
- # cljs-dev (1)
- # cljsrn (3)
- # clojure (20)
- # clojure-canada (1)
- # clojure-dev (3)
- # clojure-spec (17)
- # clojure-uk (13)
- # clojutre (1)
- # cursive (7)
- # datomic (1)
- # duct (7)
- # fulcro (33)
- # helix (77)
- # jobs (3)
- # malli (15)
- # meander (3)
- # off-topic (30)
- # pathom (3)
- # quil (1)
- # reagent (1)
- # reitit (10)
- # shadow-cljs (2)
- # tools-deps (5)
- # xtdb (6)
- # yada (1)
(time ((fn prime-numbers?
([num]
(prime-numbers? 2 (range 2 (inc num))))
([p, coll]
(let [multiples-of-prime (drop 2 (range 0 (inc (last coll)) p))
remaining-coll (remove (into #{} multiples-of-prime) coll)
next-num (nth remaining-coll (inc (.indexOf remaining-coll p)) nil)]
(if (nil? next-num)
coll
(recur next-num remaining-coll))))) 9927))
Please give feedbacks on the implementation of Sieve_of_Eratosthenes for generating primesHow is defn- different from defn
(defn- foo [x] ,,,)
is the same as (defn ^:private foo [x] ,,,)
It means that if you are in a different namespace than where foo
was defined, you cannot use the normal way to refer to it, e.g. other.ns/foo will give an error, because it is private.
You can still refer to it using #'other.ns/foo
as a workaround for it being private, if you wish.
So private in Clojure does not absolutely prevent you from using it from outside the namespace, it simply means you have to make a small explicit jump-through-a-hoop to use it.
For those reading this later, I edited my earlier message that dominicm pointed out a typo in, to correct it. Thanks for noticing that.
Is something similar to a private function in OOPs
Is there a good way to match a namespaced keyword key without knowing the namespace? e.g. when I have a keyword :employee/last-name
as a key in a map, and I want to get the value without knowing the keyword namespace.
like this?
(let [the-map {:foo/last-name 2}
[v] (keep (fn [[k v]]
(when (-> k name #{"last-name"})
v))
the-map)]
(println v))
Two issues: it creates an extra lazy collection and it traverses the entire map even though you just need the very first found key (at least, as far as I understand).
It's possible to use reduce
+ reduced
or just loop
if the points above matter.
Does anyone have a suggestion for a parser generator that also produces serializers? My ideal case is something that takes an ABNF, parses source, lets me modify the resulting AST, and goes back to source.
I'm not aware of one (aside from tools.anaylzer if this is a clojure dialect) but I suppose your other option is to use antlr and a custom visitor to go back to source? I imagine the difficulty depends on how complex your language is and how much you care about preserving comments / formatting. Are there particular things about the serialization process you're thinking about that would make writing a visitor difficult?
got it. yeah i don't think there's even an antlr grammar for hcl yet... i'm not even sure if hcl is a cfg or not
somewhat related, I ran across https://www.pulumi.com/ recently and it seemed interesting