Fork me on GitHub
#clojure
<
2018-12-28
>
ahungry02:12:31

Is there an existing option in CIDER (Emacs) that will auto-switch namespace in the REPL to match the current clojure mode buffer?

ahungry02:12:12

So that if I am in foo.clj, and I change to bar.clj, the REPL will automatically (in-ns 'whatever-project.bar)

andy.fingerhut02:12:04

I do not know, but wanted to point out that if no one here has an answer for you, there are #emacs and #cider channels that may be more target-rich environments for asking.

flefik02:01:15

cider-send-ns-form-to-repl and cider-send-ns-form-to-repl-focus

flefik02:01:26

a bit late but 🙂

ahungry03:12:59

I've been toying with ideas for what custom FS I could build in FUSE after writing a simple RESTful API + FUSE integration in Clojure to serve dog pics. To actually make a real integration that provides value, I'm wondering if something that combined (dir *ns*) type output (but mapped doc across each) and stored the results in a directory structure, with file names being the function/variable names and the VFS file contents being the doc string would provide any value to clojure users

ahungry03:12:23

Then tree based FS navigators (like ranger) or Emacs dired would let users very quickly cycle through files (filtering off ones they do vs do not want) and see the result of some doc

jaide04:12:28

Getting ready to announce the release of https://github.com/jayzawrotny/book-report tomorrow. Any sour notes stick out in my tiny, quiet symphony?

rutledgepaulv05:12:35

the “Which prints:” section shows different text printing than the code above that staged it would suggest. Probably just changed it a few times and something got out of sync.

jaide05:12:52

Good catch! Thanks for giving it a look.

rutledgepaulv05:12:00

Would also be nice to have some guidance on expected workflow. Are you expecting others to create workbooks and distribute them?

rutledgepaulv05:12:25

Or looks like this is more of a scratch pad for the person doing the learning to come back and reference? sorry maybe misread the intent originally

rutledgepaulv05:12:45

in that case probably what you have makes sense. they can organize it however they like and use whatever workflow

rutledgepaulv05:12:46

looks neat though 🙂 nice to see in-repl tooling for people learning

đź‘Ť 4
jaide05:12:23

Good point, I’ll try to clarify that in the explanation. Though it definitely could work as a repo people can clone to learn how an API works or learn a specific topic. I haven’t really thought of that use case.

dangercoder13:12:53

what library are you guys using for http-calls? I am currently using https://github.com/dakrone/clj-http but I am having issues with setting custom SSL-contexts.

dangercoder14:12:59

Got it working by using keystore parameters.

dangercoder14:12:26

I had a pkcs12 file, only had to set the parameters

keystore, keystore-pass and keystore-type
.

absolutejam13:12:28

what's the idiomatic way to build a vector in Clojure?

absolutejam13:12:45

Basically, I have a hash-map and I want to build a formatted string depending upon specific keys

absolutejam13:12:31

I was going to just create a vector and then string/join the final output but now that I think about it, maybe that entire approach is wrong

rakyi13:12:29

maybe something like ((juxt :a :b :c) {:a 1 :b 2})

rakyi13:12:10

depends on what you are trying to accomplish, maybe give us an example of input and output?

martinklepsch13:12:37

I'm looking for a way to relativize two paths like this:

(= "../basics/route-syntax"
   (wanted-function
    "/d/metosin/reitit/0.2.10-alpha1/doc/http/pedestal"
    "/d/metosin/reitit/0.2.10-alpha1/doc/basics/route-syntax"))
I briefly played with nio.path's relativize but it did return too many .. jumps

absolutejam13:12:57

Well, input would be a 'bookmark' which is an SSH connection:

{ :name "My super important production server", :alias "prodserv", :tags [ "foo", "bar" ], :address "my.host.internal", :user "james" }
And i'm just basically trying to format the output based on different fields, eg.
[1] james@prodserv (My super important production server)
or if some fields were missing, it may just be
[1] prodserv

absolutejam13:12:39

Normally, I'd just have some conditionals and append to a list the merge the list

absolutejam13:12:41

or something along those lines

absolutejam13:12:40

But now I'd have to have a load of embedded logic such as if key :name then prepend :name value @ in pseudocode

absolutejam13:12:54

Should I just have smaller functions that return a blank string if the value is missing, and use (format) to merge them all into a single output string? Or is that equally as bad?

rakyi13:12:04

I’d say functions are always idiomatic in Clojure 🙂 one function, which might be handy in your case is fnil and there might be others https://clojure.org/api/cheatsheet

rakyi13:12:13

Clojure is built around manipulating data structures and we have a lot of built-in functions to do just that

rakyi13:12:58

I’d probably use format in the end

rakyi13:12:47

you could also merge a map with defaults with the actual map to get the default values for some missing keys

absolutejam13:12:09

thanks for your help

martinklepsch13:12:47

Does somebody understand why this returns a path with two ../../ segments?

(let [->path #(Paths/get % (make-array String 0))
      s1 "/d/metosin/reitit/0.2.10-alpha1/doc/http/pedestal"
      s2 "/d/metosin/reitit/0.2.10-alpha1/doc/basics/route-syntax"]
  (.relativize (->path s1) (->path s2)))
#object[sun.nio.fs.UnixPath 0x3bbb24a4 "../../basics/route-syntax"]

martinklepsch13:12:35

Shouldn't this be just ../basics/route-syntax?

rakyi14:12:19

hmm, I’m not sure about the exact semantics, but seems to be consistent with the docs here https://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html#relativize(java.nio.file.Path)

borkdude17:12:04

in this repo https://github.com/Raynes/lein-findfn it’s written: > Distributed under the Eclipse Public License, the same as Clojure. But Clojure is not distributed under EPL, but Apache?

borkdude17:12:24

I realize the author is not with us anymore, that is besides the point.

borkdude17:12:29

What’s the preferred license in the Clojure community? Same as Clojure? I chose MIT for some projects, but I’m not really an expert on these things

dpsutton17:12:44

>>> * Clojure * Copyright (c) Rich Hickey. All rights reserved. * The use and distribution terms for this software are covered by the * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) * which can be found in the file epl-v10.html at the root of this distribution. * By using this software in any fashion, you are agreeing to be bound by * the terms of this license. * You must not remove this notice, or any other, from this software.

borkdude17:12:17

oh right, I scrolled down too far. that Apache is about a dependency

Alex Miller (Clojure team)17:12:37

Clojure and contribs (and many open source Clojure projects) use EPL, but Apache is common as well

Aleksandr Furmanov18:12:51

Is it possible to extend protocol for object?

Aleksandr Furmanov18:12:10

(defprotocol Taggable
  (tags [x] "returns list of tags"))


(def config {:option-1 "One"
             :option-2 "Two"})

(extend-type clojure.lang.PersistentArrayMap
  Taggable
  (tags [me] {:tag (get me :option-1 "None")}))


(defn print-tags [taggable]
  (prn {:tags (tags taggable)}))


(defn taggable-config [config]
 (reify  Taggable
   (tags [_] {:tag (get config :option-2 "None")})))


(def adorned-config (taggable-config config))


;; config behaves as both Map and Taggable
(print-tags config)
(prn (keys config))

;; adorned-config behaves only as Taggable
(print-tags adorned-config)
(prn (keys adorned-config))

Aleksandr Furmanov18:12:34

What I want to achieve is something like:

(extend-object config
  Taggable
  (tags [me] {:tag (get me :option-1 "None")}))

Aleksandr Furmanov18:12:06

So only specific object would have implementation of certain protocols?

Alex Miller (Clojure team)18:12:38

in Clojure 1.10, for protocols that explicitly allow it, you can supply a protocol implementation as metadata on a particular object - is that what you’re looking for?

Aleksandr Furmanov18:12:38

Thanks! I’ll give it a try. The project I am working on is still on 1.9 tough…

Alex Miller (Clojure team)18:12:43

you would need to set :extend-via-metadata true on the Taggable protocol

Alex Miller (Clojure team)18:12:00

then adorn your config object with metadata that has the impl

Alex Miller (Clojure team)18:12:58

(def adorned-config (with-meta config {`tags (fn [me] {:tag (get me :option-1 "None")})}))

mrg18:12:40

I'm in need of a macro wizard!

mrg18:12:00

I'm trying to make something that would make a test like this pass: (is (= {a 23 } (let [b 23] (mymacro [a b]))

borkdude18:12:42

@mrg

(defmacro ->map
    "(->map a b) ;;=> {:a a :b b}"
    [& symbols]
    (assert (every? symbol? symbols))
    `(hash-map
      ~@(interleave (map keyword symbols) symbols)))

mrg18:12:45

So I've been trying to selectively unquote parts of this binding vector, or to look them up in &env, but I can't get either to work

p4ulcristian18:12:03

Hello guys, I am working on a reservation system with mongoDB. I use monger for handling it from clojure. Unfortunately arrayFilters doesn't work, is this a problem on my side, or monger doesn't work? https://github.com/michaelklishin/monger/issues/181

seancorfield18:12:40

I've offered a possible solution in that GitHub issue. I haven't actually used Monger so that's just my reading of the source code.

mrg18:12:29

@borkdude it's the partial lookup that kills me

borkdude18:12:32

hmm sorry, that’s not really what you wanted

borkdude18:12:37

@mrg is this macro specific for writing tests? maybe you can use are?

borkdude18:12:20

I’m not sure what your macro is supposed to do. name a value and return a map of names and values?

mrg18:12:51

no, it's not for tests

mrg18:12:01

It's a little complicated 🙂

mrg18:12:28

I'm generating wisp (basically clojure-flavoured javascript) on the server

mrg18:12:44

which works well by itself, but i can't pass values in

mrg18:12:59

so i want to provide a mapping

mrg18:12:59

e.g. (wisp-compile [x 5] (+ 37 x) would result in "37 + 5;"

mrg18:12:36

otherwise i can only do (wisp-compile (+ 37 x)) which results in 37 + x (that part works already)

borkdude19:12:53

so you want let?

mrg19:12:15

well.. partially?

mrg19:12:14

I think I need to lookup symbols in &env, but I can't get it to work

borkdude19:12:44

@mrg

(defn compile-+ [& args]
  (str/join " + " args))

(defmacro eval* [body env]
  (let [evaled (mapv #(or (get env %) %) body)]
    `(compile-+ ~@(rest evaled))))

(defmacro wisp-compile [bindings body]
  `(let ~bindings
     (eval* ~body ~&env)))

(wisp-compile [x 5] (+ 37 x)) ;;=> "37 + 5"

mrg19:12:38

it's specifically the local bindings; i can't eval those

dominicm19:12:20

@mrg I'm assuming that you have a function somewhere which takes something like '(+ x 37) and returns "x + 37". What you need here is a macro which will walk over the code it is given and if the key is in &env, it should be set to x, otherwise 'x? You will run into difficulty if you want to support nested macros in certain cases, but overall you might be okay.

Jacob Haag19:12:27

Let's say I have a parent hiccup form that references a child hiccup form, how would I evaluate the nested hiccup form?

(defn child []
  [:p "hello world"])

(defn parent []
  [:div 
   [child]])

; [:div [#function[slm.components.input/child]]] --> what I get when I evaluate `parent`
; [:div [:p "hello world"]] --> desired outcome of evaluating `parent`

dominicm19:12:03

@mrg I think your best bet here is core.unify, having played with it some in the REPL.

dominicm19:12:36

Trying to auto-detect which variables are available based on &env is tricky, because it excludes all the def and require in the namespace.

mrg20:12:49

do you have a code snippet for me @dominicm?

mrg20:12:27

@jacobhaag17 call child like the function that it is

mrg20:12:45

that's a difference between reagent-flavoured hiccup and standard hiccup

Jacob Haag20:12:12

That's what I was thinking, however I am concerned with deeply nested hiccup forms and child hiccup forms that require arguments.

(defn child [value]
  [:p value])

(defn parent []
  [:div
   [child "hello world"]])

((first (second (parent))) (second (second (parent)))) ; doesn't seem like a very good solution
;; [:p "hello world"]

mrg21:12:53

why would you need to do that?

mrg21:12:16

this should be no problem?

mrg21:12:39

sigh see main thread. Stupid slack doesn't seem to allow code snippets in threads

pasi23:12:55

hm I just deployed my (Luminus-based, but I suspect this is not important here) server app and it's worked fine locally but now that I'm running a production build, I see java.lang.NoClassDefFoundError: Could not initialize class org.apache.batik.bridge.DefaultFontFamilyResolver. I suspect this is classpath-related (I haven't really dealt with JVM in aaages). I'm using lein uberjarto build this.. do I need to somehow tell lein about batik?

pasi23:12:28

I'm not using batik myself, it's a dependency of Dali