workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | <@Giovanna> thanks :slightly_smiling_face: the logging xf was indeed my best shot before coming back here! | 2017-12-15T04:14:39.000267 | Kalyn |
clojurians | clojure | <@Sandy> <@Foster> me too :slightly_smiling_face: and preferably regex builders rather than using the old-school regex language, which is horrible for maintaining code written in it IMO | 2017-12-15T04:24:19.000422 | Kalyn |
clojurians | clojure | Could be nice :slightly_smiling_face: | 2017-12-15T04:25:24.000001 | Kalyn |
clojurians | clojure | Hi, I want to get the meta data attached to a function var without knowing the name of the function var at compile time, I tried to do this:
```
user=> (defn ^::a-meta ttt [])
#'user/ttt
user=> #'ttt
#'user/ttt
user=> (meta ttt)
nil
user=> (meta #'ttt)
{:user/a-meta true, :arglists ([]), :line 11, :column 1, :file "NO_SOURCE_PATH", :name ttt, :ns #object[clojure.lang.Namespace 0x52d645b1 "user"]}
user=> (meta #'(symbol "ttt"))
CompilerException java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol, compiling:(NO_SOURCE_PATH:15:1)
```
It failed because the `#'` is a reader macro. If the function name is defined at runtime, are there any ways to get a function's meta data? | 2017-12-15T04:32:07.000066 | Tari |
clojurians | clojure | <@Tari> `(meta (var (symbol "ttt")))`? | 2017-12-15T04:34:32.000429 | Noella |
clojurians | clojure | that's not how var works | 2017-12-15T04:35:00.000363 | Kareen |
clojurians | clojure | use resolve | 2017-12-15T04:35:18.000026 | Kareen |
clojurians | clojure | true, `ns-resolve` is what you want: <http://clojuredocs.org/clojure.core/ns-resolve> | 2017-12-15T04:35:45.000241 | Noella |
clojurians | clojure | Thank you. <@Noella> <@Kareen> | 2017-12-15T04:37:51.000479 | Tari |
clojurians | clojure | <@Jami> thanks | 2017-12-15T05:32:20.000305 | Kalyn |
clojurians | clojure | <@Danyel> coolest stuff <https://github.com/vvvvalvalval/scope-capture> thanks! | 2017-12-15T05:34:08.000502 | Kalyn |
clojurians | clojure | 1. most `if ...` I write are atleast three lines: one for condition, one for then, one for else branch
2. C has test ? true : false
3. does clojure have a nice macro for that ? | 2017-12-15T05:40:53.000519 | Berry |
clojurians | clojure | if itself? | 2017-12-15T05:41:31.000371 | Kareen |
clojurians | clojure | how is `test ? true : false` any different than `(if test true false)` | 2017-12-15T05:41:43.000446 | Kareen |
clojurians | clojure | it's hard to read | 2017-12-15T05:41:47.000504 | Berry |
clojurians | clojure | how? | 2017-12-15T05:41:52.000017 | Kareen |
clojurians | clojure | when squished on a single line | 2017-12-15T05:41:53.000442 | Berry |
clojurians | clojure | I like the ? and : to separate the conditions | 2017-12-15T05:42:01.000135 | Berry |
clojurians | clojure | in practice, do you write single line `(if test true-expr false-expr)` code ? | 2017-12-15T05:42:25.000457 | Berry |
clojurians | clojure | yes | 2017-12-15T05:42:32.000138 | Kareen |
clojurians | clojure | maybe I'm just not used to eading them | 2017-12-15T05:42:33.000280 | Berry |
clojurians | clojure | Is there any standard file reader transducer?
Something that can be used to stream-read from a file, that can be used within a transducing process? (meaning e.g. composed with other transducers) (edited)
Or should I work up a transducer around lazy file reading myself, i.e. from something like this? | 2017-12-15T05:46:26.000185 | Kalyn |
clojurians | clojure | ```
(defn text-file-reader [filepath reader]
(with-open
[file-reader (reader filepath)]
(line-seq file-reader)))
``` | 2017-12-15T05:46:40.000013 | Kalyn |
clojurians | clojure | (empty? 23) throws an exception
is there a wa to say:
(and (.... is a collection) (empty? ...)) | 2017-12-15T05:49:06.000531 | Berry |
clojurians | clojure | there is `seq?` | 2017-12-15T05:50:21.000333 | Angela |
clojurians | clojure | also, u can use a `seq` to check for empty or nil values. `(seq [])` returns nil | 2017-12-15T05:52:04.000009 | Angela |
clojurians | clojure | <@Berry> one of `coll?` `seq?` `seqable?` depending on what you need | 2017-12-15T06:00:11.000025 | Kareen |
clojurians | clojure | Adding to my transduction question three hops above :slightly_smiling_face: is there a core library test function for a newly-written transducer "playing by the rules"? (the rules as per "<https://clojure.org/reference/transducers#Creating> Transducers") | 2017-12-15T06:05:24.000431 | Kalyn |
clojurians | clojure | given something like
```
(def myv [:a :c :b])
(def mym {:a :anew})
```
I need a function to simply do the replacement and get
```
(:c :b :anew)
``` (the order doesn't matter) | 2017-12-15T06:54:38.000337 | Krystina |
clojurians | clojure | something like this works but it's a bit insane `(keys (clojure.set/rename-keys (zipmap myv (range 3)) mym))` | 2017-12-15T06:54:51.000169 | Krystina |
clojurians | clojure | any better alternatives? | 2017-12-15T06:55:16.000265 | Krystina |
clojurians | clojure | time for another Specter solution :smile: | 2017-12-15T06:59:18.000196 | Noella |
clojurians | clojure | `(transform ALL #(get mym % %) myv)` | 2017-12-15T06:59:29.000006 | Noella |
clojurians | clojure | ah nice can't use it in this project though | 2017-12-15T06:59:41.000101 | Krystina |
clojurians | clojure | we have `medley` at least | 2017-12-15T06:59:50.000424 | Krystina |
clojurians | clojure | but not sure it helps in this case | 2017-12-15T07:00:00.000544 | Krystina |
clojurians | clojure | are you not allowed to add dependencies? | 2017-12-15T07:00:21.000006 | Noella |
clojurians | clojure | ```user=> (def myv [:a :c :b])
#'user/myv
user=> (def mym {:a :anew})
#'user/mym
user=> (replace mym myv)
[:anew :c :b]``` | 2017-12-15T07:00:37.000199 | Kareen |
clojurians | clojure | well we have to agree on which to add, and it was agreed not to add specter | 2017-12-15T07:00:42.000124 | Krystina |
clojurians | clojure | I get that people like specter but clojure.core is often more than enough | 2017-12-15T07:00:53.000134 | Kareen |
clojurians | clojure | did not know about replace! | 2017-12-15T07:01:08.000502 | Noella |
clojurians | clojure | ah nice yes replace is what I needed :smile: | 2017-12-15T07:01:09.000031 | Krystina |
clojurians | clojure | there are too many functions in core to remember them all :slightly_smiling_face: | 2017-12-15T07:01:23.000013 | Noella |
clojurians | clojure | btw I also prefer sticking to core as much as possible | 2017-12-15T07:03:40.000085 | Noella |
clojurians | clojure | I started to learn Specter today, the lib is amazing ! | 2017-12-15T07:04:22.000052 | Jami |
clojurians | clojure | it becomes less scary when you read the List of Macros and List of Navigation on the wiki | 2017-12-15T07:04:42.000239 | Jami |
clojurians | clojure | and similar thing (still without Specter), from
```
{:a 1
:b 2}
{:a inc}
```
I want to map to the values but depending on the key, so
```
{:a 2
:b 2}``` in this case | 2017-12-15T07:08:13.000408 | Krystina |
clojurians | clojure | there is `map-values` in medley but it's not quite the same | 2017-12-15T07:08:38.000097 | Krystina |
clojurians | clojure | I could split the map many submaps, apply the transformations and merge them all maybe | 2017-12-15T07:09:07.000058 | Krystina |
clojurians | clojure | this works for example
```
(into {}
(for [[k v] (seq mm)]
[k ((k tr identity) v)]))``` but other suggetions welcome | 2017-12-15T07:12:11.000052 | Krystina |
clojurians | clojure | I think that one’s readable :+1: | 2017-12-15T07:12:41.000137 | Noella |
clojurians | clojure | ```user=> (def a {:a 1 :b 2})
#'user/a
user=> (def b {:a inc})
#'user/b
user=> (reduce-kv update a b)
{:a 2, :b 2}``` | 2017-12-15T07:14:22.000224 | Kareen |
clojurians | clojure | nice another point for <@Kareen> :+1: | 2017-12-15T07:15:17.000087 | Krystina |
clojurians | clojure | slick :+1: | 2017-12-15T07:16:12.000012 | Noella |
clojurians | clojure | and last one, from
```
(def m {:a 1 :b 2})
(def order [:b :a])
```
to `[2 1]` ? | 2017-12-15T07:40:53.000031 | Krystina |
clojurians | clojure | I just did ```
(for [f fields]
(f m))``` | 2017-12-15T07:41:27.000438 | Krystina |
clojurians | clojure | mm can just do `(map #(% {:a 1 :b 2}) [:b :a])` actually | 2017-12-15T07:42:56.000114 | Krystina |
clojurians | clojure | do you know a function that executes a form and returns nil on Exception ? | 2017-12-15T07:52:44.000211 | Jami |
clojurians | clojure | I though I knew it, but I can't remember ... | 2017-12-15T07:52:56.000149 | Jami |
clojurians | clojure | hmmm try | 2017-12-15T07:56:43.000135 | Weston |
clojurians | clojure | if you really need a fn you can easily wrap it | 2017-12-15T07:57:00.000143 | Weston |
clojurians | clojure | <@Weston> got it
```
(defmacro ex-nil "Return nil if body throws an Exception"
[& body] `(try ~@body (catch Exception ex#)))
``` | 2017-12-15T08:00:18.000185 | Jami |
clojurians | clojure | a bit late to the game but finally got time to take a look at scope-capture - really cool and extremely useful, can definitely see myself using this going forward | 2017-12-15T08:26:33.000266 | Joette |
clojurians | clojure | or even better, `(map {:a 1 :b 2} [:b :a])` | 2017-12-15T08:28:01.000102 | Kareen |
clojurians | clojure | is someone familiar with clj-time ? Why is this not valid ```(f/parse-local (f/formatter "EEE MMM dd HH:mm:ss yyyy z") "Thu Apr 24 10:27:52 2014 CEST") => Invalid Format: is malformed at "CEST"``` | 2017-12-15T08:35:49.000618 | Jami |
clojurians | clojure | I think the last time zone spec needs to be more z's | 2017-12-15T08:37:53.000025 | Joette |
clojurians | clojure | OK ... apparently, joda time cannot parse 'z' zone name <http://www.joda.org/joda-time/key_format.html> | 2017-12-15T08:39:17.000052 | Jami |
clojurians | clojure | wow, did not know that, that's a pretty major omission | 2017-12-15T08:42:46.000185 | Joette |
clojurians | clojure | yes ... I couldn't agree more ! | 2017-12-15T08:43:18.000458 | Jami |
clojurians | clojure | I think the format was meant for human, not machine | 2017-12-15T08:43:56.000194 | Jami |
clojurians | clojure | doesn't solve the abbreviated "CEST" parsing, but there is <http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormatter.html#withOffsetParsed%28%29> | 2017-12-15T08:46:34.000277 | Joette |
clojurians | clojure | <https://stackoverflow.com/questions/1327229/how-can-i-parse-a-date-including-timezone-with-joda-time> | 2017-12-15T08:46:58.000403 | Joette |
clojurians | clojure | <@Joette> thanks for the help, I think there is no answer to deal with the text timezone properly | 2017-12-15T08:52:16.000102 | Jami |
clojurians | clojure | yeah, seems like it | 2017-12-15T08:52:30.000294 | Joette |
clojurians | clojure | so this is the "hack" I found:
```
(def CERT_DATE_PARSER (comp (fn [x] (f/parse (f/formatter "EEE MMM dd HH:mm:ss yyyy") x))
(fn [x] (str/replace x #"(\w+ \w+ \d+ [0-9:]+) (\w+) (\d+)" "$1 $3"))))
``` | 2017-12-15T08:52:39.000176 | Jami |
clojurians | clojure | just wrote something to set the time zone on the formatter, but 1. CEST is not one of the ids and 2. if you get the time as a string it doesn't exactly solve your problem | 2017-12-15T08:53:04.000130 | Joette |
clojurians | clojure | ```
(def fmt (.withZone (f/formatter "EEE MMM dd HH:mm:ss yyyy") (org.joda.time.DateTimeZone/forID "Europe/Paris")))
(f/parse-local fmt "Thu Apr 24 10:27:52 2014")
```
works, but like I said, no CEST | 2017-12-15T08:53:30.000404 | Joette |
clojurians | clojure | <@Jami> you always have SimpleDateFormat:
```
(.parse (java.text.SimpleDateFormat. "EEE MMM dd HH:mm:ss yyyy zzz") "Thu Apr 24 10:27:52 2014 CEST")`
``` | 2017-12-15T09:02:35.000320 | Joette |
clojurians | clojure | it works :slightly_smiling_face: thanks ! | 2017-12-15T09:03:25.000154 | Jami |
clojurians | clojure | I discovered specter yesterday, it's hard not to become addict | 2017-12-15T09:16:54.000268 | Jami |
clojurians | clojure | I wonder if there is something similar in Python | 2017-12-15T09:17:08.000520 | Jami |
clojurians | clojure | <@Joette> Try asking in <#C0744GXCJ|cursive> ? Might get a better response there | 2017-12-15T10:21:24.000587 | Mallie |
clojurians | clojure | Aah, you have :wink: | 2017-12-15T10:21:38.000222 | Mallie |
clojurians | clojure | yeah, realized a tad late that there was a channel for cursive | 2017-12-15T10:24:27.000134 | Joette |
clojurians | clojure | That will work fine, but it’s not recommended as you have not included any namespace qualification and will be potentially colliding with every other user creating a namespace `a`. Rather, Clojure follows the Java recommendation of starting your package with a reverse DNS of a domain you control or a trademarked name or some other thing that has a chance of disambiguating your code across all the other code in the world. | 2017-12-15T10:47:51.000066 | Sonny |
clojurians | clojure | it’s totally fine (just not recommended) - see my comment on prior message | 2017-12-15T10:48:07.000773 | Sonny |
clojurians | clojure | I am trying to implement a algorithm that updates objects in a list. The update function takes each object and the list itself (the other objects) as updated so far. With an imperative approach this is easy using mutability (a for loop and indexes), but what is the best approach to doing this in Clojure? I have tried a reduce, but that of course only passes the original list to the reducing function. | 2017-12-15T10:49:25.000541 | Kennith |
clojurians | clojure | <@Kennith> `reduce` doesn't pass the original list, it passes to function each element and result of previous function evaluation | 2017-12-15T10:51:37.000190 | Heriberto |
clojurians | clojure | <@Kennith> based on original message I guess `map` nested in `let` would work here | 2017-12-15T10:52:23.000264 | Heriberto |
clojurians | clojure | <@Heriberto> Yeah, I get that I meant to write the objects (maps in this case) from the original list. | 2017-12-15T10:52:45.000444 | Kennith |
clojurians | clojure | could change elements in function if they're atoms or volatiles | 2017-12-15T10:53:31.000244 | Heriberto |
clojurians | clojure | also there's `doseq` | 2017-12-15T10:54:33.000442 | Heriberto |
clojurians | clojure | <@Kennith> can you explain a bit more about what the algorithm actually achieves? | 2017-12-15T11:05:26.000237 | Daniell |
clojurians | clojure | The approach in Clojure is usually to take one step back from the (traditional) implementation and think about the problem holistically instead. | 2017-12-15T11:05:51.000506 | Daniell |
clojurians | clojure | <@Daniell> I can. It updates the position of planets. The new position of a planet depends on its own previous position and the position of the other planets - new position if they have already been updated and old if they have not. | 2017-12-15T11:09:32.000239 | Kennith |
clojurians | clojure | <@Daniell> This is the js equivalent: <https://gist.github.com/maacl/b958c97a417527f4ee4dad19b361ae9f> | 2017-12-15T11:11:34.000277 | Kennith |
clojurians | clojure | ```(reduce-kv (fn [planets i planet] (assoc planets i (new-pos planet planets))) planets planets)``` something like this | 2017-12-15T11:13:31.000153 | Kareen |
clojurians | clojure | you can use planets as both accumulator and collection over which to reduce | 2017-12-15T11:13:43.000431 | Kareen |
clojurians | clojure | ```
(defn new-position [solar-system planet]
...)
(defn update-solar-system [solar-system-state]
(map (partial new-position state) solar-system-state))
(def universe-time (iterate update-solar-system initial-universe))
``` | 2017-12-15T11:15:19.000084 | Willow |
clojurians | clojure | depending on how you store the state of the solar system. as a list, a map, etc | 2017-12-15T11:16:24.000669 | Willow |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.