This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-04
Channels
- # architecture (13)
- # bangalore-clj (1)
- # beginners (174)
- # boot (25)
- # cider (65)
- # cljs-dev (10)
- # cljsjs (4)
- # cljsrn (3)
- # clojure (169)
- # clojure-berlin (27)
- # clojure-brasil (32)
- # clojure-greece (3)
- # clojure-russia (31)
- # clojure-sg (4)
- # clojure-spec (6)
- # clojure-uk (74)
- # clojurescript (186)
- # code-reviews (5)
- # css (12)
- # cursive (17)
- # datascript (1)
- # datomic (45)
- # dirac (33)
- # funcool (42)
- # hoplon (25)
- # jobs (6)
- # jobs-discuss (114)
- # lambdaisland (6)
- # leiningen (1)
- # luminus (24)
- # off-topic (86)
- # om (13)
- # om-next (14)
- # onyx (75)
- # perun (2)
- # protorepl (19)
- # re-frame (2)
- # reagent (17)
- # ring-swagger (2)
- # rum (1)
- # slack-help (2)
- # specter (31)
- # test-check (5)
- # timbre (1)
- # untangled (34)
- # vim (8)
http://stackoverflow.com/questions/4690758/splitting-a-clojure-namespace-over-multiple-files <-- does this only work in clojure and not in cljs ?
Tonight @qqq continues the quest to try every way to not use only one clj file
@tbaldridge: I got it working with clj, but cljc also compiles at cljs, and that's the problem I'm running into 🙂
I have to ask, what are you trying to do?
so I don't like large files, as I find them difficult to navigate due to my editing habits (no fault of the editor)
I really like the SO structure of how core.clj works -- on enamespace, across multiple files
Then I gotta say, change your editing habits. Multi thousand line files are pretty standard in Clojure. Look no further than spec for examples
that's pretty insane, I like small modules of 50-200 lines; it's just unfortunate clj's support for "import from this and export this" isn't as nice as I'd like it to be
But why? If it fits in a logical unit, why break it up?
Computers are great at searching files. That kind of what I'm getting at. A great way to edit lisp is to navigate via definitions where it doesn't matter where forms are in a file.
1. I've never been in a situation where a logical unit is > 300 LOC 2. tbaldridge: well, if they're not in one logical unit, why should they be in the same namespace? 3. qqq: I don't have a good response. 4. tbaldridge: checkmate
I guess they should be in separate modules, and I just need better require/import management.
cljs blocks :refer-all; if I have multiple files that share common linew inside of (:require ... ), is there a way to def a variable there and not repeat myselv in every namespace ?
@qqq no, what I'm saying is, a logical unit of code should not be constrained by 300LOC. Let's do a quick survey of some Clojure core namespaces. clojure.core.async - 1.1k loc clojure.spec - 1.9k loc clojure.core.logic - 2.8k loc clojure.core.match - 2.1k loc clojure.test.check.generators - 1.5k loc
not sure where cljs support is with that.
@ustunozgur : alot of important people bashed that yesterday
@qqq so I say, break apart namespaces where someone is likely to want A but not B. Aside from that, just stick it all in one place. It really is easier that way.
@tbaldridge: https://github.com/halgari/odin/blob/master/src/com/tbaldridge/odin.clj <-- I understand that odin was created for educational purposes to go with your videos; in a "production environment", would odin be 1 single file instead of 4 files that are 100-400 lines long ?
that's a great question. There I mostly broke it apart based on a public API and private API (stuff in unification.clj is not public). And from there based on if you'd want A vs B. So you can choose not to import the Datomic bits if you don't need them
And also Odin doesn't have a hard dependency on several libraries. For example you don't need Datomic as a project dependency if you never require the context.datomic
namespace. Same for context.xml
re: your earlier point: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj <-- I never realized clojure.core was a single file with 7k+ lines
same with cljs
alright; so I guess . should be doing "largest reasonable unit" rather than "refactor into smallest reasonable unit"; then I should get better at emacs to manage going through files that are thousands of lines long
https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs 10k lines there
I think separating into multiple files prematurely gives a false sense of tidiness.
@ustunozgur : given the number of imports I am doing ; I unfortunately have to agree
Perhaps, but I see it as part of paredit/parnifer's view of structural editing. Just like you can copy/paste code based on logical blocks (s-exprs) so you should be able to navigate based on "jump to definition" and "find usages"
sounds like "jump to definition" is M-. in emacs
yes, but I'm at the point where if I dump everything into one file, the # of entires I have overflows a single speedbar screen (that has full vertical height)
I guess the psychological problem is as follows: with code folding, previously, I could "fold all my code" -- then see all defs in a single screen; this is no longer possible when I'm dealing with files of length 5k loc
oh I see, the tree-view of the file.
then it shows it in a vertical bar, and click,ing on it jumps me to the corresponding line in the file
I'll try this "large namespace" approach for a month or so, and if it doesn't work, I'll come back and complain later 🙂
@tbaldridge: thanks for your time / discussion
no problem. And there's really no "right way" when it comes to editing. As long as you don't feel like you're fighting the language runtime
Can you think of some interesting/nice event systems for ClojureScript which are not focused on a specific react wrapper?
I found potok (https://github.com/funcool/potok) which is actually quite nice but unfortunately is a slight bit too opinionated
I’m more looking for something along the lines of re-frame’s dispatching stuff, zelkova, etc
I've used re-frame, but not xelkova; what exactly are ou looking for? fundamentally there's a bucnh of nodes, there's a topolotical sort, and other stuff gets updated with nodes gets updated
Something I can put events in that handles them in some async manner. Something like interceptors would be nice to implement my own stuff on top of that.
@martinklepsch I'd love something like that too... I think
You think.. 😄
well I'm not sure if I even need the async part
a dead simple pub/sub mechanism would be ideal
also ideally not tied to any specific React wrapper
I’d be happy to brainstorm & jot down some ideas/requirements
my main use case is navigation events
my reagent components want to do something when you navigate to a screen X
and it turns out lifecycle methods are not the best place to do that
instead, IMO those events should be triggered by the navigation events ("user navigates to screen X")
the "things I want to do" include ajax requests, animations, setting timers. sending analytics events
does that make any sense?
@pesterhazy have you used re-frame?
@pesterhazy here's the example of how I approached navigation in Carry lib: https://github.com/metametadata/carry/blob/a04058c9ee3fef7e9f7a7971e381408bd22e10f1/examples/friend-list/src-public/friend_list/core.cljs#L48 In this sample project the url/token is synced with the search field. Demo online: https://metametadata.github.io/carry/examples/friend-list/
basically you can add a handler for the global "enter-new-page" event
@martinklepsch I've read all the docs (and am a big fan) but I'm not using it right now
I think it solves (a lot of) other problems
not sure if it really solves mine
@pesterhazy What about Google Closure's PubSub? See https://google.github.io/closure-library/api/goog.pubsub.PubSub.html
@smee, w00t
that's amazing
how did I not know about this?
nvm https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async/macros.clj
the amount of hidden treasures in google.closure is unbelieveable, and too little documented within the cljs interop. Some todo for all of us.
holy moly, so true, @hlolli. the number of times i’ve been able to remove cljs libs (cljs-http, cljs-time in particular) just by accepting some interop
The DateTime stuff in is just 👌
yep. and it’s all already sitting there. no need to add any deps
The Lisp-Lover's Illustrated Guide to Google Closure
I've thought about that recently as well, would love some sort of curated list of the closure functions that are the most useful with cljs. For example, goog.history
seems to be used a lot while goog.functions
is basically useless from cljs
there's also goog.async.Delay and friends, pretty useful
i must say, for that, i prefer to bring in core.async
being able to put transducers on dom event chans is just too damn cool 🙂
core.async also brings in a bit of complexity
In my clojurescript code (*.cljs files)
, how can i access functions or vars defined the clojure code (*.clj file)
on windows, think https://www.npmjs.com/package/cljs-repl is what I want though
@selfsame Try Lumo on Windows. https://github.com/anmonteiro/lumo
In other words, if you’d like access to what Node offers, Lumo is great. Planck is based on JavaScriptCore.
anything happen with non JVM package management? Remember there was some talk about it a few months ago
I’m torn between learning reagent vs om.next .. and honestly cannot google if om.next is released or still in alpha/beta
@kim0 you can use https://github.com/eginez/calvin to get package management without the jvm
@ambrosebs One way is to start a Clojure REPL and then “piggyback” into a ClojureScript one.
@ambrosebs Have you figured out how to create a Clojure REPL? (If not, right click on your project.clj
and make one.)
Cool. One other thing @ambrosebs is to ensure that it has cljs
picked in the little pulldown.
Yeah, that pulldown doesn’t turn it into a ClojureScript REPL—it just informs Cursive how to behave with that REPL in the odd corner cases where it needs to be different.
So, if you are in a Clojure REPL then do the (repl/repl (node/repl-env))
or whatever form would piggyback you into ClojureScript
@ambrosebs for example: http://clojurescript.org/reference/repl#using-the-rhino-environment
@ambrosebs And, if you ever want to mess with Planck from Cursive to mess around with self-hosted stuff, this would help: https://github.com/mfikes/tubular (Planck supports Socket REPL)
Let @cfleming know if you use socket repl, maybe we can bug him enough to get some more socket repl+cursive features 🙂
Hey, I feel like this is a beginner question, but I'm trying to parse URLs out of random text while not losing the intermediate text, is there some function I'm missing to do it? Like I want to go from "Check out
to ["Check out " "
(re-seq)
will give me just the links, and (string/split)
doesn't give me the links themselves if I match on eg #"https?://\S+"
Feel like there must be an obvious regex-related function I'm missing
@timgluz like https://stackoverflow.com/questions/6038061/regular-expression-to-find-urls-within-a-string ?
if you put your regex in a capture group i dont think the native js split function removes it
"Check out http://google.com/ which is awesome".split(/(https?:\S+)/); ["Check out ", "http://google.com/", " which is awesome"]
Well, I've wound up just splitting it on whitespace and then checking them word by word, which works fine but seems kind of inefficient
Yeah. I'm matching on small amounts of text
That's what I wanted to do, but you never get the matched split elements back from string/split
"Check out http://google.com/ which is awesome".split(/(https?:\S+)/); ["Check out ", "http://google.com/", " which is awesome"]
Well, I was hoping to stick to Clojure
Well, yeah
I see what you mean, I'm just slightly too stubborn to do it that way 😉
In theory the code I'm writing could be run on the server too via cljc, too
if you're in cljc then use the reader conditional to use the java string split vs js string split
Yeah, but I feel like this is just fundamental string processing, I shouldn't need to drop down to the host language to do it
...which is why I felt there must be some function I had just overlooked
I did. It works OK on the link case, not good on "this is just text with no link"
which I also need to handle
I got the best result along those lines with #"(.*?)(https?://\S+)"
matching prefix text plus link
Yeah, returns nil
Yeah, I could do that
I'm fine with the word-by-word solution for now, the perf hit isn't really noticable for my use case and the code is readable
Yeah. Thanks for the ideas though