This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # announcements (2)
- # beginners (52)
- # calva (16)
- # cider (5)
- # clj-kondo (1)
- # cljdoc (11)
- # cljsrn (4)
- # clojure (42)
- # clojure-dev (2)
- # clojure-spec (6)
- # clojure-uk (1)
- # clojurescript (18)
- # cursive (7)
- # datomic (18)
- # duct (1)
- # fulcro (11)
- # graalvm (1)
- # hoplon (9)
- # leiningen (1)
- # off-topic (8)
- # shadow-cljs (16)
- # spacemacs (9)
- # specter (3)
- # sql (33)
- # vim (3)
- # xtdb (8)
Can the clojure compiler detect side effects in functions? Can it decide at compile-time whether a function is pure?
I wouldn’t rely on that to be exhaustive though! There’s nothing in the language to make such a guarantee.
I’m interested in whether the compiler could automatically memoize all pure functions. Could effect massive speed improvements, minimal amounts of memory increase, with very little risk
I don't think it's minimal. Like any function that does something on a data structure using an uuid is unlikely to be called twice with the same.
An interesting aside on the ClojureScript side, once Google Closure knows a function is pure, it does certain optimizations with it. Here is one case where it is incorrect: https://github.com/google/closure-compiler/issues/3079
Yeah my initial impression was that you could probably do a whole dissertation on this topic and still only come up with a method that only works on a restricted scope of language features
Clojure as it’s written can not. But a runtime certainly could detect at runtime and do certain optimizations. Or if code was written to be explicit about its effects
It has probably been discussed numerous times but I can't find any answer. I have these macros:
The issue is that
(defmacro format-query [q] `(cond-> ~q (map? ~q) (sql/format :quoting :ansi))) (defmacro query [c q params] `(jdbc/query ~c ~(format-query q) ~params))
(query 1 2 3)expands to
(jdbc/query 1 2 3)whereas I want it to expand to
(jdbc/query 1 (cond-> 2 ...) 3). Is it possible to do so?
but I think in this case you can change
format-query to be a function, rather than a macro
(defn format-query [q] `(cond-> ~q (map? ~q) (sql/format :quoting :ansi))) (defmacro query [c q params] `(jdbc/query ~c ~(format-query q) ~params))
Sure. But now I can't use
format-query anywhere except for other macros. I guess a solution in this case would be to extract the common part to another macro.
That's what I'll probably do. Thanks!
Can you help me understand why it's expanded the way it is with two
The way I read it:
~(format-query q) unquotes this part, so that the macro is expanded here. It expands in a form
(cond-> ...). The thing I cannot understand is why this form is being computed during macro expansion.
format-query macro was being executed, expanded and then the
query macro continued evaluating and expanding
It's a semantic thing rather than a perf thing. I need the inverse of
nth: construct a vector with a value at position
What I'm trying to do is, for example start with a source like
[1 2] and project it using
second. So it would produce
Then, I could change the projection to
3 and use that to update the source to
I'm basically implementing a lens. I am trying to figure out how to implement it myself rather than use a lib like specter 😅
The operations you mention above sound like they could be easily done on a hash map instead of a vector with regular old
merge. It's not entirely clear to me how those things fit in to your lens implementation.
I suppose you could hold onto the novelty in a hash map and do the merge by
associng the novelty from the hash map into the vector.
Right, the issue is the source to the data is a vector and that needs to be preserved
why not just
(-> project :images :thumbnail)? thumbnail is probably not a boolean, so just having a value where you do check for nil is ok
btw. if you want to get your clojure hat on on the raspberry pi 3 b+ .... installing zulu jdk & lein works surprisingly easy
but trying to use openjdk from adoptopenjdk won't work , something with ssl connections and elliptic ciphers is broken there 😞 ... so zulu instead and life is good