workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | ```
(def printed-objects [CoreLabel TaggedWord Word])
(defn set-print-methods! [print-objects]
(doseq [o print-objects]
(defmethod print-method o
[piece ^java.io.Writer writer]
(.write
writer
(str “#<” (.getSimpleName o) ” ” (.toString piece) “>”)))))
(set-print-methods! printed-objects)
``` | 2017-11-15T22:20:50.000085 | Ernesto |
clojurians | clojure | `(-> “Short and sweet.” tokenize pos-tag)` | 2017-11-15T22:21:16.000050 | Ernesto |
clojurians | clojure | `;;=> [#<TaggedWord Short/JJ> #<TaggedWord and/CC> #<TaggedWord sweet/JJ> #<TaggedWord ./.>]` | 2017-11-15T22:21:40.000015 | Ernesto |
clojurians | clojure | I have two channels. One sends frequent, but low-priority messages. Another sends infrequent, but high-priority messages. I want to process messages from these channels sequentially. If a message is available on the high-priority channel, I want to process that message before the low priority channel is considered.
In essence, is there some variant of `alts!` that I can use/build that has a deterministic order in which it takes from channels? | 2017-11-16T02:25:59.000180 | Nilda |
clojurians | clojure | have you read the docstring for `alts!`? | 2017-11-16T02:27:35.000010 | Rebeca |
clojurians | clojure | You can specify `:priority true` after the channel and handler forms to indicate that the channels should be tried in declared order. | 2017-11-16T02:39:28.000195 | Valorie |
clojurians | clojure | hi guys. I'm using Cursive to develop & debug our Clojure apps, often experimenting things with the REPL. I wonder if there is an efficient way to create datastructures in the REPL sourced from a Debug breakpoint - e.g. if I have a complex datastructure, which I'd like to work with in the REPL as well (to test functions, debug etc...), how can I have a var referencing it the easiest way in the REPL? Of course I dont want to type the whole thing in the REPL, but would like to get the data from an app under- debugging (say I have a breakpoint and the object is there)? | 2017-11-16T03:31:07.000297 | Mirna |
clojurians | clojure | <@Mirna> perhaps `def`?
It should be generally avoided inside functions but I guess it's fine for debugging.
```
;; let's say I want to get `m`
(defn debug-me [x y]
(let [z (* x y)
w (Math/pow z x)
m {:x x
:y y
:wz {:z z :w w}}]
(def d-m m)
(keys m)))
(debug-me 4 5)
d-m
``` | 2017-11-16T03:49:02.000512 | Terra |
clojurians | clojure | <@Terra> <@Mirna> Yes, `def` should work for this. When stopped at your breakpoint, use Evaluate Expression to do something like: `(def test-data-var (my-expr))` - that should work fine. | 2017-11-16T03:58:40.000022 | Delois |
clojurians | clojure | I’m actually planning to try to have the REPL work when stopped at a breakpoint, but there’s some trickiness there when the user changes context (i.e. clicks on a higher stack frame) | 2017-11-16T03:59:38.000132 | Delois |
clojurians | clojure | {:keys [ .... ]} works with unqualified names. Does it also work with qualified names (from other namespaces)? intuition says no, since there could be more than one match, and there's no obvious way which to pick. | 2017-11-16T04:01:54.000483 | Berry |
clojurians | clojure | <https://clojure.org/guides/destructuring#_namespaced_keywords> ? | 2017-11-16T04:08:04.000208 | Rosia |
clojurians | clojure | Not really. Binding `*defaults*` isn’t really a done thing. Normally you’d `(merge defaults overrides)`.
Can even do patterns like:
```
(def default-sentiment-labels ["foo" "bar"])
(defn my-fn [{:keys [labels] :or {labels default-sentiment-labels}]
,,,)
``` | 2017-11-16T04:22:18.000042 | Magdalena |
clojurians | clojure | thanks for the responses <@Terra> <@Delois> <@Berry> Indeed, `def` can be used - was too obviuos for me to find it :slightly_smiling_face: | 2017-11-16T04:30:03.000090 | Mirna |
clojurians | clojure | hello folks - just wondering if I can dip into the hive mind for five mins…. | 2017-11-16T07:34:27.000305 | Troy |
clojurians | clojure | I want to use a resource and have it clean up …. like `with-open` | 2017-11-16T07:34:54.000157 | Troy |
clojurians | clojure | but the resource has a shutdown method rather than a close method | 2017-11-16T07:35:20.000015 | Troy |
clojurians | clojure | do I make my own or is there a more idiomatic alternative? | 2017-11-16T07:35:42.000255 | Troy |
clojurians | clojure | <@Troy> we use a custom macro like this: | 2017-11-16T08:17:23.000063 | Karolyn |
clojurians | clojure | and then something like `(with-cleanup [r (make-resource) .shutdown] ...)` | 2017-11-16T08:17:56.000542 | Karolyn |
clojurians | clojure | thanks <@Karolyn> | 2017-11-16T08:18:31.000339 | Troy |
clojurians | clojure | For the moment I just copied / pasted with-open | 2017-11-16T08:18:53.000032 | Troy |
clojurians | clojure | but yours is nicer as the method can be varied | 2017-11-16T08:19:23.000328 | Troy |
clojurians | clojure | in the end you can also just write out a `(let [r (make-resource)] (try .... (finally (.shutdown r))` | 2017-11-16T08:19:43.000005 | Karolyn |
clojurians | clojure | indeed | 2017-11-16T08:21:49.000092 | Troy |
clojurians | clojure | <@Mirna> if you might also want to use the data in a regression test, I wrote a library that simplifies stashing the clojure data to disk and re-inflating it to use it in test code | 2017-11-16T12:47:59.000283 | Margaret |
clojurians | clojure | In that context, it's fair to say that macros make Lisp a more 'tangible' language than others | 2017-11-16T14:32:48.000204 | Jeanene |
clojurians | clojure | what are some highly-considered db migration libraries (mysql specific?) | 2017-11-16T14:46:40.000162 | Lori |
clojurians | clojure | Calling Flyway (Java lib) from Clojure is just a few lines of code | 2017-11-16T14:48:44.000369 | Carletta |
clojurians | clojure | good point, I always forget I can reach for java :slightly_smiling_face: | 2017-11-16T14:51:26.000181 | Lori |
clojurians | clojure | anybody know if ideaVim, Cursive, and parinfer play well together? | 2017-11-16T16:13:44.000089 | Antonia |
clojurians | clojure | <@Antonia> Mostly, yes. There’s some doc here about problems: <https://github.com/cursive-ide/cursive/wiki/IdeaVim-issues> | 2017-11-16T16:15:28.000593 | Delois |
clojurians | clojure | Certainly there are Cursive users using it, and most seem to consider it more or less EVIL-level emulation. | 2017-11-16T16:16:37.000093 | Delois |
clojurians | clojure | I don’t use it myself so I only have hearsay on that though. | 2017-11-16T16:16:48.000550 | Delois |
clojurians | clojure | <@Delois> you get parinfer 3.0 ported over yet? | 2017-11-16T16:17:02.000348 | Antonia |
clojurians | clojure | I have it mostly done, it’s waiting on a couple of outstanding bugs. Shaun was hopefully going to find time to look at them soon. Once they’re fixed it’ll be good to go. | 2017-11-16T16:17:45.000452 | Delois |
clojurians | clojure | IdeaVim seems to have many issues on its own that are frustrating. I can never get certain leader combinations to work properly | 2017-11-16T16:20:35.000294 | Antonia |
clojurians | clojure | I’m not sure, sorry - I’m not vim-literate myself. | 2017-11-16T16:21:54.000482 | Delois |
clojurians | clojure | they seem to be known issues....I'm resigned to carpal tunnel syndrome on some of the action with some hideous ctrl-alt-shift-....if I just had one more pinkie" combination | 2017-11-16T16:26:32.000460 | Antonia |
clojurians | clojure | Hi, this is beginner stuff, an exercise to re-implement boolean: (defn boolean [x]
(if (x == "false")
false
(if (x == "nil")
false
true))) | 2017-11-16T16:56:04.000442 | Katina |
clojurians | clojure | but | 2017-11-16T16:56:30.000181 | Katina |
clojurians | clojure | user> (boolean "asd")
java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn | 2017-11-16T16:56:32.000443 | Katina |
clojurians | clojure | can't understand what's wrong | 2017-11-16T16:56:42.000402 | Katina |
clojurians | clojure | <@Katina> assuming you were wanting to output based on string values `(cond (= x "false") false (= x "nil") false true)` | 2017-11-16T16:57:57.000135 | Shameka |
clojurians | clojure | `(x == "false")` I think you want `(= x "false")` | 2017-11-16T16:58:02.000192 | Mia |
clojurians | clojure | ohh, :slightly_smiling_face: | 2017-11-16T16:58:19.000200 | Katina |
clojurians | clojure | depending on what you’re actually testing for | 2017-11-16T16:58:34.000228 | Mia |
clojurians | clojure | the string `false` or the value `false` | 2017-11-16T16:58:51.000291 | Mia |
clojurians | clojure | but, the root cause, `(x == "false")` is not doing what you think it’s doing | 2017-11-16T16:59:23.000423 | Mia |
clojurians | clojure | there is a <#C053AK3F9|beginners> channel that may be helpful for you | 2017-11-16T17:00:11.000340 | Mia |
clojurians | clojure | yes, this is for the <http://mooc.fi|mooc.fi> course, I'll see how the tests go, but that one was really noob | 2017-11-16T17:00:17.000162 | Katina |
clojurians | clojure | Thanks, and thanks for the suggestion | 2017-11-16T17:00:27.000572 | Katina |
clojurians | clojure | <@Antonia> Years ago I bought one of these and have used one for heavy typing ever since -- not cheap, but way cheaper than wrist surgery. Puts most of those modifier keys under your thumbs, and the keys are programmable, too. <https://www.kinesis-ergo.com/shop/advantage2/> | 2017-11-16T17:19:52.000048 | Micha |
clojurians | clojure | <@Micha> nice. I use this <https://www.microsoft.com/accessories/en-us/products/keyboards/sculpt-ergonomic-desktop/l5v-00001> | 2017-11-16T17:29:45.000234 | Antonia |
clojurians | clojure | <@Micha> nice. I use this <https://www.microsoft.com/accessories/en-us/products/keyboards/sculpt-ergonomic-desktop/l5v-00001> | 2017-11-16T17:29:54.000520 | Antonia |
clojurians | clojure | <@Micha> you use footpedals? | 2017-11-16T17:31:12.000174 | Antonia |
clojurians | clojure | I have them, but have only used them on occasions when I was transcribing some audio lectures, where i mapped foot pedals to play/pause on the audio. I do use VI key bindings inside of Emacs, too, just to be weird, although there are still plenty of control keys I use too often for my own good. | 2017-11-16T17:32:29.000248 | Micha |
clojurians | clojure | (Sorry, Clojure denizens, we can take this privately if it gets too much longer) | 2017-11-16T17:32:55.000170 | Micha |
clojurians | clojure | <@Antonia> sorry to hear about RSI :disappointed:
I've owned those mentioned Microsoft and Kinesis in the past (circa 2011). I found them dangerously misleading - I've used Apple keyboards since 2013 - zero pain now, zero contortions (un-natural movements) | 2017-11-16T19:24:52.000262 | Kristy |
clojurians | clojure | I have used Emacs this whole time. It hasn't been a factor of pain, given that since day one I rejected the emacsy way of using the keyboard.
all my shortcuts are in the form:
command-s
ctrl-a
alt-e
etc.
simple stuff. particularly good that one can use three modifiers easily, in Mac | 2017-11-16T19:27:24.000197 | Kristy |
clojurians | clojure | you may read a little about my approach (and my real list of shortcuts) in <https://github.com/vemv/.emacs.d> . my config is not shareable as of today, but I'm working towards that. anyone interested can ping me | 2017-11-16T19:29:11.000057 | Kristy |
clojurians | clojure | ---
in general I think I have quite a story to tell, about how I beat wrist pain. Like, it really hurted a few years ago, felt how my career was at risk. did lots of research and found some really good advice buried in a sea of workarounds.
as a sad trivia, the only people I've ever met with RSI (or similar) were clojure programmers. and I couldn't really share my advice with them, because normally you can't tell people they're just wrong | 2017-11-16T19:32:44.000080 | Kristy |
clojurians | clojure | ---
this "good advice" is a bit complex to tldr, I guess I could record a 20m video for anyone interested | 2017-11-16T19:38:57.000212 | Kristy |
clojurians | clojure | is there a way to alias a namespace without requiring it? | 2017-11-16T23:07:11.000096 | Herminia |
clojurians | clojure | Maybe clojure.core/alias can do that? Not sure. | 2017-11-16T23:12:22.000048 | Micha |
clojurians | clojure | e.g. (alias 'str 'clojure.string) followed by (doc str/join) gives docs for clojure.string/join | 2017-11-16T23:14:25.000006 | Micha |
clojurians | clojure | I have a naming question. I am genuinely tempted to mix camelCase with - . Here is the problem>
Suppose I have an object, say
update-event
then, I have other functions:
update-event-new
update-event-process
update-event-do-foo-bar
but then it's not clear to me where the "noun" and the "verb" are separated.
Whereas, if I named my event
updateEvent
then I ca ndo
updateEvent-new
updateEvent-process
updateEvent-doFooBar
however, Clojure seems to uniformly dislike camelCase | 2017-11-16T23:22:21.000042 | Berry |
clojurians | clojure | oh wait, Protocols use camelCase -- so it's actually acceptable right? | 2017-11-16T23:23:26.000221 | Berry |
clojurians | clojure | that’s a red herring - clojure.string is loaded during startup. alias requires the namespace to be loaded to be able to alias it. So the answer to the original question is no. But you can work around that with a call to `create-ns` first | 2017-11-16T23:23:29.000017 | Sonny |
clojurians | clojure | Clojure doesn’t care what you do, but other people might :) | 2017-11-16T23:24:22.000206 | Sonny |
clojurians | clojure | right, by "Clojure" I meant to say "Clojure Community" | 2017-11-16T23:24:52.000080 | Berry |
clojurians | clojure | why do you need to repeat “updateEvent” in all those names? | 2017-11-16T23:25:23.000004 | Sonny |
clojurians | clojure | it seems like the Protocol naming convention sets precedence that it's 'okay to have camelCase for multi word nouns" | 2017-11-16T23:25:24.000106 | Berry |
clojurians | clojure | protocols create Java interfaces under the hood so they steal Java style naming | 2017-11-16T23:25:43.000130 | Sonny |
clojurians | clojure | or at least many people follow that | 2017-11-16T23:26:03.000017 | Sonny |
clojurians | clojure | you only really refer to protocols by name when you implement them though | 2017-11-16T23:26:25.000095 | Sonny |
clojurians | clojure | most clojurists do not use camelCase for nouns, they use kebab case | 2017-11-16T23:27:00.000096 | Sonny |
clojurians | clojure | I have a lot of functions of type signature
verb :: foobar -> ... -> ... -> ... -> foobar
so I like to have functions of name
foobar-verb1
foobar-verb2
foobar-verb3
when 'foobar' and 'verbi' both contain dashes, I find it awkward to read | 2017-11-16T23:28:47.000225 | Berry |
clojurians | clojure | some-noun-name-do-action-one vs
someNounName-doActionOne | 2017-11-16T23:29:25.000211 | Berry |
clojurians | clojure | that seems more verbose than most clojure code | 2017-11-16T23:29:58.000002 | Sonny |
clojurians | clojure | why not just (defn verb1 [foobar]) | 2017-11-16T23:30:14.000053 | Sonny |
clojurians | clojure | <https://stuartsierra.com/2016/01/09/how-to-name-clojure-functions> has a lot of good advice | 2017-11-16T23:31:32.000077 | Sonny |
clojurians | clojure | <@Sonny>: the suggestion there seems to be lots of small namespaces, and not repeat namespace name | 2017-11-16T23:37:49.000080 | Berry |
clojurians | clojure | I like his suggestions | 2017-11-16T23:40:39.000038 | Herminia |
clojurians | clojure | I don't think I've ever used camelCase in Clojure | 2017-11-16T23:40:50.000028 | Herminia |
clojurians | clojure | I also prefer verbs in front | 2017-11-16T23:41:11.000079 | Herminia |
clojurians | clojure | like a command/imperative | 2017-11-16T23:41:21.000031 | Herminia |
clojurians | clojure | but when I see what you've written above, the first thing that pops into my head is "that's a namespace" | 2017-11-16T23:42:00.000122 | Herminia |
clojurians | clojure | that is, a common prefix for top-level definition names | 2017-11-16T23:42:28.000140 | Herminia |
clojurians | clojure | but the nice thing is it splits the two pieces with a different character, `/` | 2017-11-17T00:02:17.000074 | Herminia |
clojurians | clojure | that could solve the readability issue you're having | 2017-11-17T00:02:33.000211 | Herminia |
clojurians | clojure | I think I'd solve it how the CSS people do: `update-event--new`. But I'd also avoid this problem in the first place by not doing this. | 2017-11-17T04:05:16.000346 | Jodie |
clojurians | clojure | I'm writing some "scripts" that will help to check a few things like status of database tables or marathon tasks for example | 2017-11-17T05:08:49.000394 | Krystina |
clojurians | clojure | the scripts now simply do `log/error` on errors and `log/info` otherwise, however it would be also nice to keep track of all the errors in a data structure | 2017-11-17T05:09:36.000118 | Krystina |
clojurians | clojure | (which is computed across different functions), and exit with failure Exit code in case anything failed | 2017-11-17T05:10:08.000290 | Krystina |
clojurians | clojure | any suggestions about how to do that? | 2017-11-17T05:10:49.000259 | Krystina |
clojurians | clojure | the easiest way would be to use an `atom` maybe, but it would have to be shared across different namespaces or being passed in from `core.clj` | 2017-11-17T05:11:21.000396 | Krystina |
clojurians | clojure | Hi guys I need your help.
I want to make a clojure query, but the :where conditions are condition. SO i used cond->.
this works well. but now my problem is that I want to make a clojure function call inside a (‘) or quote.
(defn foo [num]
(inc num))
(def query ‘[:find ?e
:in $
:where ])
(cond-> query
(some-condition)
(conj ‘[? :data/number ?number])
(some-other-condition)
(conj `[~’(> ?number ~(foo 2))]))
I get this result:
[:find ?e
:in $
:where [? :data/number ?number]
[(> ?number (clojure.core/unquote (foo 2)))]]
What I am trying to achieve is this:
[:find ?e
:in $
:where [? :data/number ?number]
[(> ?number 3)]]
Can anyone please help | 2017-11-17T05:15:03.000119 | Janean |
clojurians | clojure | In clojure I do same transformation to the var and then want to store the result by same name. Is this ok to do so? I don't want to invent new var names for this. Eg. `(let [address (cleanup address)] address)` | 2017-11-17T05:23:02.000031 | Anika |
clojurians | clojure | This will work:
```
(cond-> query
(some-condition)
(conj '[? :data/number ?number])
(some-other-condition)
(conj `[(~'> ~'?number ~(foo 2))]))
```
You could write a little helper function to make this easier though.
```
;; NB: Only use this when you specifically want a list (ie. code).
;; Normally prefer using conj on a vector.
(defn append [coll & xs]
(concat coll xs))
(cond-> query
(some-condition)
;; This is probably supposed to be ?e and not just ?
(conj '[?e :data/number ?number])
(some-other-condition)
(conj [(append '(> ?number) (foo 2))]))
``` | 2017-11-17T06:46:08.000030 | Giovanna |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.