workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | But, even that is not the point. I want auto-maintained arglist documentation that I can see when I'm writing code. | 2017-11-02T14:12:20.000774 | Katelin |
clojurians | clojure | Emacs, and all other sane tools give this naturally for most functions. | 2017-11-02T14:12:40.000509 | Katelin |
clojurians | clojure | But, there is just one missing case, which is pretty common in my code. | 2017-11-02T14:12:52.000267 | Katelin |
clojurians | clojure | So, let me restate my question: | 2017-11-02T14:13:02.000439 | Katelin |
clojurians | clojure | emacs 4 lyfe | 2017-11-02T14:13:09.000213 | Else |
clojurians | clojure | What is a tasteful way to document a function whose mandate is to pass a map of parameters to deeper code? The user typically knows only about this function, but needs to see an accurate list of the parameters that it expects. | 2017-11-02T14:14:29.000303 | Katelin |
clojurians | clojure | A spec? | 2017-11-02T14:15:22.000206 | Weston |
clojurians | clojure | he already explicitly turned down using spec or schema for this | 2017-11-02T14:15:42.000291 | Margaret |
clojurians | clojure | Not to mention a docstring. | 2017-11-02T14:15:42.000314 | Weston |
clojurians | clojure | and doc string :smile: | 2017-11-02T14:15:48.000597 | Margaret |
clojurians | clojure | :slightly_smiling_face: | 2017-11-02T14:16:03.000366 | Katelin |
clojurians | clojure | doc string requires repeating myself in both functions. | 2017-11-02T14:16:16.000413 | Katelin |
clojurians | clojure | I feel like I've made my cases so won't belabor them here | 2017-11-02T14:16:20.000311 | Margaret |
clojurians | clojure | Spec is really the right answer, but I don't think the tooling is quite right yet. | 2017-11-02T14:16:35.000291 | Katelin |
clojurians | clojure | You could abuse destructuring {:as foo :keys [...]} but that d be odd if you dont use them | 2017-11-02T14:16:38.000686 | Weston |
clojurians | clojure | ```(def ^{:arglists (-> (var map) (meta) (:arglists))} my-map (fn [f coll] (map f coll)))
#'boot.user/my-map
(doc my-map)
-------------------------
boot.user/my-map
([f] [f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls])
nil``` something like this could work? | 2017-11-02T14:17:09.000120 | Evan |
clojurians | clojure | <@Weston>. Yes, that was my original anti-pattern in my initial quesiton. | 2017-11-02T14:17:18.000292 | Katelin |
clojurians | clojure | Or use a record but even then, they re quite open | 2017-11-02T14:17:18.000472 | Weston |
clojurians | clojure | spec is really really the right answer seeing as it shows up in docstrings | 2017-11-02T14:18:44.000183 | Aldo |
clojurians | clojure | Does spec show up in docstrings? I'd not realized that. | 2017-11-02T14:19:07.000541 | Katelin |
clojurians | clojure | <@Katelin> this is also true for prismatic.schema/defn btw | 2017-11-02T14:20:28.000099 | Margaret |
clojurians | clojure | ```+user=> (s/defn foo :- s/Num [] 42)
#'user/foo
+user=> (doc foo)
-------------------------
user/foo
([])
Inputs: []
Returns: s/Num
nil
```` | 2017-11-02T14:20:49.000510 | Margaret |
clojurians | clojure | <@Evan> Nice idea. But, currently, does not quite work in ClojureScript because there is an open bug in the handling of some arglists. | 2017-11-02T14:20:59.000630 | Katelin |
clojurians | clojure | these tools are imperfect, but they really are designed with these issues in mind | 2017-11-02T14:21:41.000593 | Margaret |
clojurians | clojure | ah, unfortunate | 2017-11-02T14:21:55.000557 | Evan |
clojurians | clojure | Re spec, one problem is that this forces creating a name to describe this map. For a simple set of parameters used in only a few functions, this is a bit heavy. | 2017-11-02T14:22:19.000390 | Katelin |
clojurians | clojure | if it's worth describing it's worth giving a name IMHO | 2017-11-02T14:22:44.000244 | Margaret |
clojurians | clojure | Some people wrote macros to work around this. But ultimately you ll grow to like this (I did) | 2017-11-02T14:23:01.000197 | Weston |
clojurians | clojure | But, agreed, spec does the heavy lifting nicely for "big" cases. And, arglist spoofing covers the remaining cases, I guess. | 2017-11-02T14:23:21.000664 | Katelin |
clojurians | clojure | why does it force you to create a name? (s/fdef my-fun :args (s/cat :the-arg-map (s/keys :req-un [::foo ::bar ::bash]))) is fine | 2017-11-02T14:23:36.000450 | Aldo |
clojurians | clojure | Because I need to use it twice. (in `fn-a` and `fn-b` in my original example) | 2017-11-02T14:24:09.000659 | Katelin |
clojurians | clojure | And, of course, I still need to list the parameters in the definition of fn-b. | 2017-11-02T14:24:41.000765 | Katelin |
clojurians | clojure | how could you use it twice without assigning it to some sort of name for any solution? 0_o | 2017-11-02T14:24:49.000731 | Aldo |
clojurians | clojure | In the code, I only need to use it once. fn-b requires me to list the parameters. fn-a only needs `(defn fn-a [options] (fn-b options))` | 2017-11-02T14:25:31.000253 | Katelin |
clojurians | clojure | you do need to list the parameters twice, that's true | 2017-11-02T14:25:31.000289 | Aldo |
clojurians | clojure | Right. I'm trying to avoid any need to list the options in or near fn-a, which may well be in a different file than fn-b. | 2017-11-02T14:26:43.000065 | Katelin |
clojurians | clojure | You can combine the groups of keys with s/and | 2017-11-02T14:26:44.000130 | Weston |
clojurians | clojure | Is there a way to add annotations to an interface when using `gen-interface`? | 2017-11-02T14:26:57.000482 | Demarcus |
clojurians | clojure | Which groups of keys? | 2017-11-02T14:27:01.000587 | Katelin |
clojurians | clojure | So your fist takes a spec with (s/and ::mapfoo ::mapbar etc) | 2017-11-02T14:27:44.000430 | Weston |
clojurians | clojure | And rest of fns just the precise submap | 2017-11-02T14:28:02.000026 | Weston |
clojurians | clojure | Thats one way | 2017-11-02T14:28:15.000290 | Weston |
clojurians | clojure | I don't think you are answering the same question that I'm asking. | 2017-11-02T14:28:30.000381 | Katelin |
clojurians | clojure | <@Demarcus> yes <https://github.com/clojure/clojure/blob/master/test/clojure/test_clojure/genclass/examples.clj> - you should be able to adapt this to gen-interface | 2017-11-02T14:28:32.000016 | Margaret |
clojurians | clojure | nice. i saw that example, but figured it would only work for gen-class | 2017-11-02T14:29:24.000673 | Demarcus |
clojurians | clojure | My functions take exactly the same parameters as each other. Only fn-b cares about them in detail. fn-a is just an exposed surface wrapped around it. | 2017-11-02T14:29:25.000052 | Katelin |
clojurians | clojure | i'll give it a go, thanks! | 2017-11-02T14:29:32.000242 | Demarcus |
clojurians | clojure | oh - if you keep reading there's a gen-interface example in the same file haha! | 2017-11-02T14:29:54.000512 | Margaret |
clojurians | clojure | yep but the example doesn't use annotations :slightly_smiling_face: | 2017-11-02T14:31:32.000477 | Demarcus |
clojurians | clojure | imo you're working too hard to avoid duplication here. just
```
(s/def ::param-list (s/cat :opts-map (s/keys ...) :other-arg ...))
(s/fdef fn-a :args ::param-list)
(s/fdef fn-b :args ::param-list)
``` | 2017-11-02T14:32:16.000506 | Aldo |
clojurians | clojure | meh, i guess if i dug one level deeper i would have seen the `add-annotations` call | 2017-11-02T14:34:18.000016 | Demarcus |
clojurians | clojure | Yes, understood, and not terrible since the duplicated code can sit next to its copy. But, this still requires:
- Repeating the param list in both the spec and fn-b (admittedly, this is no worse than any other spec, so ok...)
- Creating the name `::param-list` -- Well, more likely `::fn-b-param-list` which, again, is not terrible but adds a bit of weight.
In short. Yes, this is a reasonable answer and about the best that can be done today (with the arguable exception of the meta :arglists hack above).
But, there is still a bit of a smell here that bothers me. Sorry that I obviously can't pin down my discomfort well enough... I'm clearly in the minority here. :slightly_smiling_face: | 2017-11-02T14:38:04.000358 | Katelin |
clojurians | clojure | I am using at-at to schedule some functions and want to persist the schedules (preferably to datomic) - is there anything that can help with that or any pointers ? | 2017-11-02T14:42:11.000037 | Celina |
clojurians | clojure | I have some macros in a clj file (no coresponding cljs file exists). I want to import these from some cljc files. Doing a normal :require in the cljc files fails, because the cljs namespace doesn't exist:
```
No such namespace: common.css, could not locate common/css.cljs, common/css.cljc, or JavaScript source providing "common.css" in file src/common/pages/timesheet.cljc
```
I could do them in a cljc file, but the macros require java stuff, so almost everything would be reader conditionaled to clj.
I managed to get it working with `(:require-macros [common.css :as css])`, but I'm very confused, because as far as I know clj files don't recognize require-macros. Could someone explain? | 2017-11-02T14:43:35.000444 | Earlie |
clojurians | clojure | <@Celina> I'm sure it's possible (and I've done variations on it myself) but quartzite is made for this purpose <http://clojurequartz.info/> | 2017-11-02T14:43:58.000478 | Margaret |
clojurians | clojure | <@Earlie> cljc files may be compiled as clojurescript or clojure, you are compiling it as clojurescript, so clojurescript features are there | 2017-11-02T14:45:18.000008 | Rebeca |
clojurians | clojure | thanks <@Margaret> looks like thats *the* option | 2017-11-02T14:45:25.000117 | Celina |
clojurians | clojure | <@Rebeca> Except it's being compiled as clojure as well without issue. | 2017-11-02T14:45:56.000182 | Earlie |
clojurians | clojure | <@Earlie> the error message mentioning JavaScript is the clue | 2017-11-02T14:46:02.000137 | Rebeca |
clojurians | clojure | it isn't | 2017-11-02T14:46:06.000273 | Rebeca |
clojurians | clojure | The error message was with the normal (:require), not the (:require-macros). | 2017-11-02T14:46:24.000741 | Earlie |
clojurians | clojure | There isn't any error with :require-macros. | 2017-11-02T14:46:31.000457 | Earlie |
clojurians | clojure | right | 2017-11-02T14:46:36.000461 | Rebeca |
clojurians | clojure | and between those two attempts, are you loading the code the exact same way? | 2017-11-02T14:46:50.000713 | Rebeca |
clojurians | clojure | Shouldn't there be? When it's compile to clojure and it can't find the namespace, because it doesn't recognize the require-macros method? | 2017-11-02T14:47:14.000131 | Earlie |
clojurians | clojure | Yeah, same way. | 2017-11-02T14:47:19.000119 | Earlie |
clojurians | clojure | so clojurescript | 2017-11-02T14:47:35.000507 | Rebeca |
clojurians | clojure | the error message can only come from compiling clojurescript, if you are loading them the same way then they are being compiled the same way, so both are being compiled as clojurescript ∎ | 2017-11-02T14:48:05.000183 | Rebeca |
clojurians | clojure | Oh... you're right. It wasn't being compiled to clojure as well.
It thows a ns doesn't comform error now. | 2017-11-02T14:48:13.000524 | Earlie |
clojurians | clojure | So I need a reader conditional to switch between require-macros and require? | 2017-11-02T14:48:37.000097 | Earlie |
clojurians | clojure | yes | 2017-11-02T14:49:19.000499 | Rebeca |
clojurians | clojure | ```
(ns hitch.selector
#?(:cljs (:require-macros hitch.selector))
(:require [hitch.oldprotocols :as oldproto]
[hitch.protocol :as proto]
[hitch.tracking.halt :as halt]
[hitch.selector-tx-manager]))
``` | 2017-11-02T14:49:32.000195 | Willow |
clojurians | clojure | an example from us ^ | 2017-11-02T14:49:45.000433 | Willow |
clojurians | clojure | <@Willow> Well, the second require would be only for clj, since I don't have a cljs namespace of the macros namespace. | 2017-11-02T14:50:07.000442 | Earlie |
clojurians | clojure | ```
(ns common.core
#?(:clj
(:require [common.css :as css])
:cljs
(:require-macros [common.css :as css])))
```
How's that?
Can I have multiple (:require) calls in a ns? | 2017-11-02T14:50:58.000287 | Earlie |
clojurians | clojure | fwiw, I don’t think your crazy. I’ve used libraries that have similar wrapper functions and I wish that they had gone through the trouble you’re going through so I can use my `C-c d d` :slightly_smiling_face:. It seems <@Evan>’s recommendation is a decent fix if it worked with cljs. It looks a lot like <https://docs.python.org/2/library/functools.html#functools.wraps> from python | 2017-11-02T14:51:26.000412 | Jonas |
clojurians | clojure | I suppose that works:
```
(ns common.core
(:require
...
#?(:clj [common.css :as css]))
#?(:cljs (:require-macros [common.css :as css])))
```
A bit ugly | 2017-11-02T14:53:21.000067 | Earlie |
clojurians | clojure | What does <https://clojurescript.org/about/differences#_namespaces> mean by "implicit macro loading". It's not clear to me how that's accomplished. | 2017-11-02T14:53:44.000159 | Earlie |
clojurians | clojure | Hi, can anybody share a pointer on how to provide the preference for a `defrecord` that also implements `IDeref`? I get the error `interface clojure.lang.IDeref and interface clojure.lang.IRecord, and neither is preferred`. | 2017-11-02T15:17:18.000035 | Ernest |
clojurians | clojure | that is just the printer | 2017-11-02T15:17:38.000419 | Rebeca |
clojurians | clojure | if you don't try and print the record you won't get that error | 2017-11-02T15:17:53.000272 | Rebeca |
clojurians | clojure | or you can fiddle with the print-method multi method | 2017-11-02T15:18:11.000374 | Rebeca |
clojurians | clojure | it isn't a defrecord thing, it is a mutimethod thing, because the printer dispatches on type, and it has a method for IRecord and for IDeref, and neither is more specific | 2017-11-02T15:19:57.000664 | Rebeca |
clojurians | clojure | <@Rebeca> Thanks! | 2017-11-02T15:22:08.000211 | Ernest |
clojurians | clojure | Is there anything I use to purposely return nil from a function's tail when there's a call at the tail returning something? | 2017-11-02T17:40:24.000084 | Ahmad |
clojurians | clojure | yeah, just put nil at the end | 2017-11-02T17:42:01.000045 | Sonny |
clojurians | clojure | :) | 2017-11-02T17:42:20.000329 | Sonny |
clojurians | clojure | oh, so it's totally ok to do so? | 2017-11-02T17:42:35.000393 | Ahmad |
clojurians | clojure | sure! | 2017-11-02T17:42:40.000200 | Sonny |
clojurians | clojure | I’ve run into this occasionally and don’t know of any other solution | 2017-11-02T17:42:55.000327 | Sonny |
clojurians | clojure | you could write a function and wrap the validate if that was nicer looking to you | 2017-11-02T17:43:17.000495 | Sonny |
clojurians | clojure | Reminds me of actual Java code I saw once, 'if (c==null) return null else return c;' | 2017-11-02T17:43:17.000521 | Bibi |
clojurians | clojure | nice, thanks alex! i'm still learning, so just looking for best practices | 2017-11-02T17:43:20.000103 | Ahmad |
clojurians | clojure | ```(defmacro swallow [& body]
`(do ~@body nil))``` | 2017-11-02T17:44:39.000013 | Sonny |
clojurians | clojure | then `(swallow (s/validate …))` | 2017-11-02T17:44:51.000026 | Sonny |
clojurians | clojure | woah, that's interesting | 2017-11-02T17:45:03.000311 | Ahmad |
clojurians | clojure | prob a simpler way to do that | 2017-11-02T17:45:13.000167 | Sonny |
clojurians | clojure | if it’s always wrapping a single expression, you could just do `(def swallow (constantly nil))` | 2017-11-02T17:47:09.000132 | Sonny |
clojurians | clojure | i guess i prefer this alternative with `constantly`, most of the time it would be used for calls at the function's tail | 2017-11-02T17:49:10.000269 | Ahmad |
clojurians | clojure | thanks again alex! i didn't know about `constantly` | 2017-11-02T17:49:31.000572 | Ahmad |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.