Fork me on GitHub
#beginners
<
2015-07-21
>
surreal.analysis00:07:26

This could more generally be, if I want a function to return multiple vectors, what’s the best way to do that?

surreal.analysis00:07:12

The right way appears to be just wrapping everything in a list

surreal.analysis00:07:17

clj-pdf will render all elements of the list

agile_geek05:07:45

Can anyone explain the difference between structs and records to me please?

grounded_sage10:07:56

How do I make a a target directory for exporting pages in the stasis library?

grounded_sage10:07:13

Dw got it working lol

surreal.analysis11:07:36

@agile_geek: It’s my understanding structs are obsolete

surreal.analysis12:07:13

And also http://clojure.org/datatypes, which in addition to outlining the differences says "Overall, records will be better than structmaps for all information-bearing purposes"

surreal.analysis12:07:57

Hmm, still running into the issues from earlier. If I have a list of things, say, (“item 1” “item 2” “item 3”), and I want them to appear as:

[item 1]
[item 2]
[item 3]
What’s the best way to do such a thing? Do I need a macro?

surreal.analysis12:07:30

Or is there a way with apply I just haven’t figured out yet

surreal.analysis12:07:45

@yogthos If you have any suggestions on how to do such a thing, I’d appreciate it. A concrete example of what I’d like, given that items refers to a vector of

[“Item 1” “Item 2” “Item 3”]
, what’s the best way to transform that to
[:list
  [:chunk “Item 1"]
  [:chunk “Item 2”]
  [:chunk “Item 3”]
]
Currently trying with this:
(let [items ["item 1" "Item 2" "item 3"]]
            [:list
             (for [item items]
               [:chunk item])
             ]
            )
which fails due to a ClassCastException

surreal.analysis12:07:24

This is all in clj-pdf

akiva12:07:28

[:list (vec (mapcat #(apply vector [:chunk %1]) x))] should do it.

surreal.analysis12:07:01

Thanks @akiva! That did it

james14:07:24

@surreal.analysis: I think akiva’s solution might flatten the three [:chunk “Item <n>”] vectors into a single vector. If you want the output to be exactly as you requested you could try this approach: (into [:list] (map (juxt (constantly :chunk) identity) x))

surreal.analysis14:07:24

Ah, you’re right @james - Not sure why that was considered valid

surreal.analysis14:07:29

Thanks for the clarification

james14:07:41

@surreal.analysis: Your approach with the for macro also works: (into [:list] (for [item items] [:chunk item]))

surreal.analysis14:07:08

Oh, that’s my favorite so far

agile_geek16:07:49

@surreal.analysis: I suspected as much but I just wasn’t sure. Thanks.

arathunku17:07:24

Hi, How do I decipher following error?

[server] lein figwheel                                                                                                                                                                                                                                                                  
Figwheel: Starting server at 
clojure.lang.ArityException: Wrong number of args (2) passed to: reader/read
        at clojure.lang.AFn.throwArity(AFn.java:429)
        at clojure.lang.AFn.invoke(AFn.java:36)
        at cljs.analyzer$forms_seq_STAR_$forms_seq___2093$fn__2094$fn__2095.invoke(analyzer.cljc:2040)
        at cljs.analyzer$forms_seq_STAR_$forms_seq___2093$fn__2094.invoke(analyzer.cljc:2034)
        at clojure.lang.LazySeq.sval(LazySeq.java:40)
        at clojure.lang.LazySeq.seq(LazySeq.java:49)
        at clojure.lang.RT.seq(RT.java:507)
        at clojure.core$seq__4128.invoke(core.clj:137)
        at cljs.analyzer$parse_ns$fn__2109.invoke(analyzer.cljc:2111)
        at cljs.analyzer$parse_ns.invoke(analyzer.cljc:2094)
        at cljs.analyzer$parse_ns.invoke(analyzer.cljc:2085)
        at cljs.analyzer$analyze_file.invoke(analyzer.cljc:2212)
        at cljs.compiler$with_core_cljs.invoke(compiler.cljc:967)
        at figwheel_sidecar.repl$analyze_core_cljs$fn__18151.invoke(repl.clj:263)
        at figwheel_sidecar.repl$analyze_core_cljs.invoke(repl.clj:261)
        at figwheel_sidecar.repl$run_autobuilder_helper.invoke(repl.clj:298)
        at figwheel_sidecar.repl$start_autobuild.invoke(repl.clj:376)
        at figwheel_sidecar.repl$run_autobuilder.invoke(repl.clj:535)
        at user$eval18255.invoke(form-init3831675151583155220.clj:1)

surreal.analysis18:07:05

@arathunku: Not sure the right way to go about it, but I see that error when I have a # symbol out of place

surreal.analysis18:07:15

Specifically, if I’m moving s-expressions around

surreal.analysis18:07:21

And I end up with an anonymous function like

surreal.analysis18:07:29

# (do-something %)

surreal.analysis18:07:38

So it might be a dependency conflict with your ~/.lein/profiles.clj

arathunku18:07:38

Hmm... I'm not using anything like that 😕

surreal.analysis18:07:49

Are you using cider-nrepl?

surreal.analysis18:07:40

What does your project.clj look like?

dnolen18:07:53

@arathunku: oh right, that error is a clashing dependency issue, possibly someone else trying to bring in a stale version of tools.reader

dnolen18:07:23

@arathunku: ClojureScript relies on a specific version of tools.reader some other dep might be clobbering that

surreal.analysis18:07:45

Though I do not see any clash when I do lein deps :tree, what does your ~/.lein/profiles.clj look like?

arathunku18:07:53

@dnolen: is there any place where I should report such stuff? Because if it wasn't for git diff, I'd have never guessed that from the error message

dnolen18:07:27

@arathunku: not really since this is just typical dep management hijinks

dnolen18:07:35

that said you have a lot of expressed dependencies

dnolen18:07:59

I’m generally conservative about deps to avoid stuff like this

Lambda/Sierra18:07:32

@arathunku: That's a conflict caused by the wrong version of Clojure in your dependencies somewhere, I think. read accepting 2 arguments was added in Clojure 1.7.

surreal.analysis18:07:38

Ah, okay, I didn’t see you were on a feature branch. Running lein deps :tree prints out a huge tree, which includes:

[jarohen/chord "0.6.0"] -> [org.clojure/tools.reader "0.8.3"]
 overrides
[lein-figwheel "0.3.5"] -> [figwheel-sidecar "0.3.5"] -> [com.cemerick/piggieback "0.1.5"] -> [org.clojure/clojurescript "0.0-2665"] -> [org.clojure/tools.reader "0.8.10”]

surreal.analysis18:07:51

I know it’s not the simplest solution, but that gives you a place to start if you run into weird errors that might be dependency management again

arathunku18:07:07

That might be the case, but still, shouldn't lein take care of that and inform me about the problem? I'd like open an issue about that somewhere and avoid poking around next time something like that happens. For the same error message I've received 3 completely different suggestions what should I check, clearly something is wrong.

Lambda/Sierra18:07:21

That's why we call it dependency hell. No one has solved it yet in the history of programming. simple_smile

arathunku18:07:10

I've never experienced such problem with bundler(ruby) because the output is very clear about the problem and highlights gems with their deps and conflicts.

dnolen19:07:24

@arathunku: I don’t know what bundler you used but it’s not the bundler I used at NYTimes for 3 years

roberto19:07:49

hah! I always have issues with ruby. I’m boycotting it from my machine.

dnolen19:07:53

I wasted mutiple days on bundler time and time again

roberto19:07:14

I’m traumatized by vagrant because of ruby.

Lambda/Sierra19:07:45

Since this discussion is in #C053AK3F9, I expect @arathunku is experiencing the typical difference between a tool/environment you have a lot of experience with — where most problems are "easy" — and an environment that is totally unfamiliar.

arathunku19:07:41

@dnolen: newest, for last 2y. I've fighted with bundler a lot too just not with conflicting versions of gems.

dnolen19:07:05

@arathunku: I fought everything from conflicting gems to native gems

roberto19:07:18

I word: nokogiri

arathunku19:07:45

@stuartsierra: for me it's more about completely useless error message.

dnolen19:07:53

anyways I wish I could say Clojure solved this problem, it did not

dnolen19:07:04

rather I learned my lesson, I don’t take on a dep w/o auditing it

roberto19:07:11

having said that, yeah, I’ve run into weird deps issues with clojure, but maybe because of my java background, I kind more or less diagnose the issue

roberto19:07:25

lein deps :tree is my friend simple_smile

hq120:07:37

can someone please help me understand the exception (#(%1) 1) throws? I'd expect it to be an equivalent of 'identity' function, but am getting ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn

Lambda/Sierra20:07:30

@hq1 Very common #C053AK3F9 mistake simple_smile

Lambda/Sierra20:07:47

#(%) is not the same as (fn [x] x)

hq120:07:06

well I can see it's not, trying to understand why

Lambda/Sierra20:07:09

Rather, #(%) expands to (fn [x] (x)).

hq120:07:58

thank you

Lambda/Sierra20:07:08

you're welcome!

hq120:07:55

@stuartsierra: how can I expand that macro to actually see it?

Lambda/Sierra20:07:30

@hq1: It's a reader macro, so something like (read-string "#(%1)")

hq120:07:58

nice, thanks