Fork me on GitHub

I know this is discussed rather frequently here, but I have questions about currying... I was able to find a whole variety of currying functions from the mailing list years ago that are compiled here:


The "decorated" macro doesn't fit my use case, so I'm really just using curry* from the above example, which means I can't simply expand it for debugging purposes


My use case is applying this (kind of nasty) curried function to convert Church numerals into strings, primarily in order to test for equivalency: (fn [f] ((f (fn [n] (format "f(%s)" n))) "n"))


Very often I want to apply it to a binary Church numeral, e.g. (def one #(%1 %2)), or to ones that simply move the inner binding site, e.g. (def one (fn [f] (f (fn [x] x)))) vs. the canonical (def one (fn [f] (fn [x] (f x)))). I think both of these should be possible by currying the second function, but I'm not having any luck using the techniques from this gist 😕


For the non-unary case, I went so far as writing a macro transform functions that look like anonymous literals into gensymed univariate fns with the bindings all stacked at the top level.


The second example is even weirder...using a fork of the compiler that allows nested anonymous function literals I had to do (def one #(let [x %] #(x %))) rather than simply (def one #(% #(%))) just to deal with the mismatch of binding sites.


I keep thinking it may actually be as simple as writing a more clever printer than (fn [f] ((f (fn [n] (format "f(%s)" n))) "n")) rather than trying to transform the functions I'm applying it to. The structure means that requires something beyond simply uncurrying, i.e. calling apply, though.


Somehow I missed the question


Can you restate?


Put more tersely: I would like to uncurry a function so it can be applied without respect for binding sites (only order). Example: ((fn [f] ((f (fn [n] (format "f(%s)" n))) "n")) #(%1 %2))


A different example since the callee is also curried is: ((fn [f] ((f (fn [n] (format "f(%s)" n))) (fn [f] (f (fn [x] x))))


Put differently, say I have (def cprint (fn [f] ((f (fn [n] (format "f(%s)" n))) "n"))) and I want the same behavior except with arguments more like (defn cprint [[f n]] ((f (format "f(%s)" n)) "n"))


Or whatever would allow me to call (cprint (fn [f x] (f x))) as well as (cprint (fn [f] (f (fn [x] x)))) rather than only (cprint (fn [f] (fn [x] (f x))))


Hope that makes sense


this is giving me flashbacks to grad school

😄 4

Its lambdas all the way down ...


In some ways, Clojure is a step forward because it's not lambdas all the way down. On the other hand, I find it often makes standard lambda calculus tricks more difficult. I'm sure people are thinking, "Well, those are never things you'd use in production," but a lot of this speaks to things like argument order that I know Rich put a lot of thought to and maybe will continue to since he seems unsatisfied as of yet (pretty sure he mentioned this in last year's Conj keynote). This example demonstrates how currying actually doesn't solve that problem like many people assume.


I think currying solves it in terms of the very specific use case of typechecking. But when it comes to source transformation things get much more complicated. I often want to write macros that function like apply-template (not sure what the story is with clojure.template...I've played with it a bunch recently, but have never seen it used anywhere) except that reduce after splicing. Of course Clojure can't do that because many reductions are nondeterministic.


But I think it's not unreasonable to say, "Well, I want two binary functions to compose in a manner where the variables are substituted in the order of their binding and then I'm going to call eval on certain parts of the resulting AST that I know actually can be reduced deterministically."


If you look at these examples, that's essentially what's going on here. The nesting just makes it impossible to use apply-template and even if I could it would be semantically equivalent but not syntactically. That's actually the whole need for the function that calls format in the context of Church encoding! The easiest way to check equivalence, i.e. reduce lambdas to forms that are syntactically equivalent, is through contrived string generation.


@sophiago I'm curious what domain you're using Clojure for and what sort of production applications you're building?


Nothing at the moment actually. I've used Clojure as the primary language for my personal projects for some years now, but most recently worked in Haskell and it seems my next job will probably be in either Haskell or OCaml (just based on demand and what I'm interested in at this point). Anyway, everything I'm talking about above just stemmed from a language-agnostic idea I had a while back regarding lambda binders and working memory while programming and am only now finalizing as a blog post. I wanted to actually quantify how variables are tracked in these different styles using tools.analyzer, which is something I could actually use for source transformation in my automatic differentiation library, but am putting that part off so know...actually finish a blog post.


I remember we talked about this currying issue before. I really am interested to see if Rich ends up going anywhere as far as how we interact with function arguments, even though I haven't agreed with many of his more recent opinions.


I suppose the main library I'm working on is intended to be a production application, even though I'm not being paid for it in the form I'm developing it in Clojure. It started from thinking about speeding up multivariate automatic differentiation, but has moved more towards fast integer arithmetic and vector calculus functions that operate on an IR form I can transform regular Clojure code too and from (although that last part isn't out yet).


So the idea is to add some macros that use tools.analyzer so you'd be working on a higher-level than this ugly format with tuple-keyed sorted-maps. I also tried int-maps for the individual polynomials, but eventually you end up needing to develop custom integer representations to have the same functionality. I'm not sure I'll get to that point in Clojure because various issues with Java, both mine and the environment's.


Wow... I haven't done PDEs since... 1980 I think...


That was first year analysis at university. I vaguely remember quite enjoying that course...


Ha. Well, there are many possible applications of this. I might actually get to do stuff like this for work soon, although not certain enough to talk about it.


I guess I didn't know there were jobs based on stuff like that 🙂


The blockchain folks have finally had enough with being stolen from :woman-facepalming:


and they’re going to start hiring people to investigate themselves? 😉


if the blockchain folks can figure out how to stop getting robbed, they'll make a (another) fortune selling the solution


Hi everyone. I’ve got the following system map:

(defn new-system
  [{:keys [port mongo-uri]}]
  (-> (component/system-map
       :routes       (new-endpoint handler-fn)
       :handler      (new-handler)
       :http         (new-web-server port)
       :middleware   (new-middleware {:middleware [wrap-reload]})
       :db           (new-mongo-db mongo-uri)
       :message-repo (new-message-repo))
       {:routes       [:message-repo]
        :handler      [:routes :middleware]
        :http         [:handler]
        :message-repo [:db]})))
and this is my handler function
(defn handler-fn
  [{:keys [message-repo]}]
   (GET "/" request (index-page message-repo))))
and it looks like my handler fn is not receiving message-repo and I can’t figure out why


I’m using danielsz/system for those new.. functions


@bravilogy You need to wrap the contents of the key in component/using and provide the key you need to the component


@jarcane isn’t that what component/system-using is doing though?


Hmm, you're right, I missed that.


Maybe it also needs to be provided to :handler as well`?


oh and also, if I do

(defn handler-fn
  [& args]
  (println args)
   (GET "/" request (index-page message-repo))))
it shows me this:
(#system.components.endpoint.Endpoint{:routes-fn #object[component_tutorial.core$handler_fn 0x3d0697da component_tutorial.core$handler_fn@3d0697da], :message-repo #component_tutorial.models.messages.MessageRepoMongo{:mongo {}, .... 


notice message-repo in there


Is there a library for generating mysql schema from clojure spec like the way spectomic works?


@bravilogy in component/system-using you need :handler [:routes :middleware :message-repo] I think


@bravilogy the "message-repo" in the println is the one nested in the endpoint from the :routes/Endpoint component


ok, I’m getting somewhere now I think 😄 so I added :message-repo to handler and it works now. but I have another issue. I’m getting com.mongodb.MongoClient cannot be cast to com.mongodb.DB


and I have a feeling that it’s something to do with this

(defrecord MessageRepoMongo [mongo]
  (find-all [this]
    (mc/find-maps (-> this :db :conn) "messages")))


this is that message repo basically


and -> this :db is giving me the mongo component from danielsz/system


but I think it doesn’t like that conn, even though that’s the actual connection


ok figured it out! damn it, finally 😄


I should’ve used (-> this :db :db) instead


where first db corresponds to just mapping from system-map. perhaps I should change that


Morning. I have a friend who wants to learn Clojure with TDD. I know of quite a few good books on Clojure, and quite a few books and courses that teach using TDD, but I don't know of any courses that teach Clojure using TDD - has anyone heard of one?


(and yes, I used the Slack search here and Google, and apart from a no-longer running Helsinki university MOOC I didn't find anything appropriate)


@sleepyfox the thing is, many clojurists prefer the REPL over tests for exploration


Learning through the REPL feels natural.


I would agree with the statement "learning through the REPL feels more natural than learning through tests". I was hoping that I could kill two birds with one stone for my friend, who doesn't know either. Many places now teach Ruby, Python etc. using TDD e.g. Maker's - I had wondered whether anyone had tried doing the same for Clojure.


Perhaps it’s easier to learn TDD and programming separately (unless your friends already knows another language). I definitely think Clojure could benefit from more articles on TDD though, especially for those coming from the Java / Scala / Ruby world. Another interesting project to add to the long list of things I’d like to do!


I think there's a subtle difference here between "teaching X using TDD" and "teaching X and TDD at the same time", and I'm talking more about the latter than the former.

👍 4

@bravilogy just as a design thing, it would be better to define a function in your mongo component namespace that you call and pass your mongo component to get its database handle, rather than having other components reach into its internal structure


@mg the thing is, that mongo component comes from a package I use - danielsz/system and I don’t think I can extend it like that


but it turns out it’s not that bad. I was doing it wrong


but I understand your point as well

Drew Verlee19:05:36

Clojure and Datomic continue to teach me things even two years into learning the basics. 🙂. Just a reminder of how awesome this all is.

👍 12
🎉 12

Want to share what you learned today?

Drew Verlee19:05:16

I was struck with the thought today that postgres and sql dont offer declarative semantics for extending or querying arbitrary data. Specifically, if you want to associate some data in a relational model, 1.your forced to worry about the storage model (normalization vs demoralization) 2. In cases where you want flexible associations, the language offers no support, so you have to model it yourself.

Drew Verlee19:05:29

For example, if some people have dogs and others dont. You can create a 3 tables: person person_dog dogs Then use the person_dogs table to link them. The same goes for people having cats, etc…

Drew Verlee19:05:07

The information the table conveys, is no different then any other piece of information.


I'm pretty sure it is an unintentional typo, but I love the use of "demoralization" above 🙂

😂 8
Drew Verlee19:05:29

thats how i feel lol

Drew Verlee19:05:02

I need to find a way to make less spelling mistakes.


nice to have the ability to do [?person _ ?dog] in a query

Drew Verlee19:05:26

these issues seem minor, but if you take a big step back from what the majority of my “leads” work on, its patching issues of this nature.

Drew Verlee19:05:46

imposing graph semantics on relational databases.

Drew Verlee19:05:27

dealing with state oriented programming issues.


I wrote a bit of a screed on that former issue here:

Drew Verlee20:05:48

Also, i have been really thinking a lot about the protective mentality that types (at least in java) tend to create. So much energy goes into what cannot happen. As if the goal is to narrow the specification down to only one option. In which case, why not have a function that does that one thing? What have we achieved? We have documented what can go wrong, but we haven’t done the right thing. I think Types that model real constraints are useful, but real constraints are few and far between and many if not most are probably already handled by your programming language. This one is harder to reason about, because its not about universal truths (types are good vs types are bad) its when, in the context of your language, the type system moves you closer to a useful system or away from it. This is what happens when we get sunshine in michigan. I should move…


Hm, this is more of a Clojure/Java question, but how could I start a process in clojure that wouldn't be a subprocess in that it wouldn't exit when clojure app exits?


There is most likely some kind of Clojure wrapper floating around I imagine


There is also the shell namespace in


you might specifically want nohup when spawning your process

Brian F20:05:44

I just had to solve this problem recently. just adding & at the end of the command seemed to be enough. It will initially be a subprocess, but when the parent process dies it gets promoted such that it is no longer a subprocess (not an orphan)

Brian F20:05:00

One caveat I found was that when you are running this in the repl, if you ctrl+c as you are shutting it down, it will kill the subprocess before it gets promoted


hm, ok, but what about windows

Brian F23:05:07

Can't help you there, I haven't run clojure on windows yet


hello guys, I want to use specter library. does anyone of you know which function is used to navigate the entire data structure tree and manipulate specific key


See #specter

👍 4
Brian F21:05:01

Hey all, I'm currently evaluating different http servers. We're currently on http-kit, but we are trying to get off of it because it is not clear that it is going to continue to be maintained going forward. Specifically, I'm looking for something that does a good job with asynchronous websocket connection handling. Aleph seems like a reasonable alternative, but I wanted to see if anyone had any recommendations


I use #yada for that (on top of aleph)


@bfouts I’ve not used it, but might be something to look at


pedestal is a framework that runs on top of either jetty, immutant, or tomcat, so if you already have your own stuff built on top of a raw http server, it's probably not what you're looking at


http-kit is still being some-what actively maintained, so if that's your only reason for looking, I wouldn't jump the gun yet


but either way, aleph is also a nice choice

Brian F21:05:05

Ok sweet. Thanks for the feedback!


(defprotocol process-assets (process-assets-impl [asset] "assets")) (extend-protocol process-assets String (process-assets-impl [assets] "string assets") java.util.Vector (process-assets-impl [assets] "vector assets"))


whats wrong with this protocol definition


I am getting CompilerException java.lang.ClassCastException, compiling


@huthayfa.ainqawi not sure what error you're getting but this works for me

(defprotocol process-assets
  (process-assets-impl [asset] "assets"))

(extend-protocol process-assets
  (process-assets-impl [assets] "string assets")

  (process-assets-impl [assets] "vector assets"))

(process-assets-impl "my string")
;;=> "string assets"


btw. not sure what's your intention by specifying "assets" in defprotocol definition, but that's the ends up being docstring for process-assets-impl


after I cleaned the build the error was gone


@huthayfa.ainqawi use backticks around your code to make it more readable. `


I'm using environ to set some environment variables for a project. In one namespace there is a value like:

(def foo (Integer/parseInt (env/env :foo)))
When the ns is AOT'ed, lein {uber}jar results in a java.lang.NumberFormatException. I can set any value at compile time like:
FOO=1234 lein uberjar
And the problem goes away. But this is annoying. Is there a better way to deal w/ this than something like:
(def foo (when-let [foo (env/env :foo)] (Integer/parseInt foo)))


write a function (or macro) that makes it more convenient, and lets you specify what you want if the environment variable doesn’t exist.


(defmacro getenv [name parser default]
  `(let [name# ~name]
     (if (contains? env/env name#)
       (~parser (env/env name#))

(getenv :foo Integer/parseInt 0)
;; => 0

(getenv :foo Integer/parseInt (throw (ex-info "Missing FOO" {})))
;; throws an error


I'm using lein ring uberwar to build my clojure/clojurescript webapp. All the clojurescript-only dependencies are copied to WEB-INF/lib, causing the war to be much larger than needed. Is there a way to only include the jvm-specific dependency jars?


Cljs dependencies should have the scope provided like

[org.clojure/clojurescript "1.7.228" :scope "provided"]
to prevent that.


Doesn't seem to work, unfortunately. All of them are still there


The "provided" scope should take care of that (did you clean properly?) Another approach is to have a separate git branch or repo for server stuff only and for production releases do an uberjar /war and just copy there the compiled js code (that you have compiled from a separate git branch/repo again).


you can put all CLJS deps into the :dev profile via :profiles {:dev {:dependencies [...]}}


or use a custom profile but that needs to be enabled manually during development


Yes, pretty sure I cleaned everything. Removed all non-git folders in project including target, out, js/compiled


I also thought about putting cljs dependencies in the dev profile. So the war/jar tasks don't include dependencies from dev-profile? I'm asking since the cljsbuild task implicitly does (?).