Fork me on GitHub
#clojure
<
2016-06-10
>
stijn10:06:14

is this the way to create a namespaced keyword from a string with the namespace being the one of the source file the keyword is being created in? (keyword (str *ns*) "aka")

stijn10:06:56

apparently not 🙂 it uses the namespace the fn is called from

rauh10:06:27

Why not ::aka?

stijn11:06:55

it's a map of String keys that I want to convert to namespaced keywords

xtreak12:06:11

Hence a new Object with a different implementation of toString is returned. Since str is called which in turn calls the toString on that method a new value is returned. Am I right on this?

berrysoup12:06:01

Hi is it possible to build in boot clj, in easy way, a whole package with jar+log.xml file and a few bash scripts?

mateus.henrique.brum13:06:09

some question, what is the difference of ::something and :something ?

mateus.henrique.brum13:06:31

If both are equals, when I use each idiomatic expression ?

mpenet13:06:31

one is namespaced the other isn't

mateus.henrique.brum13:06:57

I didn't got it 😕

mpenet13:06:10

:something is always equal to :something no matter the namespace where you compare them

Lambda/Sierra13:06:20

::something reads as :the.current.namespace/something

mpenet13:06:26

well the second should read ::something, instead of clojure.core/something but yeah

mateus.henrique.brum13:06:26

@stuartsierra I am your fan man ... nice work ... 🙂

yogidevbear15:06:37

Is there an easy way to do exponents using core Clojure functionality?

carocad15:06:28

hey guys, quick question: Are there any guidelines for when to return lazy seq as opposed to eager ones? I am creating a lib, and I can't decide whether lazy or not lazy. The problem is that if I make it lazy, the results are not properly ordered which is not so nice as a return value. But being lazy gives it a speed boost as not everything has to be computed

carocad15:06:21

@yogidevbear: (Math/pow 2 3) ;; => 8

Lambda/Sierra18:06:16

@carocad: In general, if there is an advantage to the user in having a lazy sequence, then that is what you should return.

Lambda/Sierra18:06:30

But it is important to remember that lazy sequences are not always 100% lazy. For example, functions like map have optimizations which may cause them to realize more values than the consumer used.

Lambda/Sierra18:06:42

If you truly want to leave the user in control of how many values get produced, then you probably want a pull-oriented API in which the user has to ask for the next value. It is trivial to build a lazy sequence on top of that.

genmeblog20:06:43

Hi all, I have a question around multimethods

genmeblog20:06:51

I'm trying to wrap creation of various randomization algorithms (using apache math classes) into multimethod

genmeblog20:06:07

I came up with following solution

genmeblog20:06:25

code works but I have to issues:

genmeblog20:06:25

how to avoid use of map as a function parameter or in other words: how to force multi-arity in defmethod?

genmeblog20:06:02

and second: how to avoid code repetition (if-let...)

hiredman21:06:07

the part after the dispatch value in a defmethod can be anything that goes after the (fn ... for a function

hiredman21:06:27

like (fn ([a] ...) ([a b] ...) ...)

hiredman21:06:51

almost never taken advantage of

genmeblog21:06:33

ok... let's check

hiredman21:06:44

your dispatch function will also need to be multi-arity

hiredman21:06:04

and watch out for defmulti's defonce semantics if you are playing at the repl

genmeblog21:06:35

yes, yes, I've just fallen into this trap

aengelberg21:06:41

or you could (defmulti make-randomizer (fn [m & args] (:algorithm m))) which allows all defmethods to define whatever arities they want

genmeblog21:06:15

I want to call (make-randomizer :mersenne) or (make-randomizer :mersenne 1111)

genmeblog21:06:57

aengelberg method works!

genmeblog21:06:55

and what about second issue? how to create java object by passing class name?

aengelberg21:06:44

sorry didn't see that question

genmeblog21:06:58

"and second: how to avoid code repetition (if-let...)"

genmeblog21:06:13

but I've just came out how to make it with macro

gfredericks21:06:50

tsulej: yeah a macro is the only way to factor out that part without reflection

genmeblog21:06:53

thanks for support, everything works, final code looks like this

genmeblog21:06:24

if you see something to optimize more, leave me a note

gfredericks21:06:24

you don't need the indirection of having the macro create a function

gfredericks21:06:16

(defmacro multiarity-new [cl arg] (let [arg# arg] (if arg# (new cl arg#) (new ~cl))))

gfredericks21:06:19

(defmacro multiarity-new [cl arg] (let [arg# arg] (if arg# (new cl arg#) (new ~cl))))`

genmeblog21:06:16

is macro expanded during execution (line 16) or during compilation?

genmeblog21:06:39

ah, got it, thx

genmeblog21:06:45

it's simpler

magnus22:06:10

I have two simple macros. I’m trying to add metadata to a function var. The first one doesn’t work, while the second does. Anyone knows why?

gfredericks22:06:12

magnus: I don't have time to explain, but using ~(vary-meta x assoc :a :b) should work

magnus22:06:30

that worked! I’ll read up on vary-meta

gfredericks22:06:15

general macro stuff is highly relevant

aengelberg22:06:12

@magnus using a backquote expands to clojure code that appends unquoted expressions into the desired location. Using a regular quote and THEN a backquote lets you inspect what it's doing behind the scenes.

user> ' ` ^:a a
(clojure.core/with-meta (quote user/a) (clojure.core/apply clojure.core/hash-map (clojure.core/seq (clojure.core/concat (clojure.core/list :a) (clojure.core/list (quote true))))))
user> ' ` ^:a ~(symbol 'a)
(symbol (quote a))