Fork me on GitHub
#beginners
<
2016-04-18
>
dmi3y12:04:46

Is there a way to add java doc to methods of a class generated with :gen-class?

alexmiller16:04:31

I don't think so

alexmiller16:04:56

if you're asking that question, you're likely to be better off creating a Java interface and implementing it in Clojure instead

alexmiller16:04:39

Clojure functions, records, and protocols will generate Java interfaces that take and return Object for all args which most Java users find disconcerting :)

dharrigan19:04:41

Hi all. Very new to Clojure. Say I have a list of symbols (names if you will) and I want to derive a list with certain symbols removed, I'm sort of struggling to understand how to do that in Clojure. In Java 8, for example, I would simply do something like this:

nonrecursive19:04:18

(remove #{'a 'b} '(a b c)) maybe?

dharrigan19:04:19

Anyone share any insights on how to do this using Clojure?

dharrigan19:04:44

what if I don't know in advance what the collection of names contains?

dharrigan19:04:55

but I know that I want to remove certain things that it may contain

nonrecursive19:04:02

that returns ’(c)

nonrecursive19:04:50

(remove #{’name-to-remove} names) maybe? where names is a sequence?

dharrigan19:04:11

REPLing.... simple_smile

nonrecursive19:04:57

#{} is a set literal, so (remove #{’set ‘of ’things} x) returns a new sequence where anything in the set is removed

dharrigan19:04:30

what does the ' mean in front of the bar and in front of the sequence of foo bar baz?

nonrecursive19:04:29

the does “quoting”, which means “treat this as data, don’t evaluate it”. otherwise Clojure would try to call the foo function on arguments bar and baz

dharrigan19:04:00

I see I see.

nonrecursive19:04:04

with quoting, you get a list containing the symbols foo etc

dharrigan19:04:22

so the '() means that everything contained within this list are literals?

nonrecursive19:04:32

instead of clojure trying to evaluate the function that foo evaluates too, and applying that to the value that bar evaluates to

bojan.matic19:04:17

@dharrigan: might i suggest reading clojure for the brave and true? it’s free to read online

dharrigan19:04:24

Would it not be the case that if foo, bar and baz are not found as a function or macro, that clojure would then think it's a symbol and treat as such?

bojan.matic19:04:39

it does a good job of introducing clojure

jeffh-fp19:04:49

I’m looking to iterate over a number (e.g. 1 to 5) and create a vector of maps (using the number as part of the input). (brave clojure chapter 3 ex. 6) — seems like I should be using reduce but I can’t figure out how

dharrigan19:04:57

bojan.matic: thank you. I have it - but to be honest, I find it a bit "brogrammy" with tales that I find distracting from getting to the gist of the code.

jeffh-fp19:04:58

suggestions to point me in the right direction?

bojan.matic19:04:21

if i’m not mistaken, quoting really only means “don’t evaluate this list as a function call, and don’t try to resolve symbols within it”

dharrigan19:04:11

thank you nonrecursive and bojan.matic simple_smile

nonrecursive19:04:07

@dharrigan: if you can make it past all stuff you don’t like, http://www.braveclojure.com/read-and-eval is meant to give a solid understanding of how clojure evaluation works

jeffh-fp19:04:45

FWIW I like the silly stuff @nonrecursive 😉

nonrecursive19:04:37

tx 😄 I know it’s not for everyone, no big deal

jeffh-fp20:04:19

my question was missed a little while back: I’m looking to iterate over a number (e.g. 1 to 5) and create a vector of maps (using the number as part of the input). (brave clojure chapter 3 ex. 6) — seems like I should be using reduce but I can’t figure out how. Any pointers in the right direction?

jeffh-fp20:04:56

(take 5 (map inc (iterate inc 1))) <— maybe I could apply something like this ?

bojan.matic20:04:41

what do you want to be the output, given an input of [1 2 3 4 5]

jeffh-fp20:04:30

a vector of maps… like [{:a 1} {:b 2}]

bojan.matic20:04:47

where do the :a and :b come from?

dharrigan20:04:35

shamelessly copied and adapted: (map vector [:a 😛 :c :d :e] (take 5 (map inc (iterate inc 0))))

dharrigan20:04:04

(map vector [:a :b :c :d :e] (take 5 (map inc (iterate inc 0))))

jeffh-fp20:04:40

that’s a good lead, thanks I’ll poke around with that

jeffh-fp20:04:53

sorry Bojan it’s hard to explain simple_smile

dharrigan20:04:58

I would strongly suspect that the (take 5...) can be done easier!

dharrigan20:04:01

(map vector [:a :b :c :d :e] (range 1 5))

dharrigan20:04:27

hint: don't type (range) and eval into REPL simple_smile 0...to infinity and beyond!

dharrigan20:04:37

watch those CPUs burn simple_smile

akiva20:04:24

Look into zipmap: (zipmap [:a :b :c :d :e] [1 2 3 4 5])

bwstearns21:04:05

@jeffh-fp: I’m with Bojan in asking about where the keys are coming from but from the sound of it you might want to look at reduce-kv misread about the input data

surreal.analysis22:04:38

If the keys are just :a, :b, :c, etc. , something like

(map (comp keyword str char) (range 97 (+ 97 vector-size)))
can generate the array of keywords

jswart23:04:18

@jeffh-fp: I wrote this awhile back to explain how to reduce more complicated things http://jcswart.github.io/2014/01/25/clojure-like-im-five-reduce-functions/