This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-02
Channels
- # aleph (3)
- # announcements (2)
- # babashka (4)
- # beginners (74)
- # calva (21)
- # clj-kondo (30)
- # cljs-dev (7)
- # cljsrn (42)
- # clojure (121)
- # clojure-dev (13)
- # clojure-europe (23)
- # clojure-losangeles (2)
- # clojure-nl (2)
- # clojure-norway (7)
- # clojure-spec (140)
- # clojure-uk (58)
- # clojuredesign-podcast (9)
- # clojurescript (49)
- # clojutre (2)
- # cursive (32)
- # datascript (2)
- # datomic (59)
- # duct (7)
- # figwheel-main (6)
- # fulcro (18)
- # graphql (5)
- # jackdaw (1)
- # joker (6)
- # juxt (7)
- # leiningen (9)
- # off-topic (1)
- # pedestal (14)
- # quil (2)
- # re-frame (3)
- # reitit (8)
- # shadow-cljs (78)
- # sql (8)
- # timbre (3)
- # vim (69)
I trying to get the values of a protocol definition from another namespace and there is no success.
@iha2 Not sure what you mean by "the values of a protocol definition" -- perhaps you can share (some of) your code in a Gist or Pastebin link?
(defrecord Nav [text link nav])
(def articles (map-indexed #(Nav. (->> % second :title) '(::article {:id (->> % first)}) nil)
(:articles @app-state)))
What's nav-tree
?
Also, since you are def
ing articles
, it will be assigned a value when that namespace loads and it will not change after that.
Basically I need to able to do this (:text value)
where value is the (Nav. "root" ::root nil)
in another namespace.
OK... So I'm not sure what you're asking... what are you having problems with?
I don't see any protocols in that code.
It would probably help you to use the auto-generated constructor function ->Nav
instead of trying to use the type constructor Nav.
When you require
the namespace that contains the defrecord
, it will give you access to ->Nav
and map->Nav
etc but in order to get at the type Nav
, you need to import
it, just like any other native types.
I suspect you're getting an error (you didn't say what error you're seeing) because you're not import
ing the record type?
Like this
user=> (ns first.one)
nil
first.one=> (defrecord Nav [text link nav])
first.one.Nav
first.one=> (ns second.thing (:require [first.one :as one]))
nil
second.thing=> (one/->Nav "root" ::root nil)
#first.one.Nav{:text "root", :link :second.thing/root, :nav nil}
second.thing=>
@iha2Otherwise you'd need this:
first.one=> (ns second.thing (:import (first.one Nav)))
nil
second.thing=> (Nav. "root" ::root nil)
#first.one.Nav{:text "root", :link :second.thing/root, :nav nil}
second.thing=>
(I'm assuming it works the same way in cljs 🙂 )
Hello, I need some help! At the minute it returns a vector and I'd like it to return a string separated by a ,
It looks like it is returning a string. Note that it starts with ", and all of the other occurrences of " you show are escaped by preceding them with a \
What does (load-csv-file ...)
return?
That is a list whose first (and only) element is a vector of strings.
To get what you want, something like (str/join "," (first (load-csv ...)))
would return what you want.
Yup, I cut it but its a list of vectors in a csv. Essentially I need it to return just a string so I can pass that to other functions
What functions do you want to pass it to, that require strings?
what I'm trying to do is replace the (slurp filepath) part
It looks like perhaps load-csv
returns a similar kind of value that csv/read-csv
might? Or do they return different kinds of data structures?
Turning all of your data into a string in memory, just to parse it again, seems odd
I'm integrating code someone else has written into my project, and it needs to use the load-csv format to be consistent with the rest of my project essentially
If I can get the load-csv-file function to do what I want I can move on with the rest of my task!
Understood. Sorry, I am not aware of the differences in detail between load-csv and read-csv. Someone else might know.
no worries, thanks for getting back to me anyway!
It seems that if you do really want to create a string of your CSV data, and reparse it, perhaps you want to do (str/join "\n" (map #(str/join "," %) (load-csv ...))). The map
will create comma-separate strings of each element of your list (where each of those elements is a vector), then the outer str/join will concatenate those together, with newlines between them.
@ilayda It seems like your load-csv-file
function is loading the csv as a vector of things and then applying the str
function to that vector. If you read the csv file in as a vector and do not coerce it, then you can call (clojure.string/join "," my-vec)
and get the desired `"username,password,..." output
something like this should do it for all of the rows. you can adapt this to do it for only a specific number of rows or whatever you'd like
(with-open [reader ( "my-csv-file.csv")]
(->> (clojure.data.csv/read-csv reader)
;; (take n) ;; uncomment this to take 'n' number of rows, you'll have to define 'n' somewhere
(map #(clojure.string/join "," %))))
Hello guys. How are u doing?
I'm a beginner at clojurescript with re-frame. I'm having a few issues using bidi to route my views
core.cljs:3901 re-frame: no subscription handler registered for: :active-panel. Returning a nil subscription.
Error rendering component (in poc_cljs.views.main_panel)
(rf/reg-sub
:active-panel
(fn [db _]
(:active-panel db)))
you probably want something like thisThis piece of code gets the variable and put it on a db?
hi guys i am using figwheel-main template for simple site
i am hosting it on github pages which require me to put compiled version there
github pages require index.html
to be on top lvl but in my case it's in
Is there a way to move this to top level for development and also github pages?
I created an deps.edn
alias to generate a single minified .js file in /docs/js directory and manually copied any html, css and other static resources to /doc
. The static assests dont change much, so can just run Clojure CLI tools alias to create a new version of the ClojureScript application.
See the end of this article for examples: http://jr0cket.co.uk/2019/08/development-workflow-with-clojure-cli-tools.html
just copy it? the html is most likely dead simple and doesn't change? it's just a call to app.js or whatever, right?
Hi everyone If afrit is a macro, how do I get it to expand within the let definition? (defn cfrit [ks] (let [ (afrit ks int32) ])())
I'm trying to write a macro to expand to name (get-type handle) so the example above would expand to let [ ks (get-int32 handle) ] (...)
but macroexpansion seems to see (afrit ks int32) as a single form and let requires an even number of forms within the [] or it throws an error
`(let [~@(afrit ks int32)] ...)
- something like this~@ when inside ` unwraps a sequence as individual children of the parent
No luck I'm afraid with that Syntax error macroexpanding clojure.core/let at (core.clj:1273:5). [(clojure.core/unquote-splicing (afrit ks int32))] - failed: even-number-of-forms? at: [:bindings] spec: :clojure.core.specs.alpha/bindings
what does afrit actually return?
no, that's wrong
you can't use ~ outside `
and you can't do this in a defn correctly, this needs to be a defmacro
https://github.com/bhauman/figwheel-main/blob/master/doc/figwheel-main-options.md#pre-build-hooks can i use this in order to create copy of 1 folder (images)
@noisesmith thanks for your help, that's given me a pointer I needed, I appreciate it.
for reference
1255 (defn gass
1256 [ty]
1257 (symbol (str "bb-" ty)))
1258
...
1266
1267 (defmacro afrit
1268 [ks ts]
1269 `(symbol ks) ((gass ts)))