This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-24
Channels
- # arachne (1)
- # bangalore-clj (11)
- # beginners (177)
- # boot (63)
- # business (1)
- # cljsjs (21)
- # cljsrn (3)
- # clojars (4)
- # clojure (116)
- # clojure-art (4)
- # clojure-belgium (3)
- # clojure-india (1)
- # clojure-italy (6)
- # clojure-russia (14)
- # clojure-spec (8)
- # clojure-uk (67)
- # clojurescript (51)
- # community-development (5)
- # cursive (13)
- # datascript (14)
- # datomic (29)
- # devcards (3)
- # emacs (3)
- # events (3)
- # funcool (4)
- # hoplon (29)
- # mount (6)
- # om (34)
- # om-next (5)
- # onyx (16)
- # perun (8)
- # planck (22)
- # re-frame (13)
- # reagent (5)
- # ring-swagger (21)
- # rum (3)
- # spacemacs (3)
- # specter (1)
- # untangled (39)
But how di I "save" the contents of the 4 . Do I need to use 3 variables acc , rest seq and the rest of the whole seq ?
@roelofw Consider instead that you could concat
sequences together -- so if you have a non-sequence element, you can turn it into a sequence by wrapping it in [ ]
, and if you do have a sequence you can recursively flatten it and then concat
it (since it may contain nested sequences).
Is this a 4clojure puzzle? Which one? (so I know exactly what problem you're trying to solve)
@seancorfield This is a 4clojure puzzle and here is the link : http://www.4clojure.com/problem/28
As described im not allowed to use flatten, otherwise the puzzle would be very simple
Since you need to handle deeply nested sequences, you'll need to call your "flatten" function recursively on any vectors or lists but you can do this with mapcat and a function that does what I described above.
Hello, Could you help me - give an example/ tutorial - what is possible with clojure in the NLP area?
@seancorfield you mean the part , if it's not a seq turn it into a seq otherwise take all the elements out of it ?
@sb: Google suggests this might be a good starting point for you https://github.com/dakrone/clojure-opennlp/blob/master/README.markdown
@roelofw: if coll? x then recursively call your flatten on it else return [x] -- then your flatten function would just mapcat that logic over the collection. Make sense?
@sb: I think your question is too vague. You can do anything with Clojure that you can do with Java libraries, just easier.
@roelofw: I avoided parentheses so it's not code 😆
@seancorfield time to experiment with the code. But I was on the good way when I thought about mapcat
:thumbsup::skin-tone-2:
@seancorfield Yes, I know. I saw a few really good example with java libraries (like stanford-nlp). I try a few.. and I will see. By the way thanks!
bummer, I see a object here :
(defn my-flatten [s] (mapcat (fn [_ n ] (if (coll? n) (my-flatten n ) ([n])) s )))
(my-flatten [1 [2 3 ] 4])
@rauh : You mean something like this :
(defn my-flatten [s]
(map (fn [_ n ]
(if (coll? n)
(my-flatten n )
([n]))
s )))
with the second you get this error : ArityException Wrong number of args (0) passed to: PersistentVector clojure.lang.AFn.throwArity (AFn.java:429)
yes, arity exceptions you get when you try to call function with wrong number of arguments
@roelofw you never indented your code properly. Use Cursive's help if you can. It'll indent itproperly
ok, then see how many arguments you have for each function and check closing paranthesis
aha. the s is on the wrong place. its looks now if it's a part of the anymous function
oke, I have now this :
(defn my-flatten [s]
(map (fn [_ n ]
(if (coll? n)
(my-flatten n )
[n]))
s ))
I see this error : ArityException Wrong number of args (1) passed to: core/my-flatten/fn--1463 clojure.lang.AFn.throwArity (AFn.java:429)
fn--1463
ss internal anonymous function, and error says that it's called with one (which is wrong) argument
"In Clojure, the underscore is used idiomatically to indicate that the argument it identifies is not subsequently used."
This one :
(defn my-flatten [s]
(mapcat (fn [ n ]
(if (coll? n)
(my-flatten n )
[n]))
s ))
(my-flatten [1 [2 3 ] 4])
(my-flatten [1 [22 [:e] '(1 2 3 [33 33 {:e a}]) 33] [33 33]])
;; => (1 22 :e 1 2 3 33 33 :e a 33 33 33)
btw https://mwfogleman.github.io/posts/20-12-2014-flatcat.html has a nice discussion on flatten
i'm trying to copy a file to a resource path that's different in development than it is to in production, any ideas?
is there a way to get the current resource path?
usually io/resource
takes care of it, but it doesn't work for a file that doesn't exist yet
This has bitten me before. It seems like the resource
directory is not present in production
it is present, but it's within the jar
so i have a resources
directory alongside the jar in production
but in development, it's called dev-resources
any ideas would be great!
@dpsutton I think i've got it
instead of calling io/resource
on the none-existent file, i'm doing it on the target directory then amending the new filename
let me know if you want to discuss it further!
@roelofw of course if you know that you're upper level list will only have one item (or at least you're only interested in the first) you can simply use (first xs)
where xs
is your list