Fork me on GitHub
#clojure
<
2018-05-08
>
dcj02:05:57

I am attempting to use the function clojure.data.xml/element* but the Clojure repl gives

No such var: clojure.data.xml/element*
I'm using Clojure 1.9.0, Leiningen 2.8.1, Java 9.0.1 on macOS. Any ideas?

noisesmith03:05:53

@dcj how did you pull in the clojure.data.xml namespace?

dcj03:05:34

@noisesmith Other functions in the namespace work fine. My ns require looks like this: [clojure.data.xml :as data.xml] and calling it as data.xml/ or clojure.data.xml/ produces the same result/error

dcj03:05:51

@noisesmith I created a new namespace in my project so I could minimize the amount of other libs pulled in to isolate...no difference

dcj03:05:22

@noisesmith I have an appointment now, back in 2.5 hours...

noisesmith03:05:49

what makes you think element* exists in that ns?

noisesmith03:05:13

OK - there's something fishy going on with "export-api", and that comes from the clojure.data.xml.node ns

noisesmith03:05:57

looks like some kind of re-export macro that might be broken

dcj03:05:23

The api docs describe element*

noisesmith03:05:47

yes, I see that

noisesmith03:05:16

and I also can't access it, the re-export mechanism seems to be broken

dcj03:05:01

Thanks for confirming

dnaeon08:05:28

Is there any way I could make this tail-recursive and not overflow the stack?

dnaeon08:05:38

I've also looked into clojure.zip, but not really sure if that would help me with it.

Empperi08:05:19

hmm, I must be missing something obvious, I can't fathom a way to use :keys map destructuring when my keys are actually namespaced keywords

Empperi08:05:59

am I really forced to use the more traditional {foo :bar/foo, lol :bar/lol} destructuring?

Empperi08:05:42

makes my code extremely verbose since I'm mostly destructuring values from my data model which have descriptive names for what they are representing

Empperi08:05:45

it would simplify things if I could just do something like :keys #bar[foo lol]

Empperi08:05:02

if this is impossible this is actually a pretty major drawback for using namespaced keywords everywhere

Empperi08:05:56

as it is now, most of the code in my functions consist of characters repeating these keywords...

schmee08:05:18

@niklas.collin the syntax is {:person/keys [first last email]}

Empperi08:05:58

right, nice thanks

Empperi08:05:24

and apparently if I have several namespaces then I just need to use the :keys [foo/bar] syntax documented there

Empperi08:05:40

which isn't much better than the normal way of doing things

andy.fingerhut09:05:21

I believe you can do :ns1/keys [a b c] :ns2/keys [d e f] if that helps

Empperi11:05:17

ah cool, that helps in some places although not in all

idiomancy17:05:21

anyone know how to work with metadata maps in macros? I want to make a macro that attaches metadata to a hiccup vector, but I don't really understand metadata tags... so, like

(defmacro keyed [key component]
  ???????)

(keyed (:name vehicle) [vehicle-component vehicle])
would ideally compile as ^{:key (:name vehicle)} [vehicle-component vehicle]

idiomancy17:05:50

but I don't really know what that pairing of tag and value should look like in macro form...

gdanov17:05:43

try something like

`(with-meta :key ~key ~component)

idiomancy17:05:32

Yeah, I guess I can always do it without using the special forms. That's probably a good idea.

gdanov17:05:22

that's the macro code. natural question is why do you need the macro when there is

with-meta

noisesmith17:05:44

yeah, reader macros are tricky inside macros, as they almost never expand at the time you want

noisesmith17:05:24

and returning a reader macro from a macro doesn't work, ever

gdanov17:05:59

can you elaborate? I'm not sure I understand what's reader macro in thin context

noisesmith17:05:10

^ is a reader macro

gdanov17:05:40

ah, I interpreted that as target value, not target form

noisesmith17:05:11

when the reader consumes ^foo bar, it creates (with-meta bar {:foo true}), but that doesn't apply to the form returned from the macro, it applies to the macro code itself, which is pretty much never useful

noisesmith17:05:11

sometimes ^ inside the form returned by the macro will do the right thing, but it's relatively unflexible and a lot harder to reason about, compared to just emitting a call to with-meta directly

gdanov17:05:51

hah, I can't even figure out how to sneak ^ inside the macro result code

idiomancy17:05:30

hahaha, yes @gdanov I agree, the specific example I used here would be pointless to abstract into a macro

noisesmith17:05:54

(since reading always happens before expansion)

idiomancy17:05:01

okay, gotcha @noisesmith. that makes sense

lsund18:05:40

Hi guys I'm asking for a clojure book. I have solid experience with functional programming although not with clojure or any lisps for that matter. Looking to dive deeper into the core ideas of the language, the philosophy and best practices in everyday projects. Any ideas where to start?

manutter5118:05:56

I think the 2nd Ed. of The Joy of Clojure is more the philosophy and stuff you might be looking for, but not sure how hard it would be if you have little or no lisp background

manutter5118:05:58

Clojure for the Brave and True is an intro to Clojure that might be of interest: https://www.braveclojure.com/

theeternalpulse00:05:07

I have both these books and braveclojure is a great intro, and joy of clojure is a great next step. I would say if you're not interested in some details to skim over (but not totally) the first few chapters of The Joy of Clojure. It gets into useful info later.

lsund18:05:59

Thanks for the suggestion, I got the basic ideas but I'm not convinced (yet) coming from a haskell like background I'm looking to be convinced

sundarj18:05:30

you might also try Programming Clojure and Clojure Applied

☝️ 4
👍 8
yogidevbear18:05:05

I recently bought the 3rd edition of programming Clojure and was think of getting Clojure Applied after that