This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-25
Channels
- # announcements (1)
- # beginners (131)
- # cljs-dev (1)
- # clojure (178)
- # clojure-argentina (1)
- # clojure-dev (3)
- # clojure-uk (2)
- # clojuredesign-podcast (1)
- # clojurescript (16)
- # code-reviews (2)
- # core-async (2)
- # emacs (28)
- # figwheel-main (19)
- # fulcro (11)
- # kaocha (1)
- # leiningen (4)
- # music (6)
- # off-topic (2)
- # re-frame (2)
- # reitit (6)
- # rewrite-clj (9)
- # shadow-cljs (78)
- # slack-help (6)
couldn't get a functioning repl on emacs or cursive if vim doesn't work i'm making a linux partition.
Hello, I am trying to define a function inside a macro. I googled for a while but can't seem to search for the right thing. I tried:
(defmacro defattrs
[]
`(defn my-function [] nil))
but I get the error:
failed: simple-symbol? at: [:fn-name] spec: :clojure.core.specs.alpha/defn-args
Maybe someone could help me out? Would be highly appreciated šTry doing a macroexpand on your macro and seeing what it expands to. Away from computer at the moment but something like (macroexpand-1 '(defattrs)) Expansion is my first port of call with macro errors - is the macro really expanding to the code I think it is expanding to. I think here that my-function has probably become namespace qualified - some.ns/my-function which means it's no longer a simple symbol.
Thank you I'll try using macroexpand
Hi everyone. I'm having a great time with spec, I'm using expound to format spec errors, and I'm using cursive for development. Following expound's docs I have (set! s/*explain-out* expound/printer)
but cursive is giving me a "cannot be resolved" warning on s/*explain-out*
. I have required [clojure.spec.alpha :as s]
Is there actually anything wrong, or should I just ignore the warning? Generally I like to fully understand why I'm getting warnings before ignoring them, so any explanation of why this might be happening would be gratefully received
So I'm still working on this XML -> EDN mini project interstitial bridge and i'm wondering, what is this https://github.com/thebusby/into-edn into-edn library doing at the end that cannot be done with plain vanilla zipper and xml?
In CLJS, how can we emulate create a state variable in react? I tried to use reagent/atom and js-obj, but I was unsuccessful.
How did you use reagent/atom?
I followed this example
But my issue I define my component in did-mount, but the component never gets the new props in component-did-update.
Maybe I will retry to use useState from 16.8
Oh are you trying to use hooks? Reagent doesn't work very well with hooks, as it has its own way of handling state
The basic reagent way for local state would be to use a form 2 component - declare a reagent atom and return a render function
(defn counter [] (let [n (r/atom 0) (fn [] [:span {:on-click #(swap! n inc)} @n])))
The example you posted is specifically about interop with js components that may have their own non react state
If you've got more hooks experience you could try the library hx
xml is melting my brain
hope you're all having a sunshiney day š
@danieleneal Thanks for the tip, however I am trying to interop with a JS react component that mutates its internal states to communicate changes to its children
I am trying to reimplement this component with CLJS
https://github.com/plotly/react-chart-editor/blob/master/examples/simple/src/App.js
how can i turn the big clojure data structure i got from an xml file into a neat clojure map?
"neat" = ?
#clojure.data.xml.Element{:tag :entry, :attrs {}, :content (#clojure.data.xml.Element{:tag :ent_seq, :attrs {}, :content (1000000)} #clojure.data.xml.Element{:tag :r_ele, :attrs {}, :content (#clojure.data.xml.Element{:tag :reb, :attrs {}, :content (ć½)})} #clojure.data.xml.Element{:tag :sense, :attrs {}, :content (#clojure.data.xml.Element{:tag :pos, :attrs {}, :content (unclassified)} #clojure.data.xml.Element{:tag :gloss, :attrs {:g_type expl, :xml:lang eng}, :content (repetition mark in katakana)})})}
i want to end up with a vector of entries, each entry a map,
[{:ent_seq 100000
:reb ć½
:sense {:gloss "repetition mark in katakana"}]
some keys of entries might end up having vectors of maps (like in the case of multiple :glosses )
it's pretty much the most basic thing to do with an xml file in clojure, make it a clojure datastructure without the fluff, but i'm trying to think of how to do it efficiently because the file is kinda big for zipping and stepping... so i'm just working with a smaller file for the moment, like i don't want to do (doseq) with conditionals, but maybe that's the best way?
generically, it seems like you want to recursively convert Elements to some Clojure data
you could actually do it recursively, but you'd want to be somewhat careful not to end up holding too much in memory and blowing either the stack or the heap
another option might be to use clojure.walk/postwalk-replace
which again, might need to be a little careful
Right on. Well it's not a big deal because I only have to do this once really
Recursively probably OK
oh, well that's nothing
recursion is like learning to pop a bubble molecule by molecule
well you only need to learn how to do the first one :)
So i get something like
#clojure.data.xml.Element{:tag :JMdict, :attrs {}, :content (#clojure.data.xml.Element{:tag :entry, :attrs {}, :content (#clojure.data.xml.Element{:tag :ent_seq, :attrs {}, :content (1000000)} #clojure.data.xml.Element{:tag :r_ele, :attrs {}, :content (#clojure.data.xml.Element{:tag :reb, :attrs {}, :content (ć½)})} #clojure.data.xml.Element{:tag :sense, :attrs {}, :content (#clojure.data.xml.Element{:tag :pos, :attrs {}, :content (unclassified)} #clojure.data.xml.Element{:tag :gloss, :attrs {:g_type expl, :xml:lang eng}, :content (repetition mark in katakana)})})} #clojure.data.xml.Element{:tag :entry, :attrs {}, :content (#clojure.data.xml.Element{:tag :ent_seq, :attrs {}, :content (1000010)} #clojure.data.xml.Element{:tag :r_ele, :attrs {}, :content (#clojure.data.xml.Element{:tag :reb, :attrs {}, :content (ć¾)})} #clojure.data.xml.Element{:tag :sense, :attrs {}, :content (#clojure.data.xml.Element{:tag :pos, :attrs {}, :content (unclassified)} #clojure.data.xml.Element{...
I can invoke (first j-coll)
and (rest j-coll)
... but when I do (first j-coll)
I get a sequence of vectors
not sure what j-coll is but if its the data xml that's a record so you probably don't want to interact with it with first
and rest
right thank you
i don't know which spoon to use on this melon
I want to parse this xml japanese dictionary file called jmdict and create a vector of clojure maps for each entry
the tags are pretty simple <entry><ent_seq>###</ent_seq><k_ele><keb>~</keb></k_ele><sense>...</sense></entry>
but i'm having a hard time accessing the first content child because i'm not sure what to do to recurse over xml.Element
i think you essentially have that. you have a "map" with a key :content
which is a seq of nodes, each of which is a map. is pretty 1-1 with "vector of clojure maps for each entry"
I want to spit it out into clojure consumable data so that i can mess with it more for this web app
yeah, so aside from first
and rest
... should I check if the node is typeof xml.Element and then attempt to access content?
yeah i think so
#clojure.data.xml.Element{:tag :entry, :attrs {}, :content (#clojure.data.xml.Element{:tag :ent_seq, :attrs {}, :content (1000000)} #clojure.data.xml.Element{:tag :r_ele, :attrs {}, :content (#clojure.data.xml.Element{:tag :reb, :attrs {}, :content (ć½)})} #clojure.data.xml.Element{:tag :sense, :attrs {}, :content (#clojure.data.xml.Element{:tag :pos, :attrs {}, :content (unclassified)}
would this turn into?Something like
[{:entry {:ent_seq "100000"
:r_ele {:reb "ć½"}
:sense { :pos "unclassified" }}]
Let's do another one that's actually a word...
<entry>
<ent_seq>1000130</ent_seq>
<k_ele>
<keb>ļ¼®éæ</keb>
</k_ele>
<r_ele>
<reb>ćØćććć</reb>
</r_ele>
<sense>
<pos>&n;</pos>
<misc>&abbr;</misc>
<gloss>NHK Symphony Orchestra</gloss>
</sense>
</entry>
is the native XML
#clojure.data.xml.Element{:tag :entry, :attrs {}, :content (#clojure.data.xml.Element{:tag :ent_seq, :attrs {}, :content (1000130)} #clojure.data.xml.Element{:tag :k_ele, :attrs {}, :content (#clojure.data.xml.Element{:tag :keb, :attrs {}, :content (ļ¼®éæ)})} #clojure.data.xml.Element{:tag :r_ele, :attrs {}, :content (#clojure.data.xml.Element{:tag :reb, :attrs {}, :content (ćØćććć)})} #clojure.data.xml.Element{:tag :sense, :attrs {}, :content (#clojure.data.xml.Element{:tag :pos, :attrs {}, :content (noun (common) (futsuumeishi))} #clojure.data.xml.Element{:tag :misc, :attrs {}, :content (abbreviation)} #clojure.data.xml.Element{:tag :gloss, :attrs {:xml:lang eng}, :content (NHK Symphony Orchestra)})})}
desired:
[{:entry {:ent_seq "1000130"
:k_ele {:keb "ļ¼®éæ"}
:r_ele {:reb "ćØćććć"}
:sense { :pos "&n;"
:misc "&abbr;"
:gloss "NHK Symphony Orchestra"}}]
Anyway don't stress to much about it, i'll figure it out ^^
not to mention this file is full of landmines like &n;
i'm one of those people who abhors reading the manual
but when i finally sit down and do things end up being clearer
how would I set jdk.xml.entityExpansionLimit = 0 in :jvm-opts []?
Maybe something like ["-Djdk.xml.entityExpansionLimit=0"]
o.o Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded
now that i've increased the jvm available mem i think it 'll go now ^_^
Has anybody on windows encountered this error message? >lein deps java.io.IOException: Cannot run the program clojure in directory xyz. CreateProcess error=2 The system cannot find the file specified at java.lang.ProcessBuilder.start (ProcessBuilder.java:1128)
If no one here knows the answer, there is also a #leiningen channel where someone may
Hmmm... How to deftly manipulate a deftype?
@norilinoriginal Cannot find clojure? hmm that's a weird one...
It's accompanied by Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessImpl.create (ProcessImpl.java:-2)
I can connect to the REPL I create from ~, but then it can't find the classes I reference.
@norilinoriginal Try creating a shortcut link to your global clojure executable
and drop it into ~/_dev/overtone
i don't play on windows much with clojure ;x but maybe that can help
(defn recurse-over-jmdict [element]
(cond
(instance? clojure.data.xml.Element element)
(do
(println element)
(recurse-over-jmdict (:content element)))
; (string? element) (println "str: " element)
; (integer? element) (println "int: " element)
:else "heyx"))
;external entry point into bubble popping recursive function
(recurse-over-jmdict parsed-jmdict)`
How can I "step in to" a #clojure.data.xml.Element{:tag :JMdict, :attrs {}, :content (#clojure.data.xml.Element{.......})}
? I try accessing the :content of element with (:content element)
but this is apparently not the way to access the content field of data.xml.ElementDid you try asking in leiningen ? hopefully somebody can help. Did you install clojure via package manager of some kind?
i feel like i'm missing something very basic about deftypes
I asked in leinengen, yes. I did not install clojure via package manager, I installed it via clojure on windows. https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows
clojure.xml/parse doesn't put lots of #clojure.xml.data.Element{}s everywhere so I just switched to that
you may have to reinstall with admin privs
so it's a global executable,
that's just my guess with how windows is
If I want to test a function that creates a file, is the best approach to allow the test(s) to create files and use .deleteOnExit
for cleanup after the fact? It looks like thatās how
tests handle I/O unit tests?
I cannot think of a way to actually test the ability of code to create files, without actually letting it create a file.
One could imagine testing it inside of a container, or VM, etc. and then blowing away the entire container/VM after the test, but deleting a single file seems a lot quicker.
(or even deleting hundreds of files seems a lot quicker)
Thanks, Andy! Thatās essentially what Iāve concluded as well. Iām still trying to find a clean way to run a ādelete file after test completesā for this specific situation Iām in, but Iāll get there.
Thanks again. I ended up with the following (although it appears the catch
block is unnecessary):
(deftest generate-file-test
(testing "generate file"
(let [filename (create-file "hello-world")]
(is (re-matches #"resources\/files\/\d+-hello-world\.edn$" filename))
(try
(let [contents (slurp filename)]
(is (= contents "generated contents")))
(catch Exception e
(throw e))
(finally
(.delete (io/file filename)))))))
@zhuxun2 functions and macros don't possess any distinctive symbolic identifiers or attributes to my knowledge.
@norilinoriginal Thanks, so you are saying it's impossible to programmably tell them apart by design?
>>>macroexpand-1 function Usage: (macroexpand-1 form) If form represents a macro form, returns its expansion, else returns form. Added in Clojure version 1.0
>macroexpand function Usage: (macroexpand form) Repeatedly calls macroexpand-1 on form until it no longer represents a macro form, then returns it. Note neither macroexpand-1 nor macroexpand expand macros in subforms. Added in Clojure version 1.0
@zhuxun2 Those two functions appear to be able to programmatically identify macros when they're not inside subforms.
@zhuxun2 Something like this may work for you:
user=> (:macro (meta #'let))
true
user=> (:macro (meta #'str))
nil
That is for Clojure/Java, at least. It is probably different in ClojureScript, where macros are a bit different than Clojure/Java.
Is there a way for me to run some code before I open up my clojure repl (I mean the $ clojure
repl)
I added the new path to the PATH and tried >clj and I got Copy-Item : Cannot find path
'C:\Users\noril\Documents\WindowsPowerShell\Modules\ClojureTools\example-deps.edn'
because it does not exist.
At C:\Users\noril\Documents\WindowsPowerShell\Modules\ClojureTools\ClojureTools.psm
1:196 char:5
+ Copy-Item "$InstallDir\example-deps.edn" "$ConfigDir\deps.edn"
+
+ CategoryInfo : ObjectNotFound: (C:\Users\noril\...xample-deps.edn:S
tring) [Copy-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemC
ommand
@norilinoriginal maybe take this to #clj-on-windows -- the Powershell installer is basically pre-alpha and still be actively worked on. The folks in that channel will be more knowledgeable about what works and what doesn't, as well as asking the right questions to help you debug the problem.
(just bear in mind it is Sunday and the channel may be quiet today)
I got here via link from the clj on windows github page, idk where to find all the channels here though.
@norilinoriginal There's a #slack-help channel (which you should be auto-joined into?) where you can ask how to use/navigate Slack š