workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
``` (defn reposition [planets] (map (partial new-position planets) planets)) ````
2017-12-15T11:18:16.000582
Jami
clojurians
clojure
but you have to define `new-position` to take the list of planets first
2017-12-15T11:18:36.000513
Jami
clojurians
clojure
no, using map is not correct
2017-12-15T11:19:36.000334
Kareen
clojurians
clojure
note that in <@Kennith>'s js version, each invocation of newPosition takes the updated planets map, not the original one
2017-12-15T11:19:53.000300
Kareen
clojurians
clojure
good point.
2017-12-15T11:20:52.000189
Willow
clojurians
clojure
reduce is the natural way to express this in clojure
2017-12-15T11:21:06.000728
Kareen
clojurians
clojure
<@Kareen> <@Willow> agreed, I though the planet object did not change after each iteration
2017-12-15T11:22:12.000559
Jami
clojurians
clojure
<@Kareen> Yes, that is correct. This is actually what tripped me up. Planets is a vector of maps, but reduce-kv works anyway as far as I can tell.
2017-12-15T11:22:21.000119
Kennith
clojurians
clojure
yeah reduce-kv supports vectors
2017-12-15T11:22:49.000492
Kareen
clojurians
clojure
`reduce` is the traditional solution for `state` + `rules for state change` =&gt; `new state` <@Kennith>
2017-12-15T11:24:58.000833
Daniell
clojurians
clojure
(for a given set of events -- in this case the set of planets acts as both the initial state and the set of "events" that trigger state change)
2017-12-15T11:27:14.000415
Daniell
clojurians
clojure
<@Daniell> Yes, I was missing the idea of using planets as both the accumulator and collection over which to reduce, as mentioned by <@Kareen>.
2017-12-15T11:37:25.000148
Kennith
clojurians
clojure
<@Kennith> are you doing gravitational dynamics?
2017-12-15T12:11:55.000054
Priscilla
clojurians
clojure
because if so you're making it unnecessarily difficult from a programming standpoint
2017-12-15T12:13:35.000390
Priscilla
clojurians
clojure
since from a physics standpoint you'd like to do one pass over the planets and calculate force
2017-12-15T12:14:00.000667
Priscilla
clojurians
clojure
and then another pass to update momentum
2017-12-15T12:14:20.000695
Priscilla
clojurians
clojure
and another pass to update position
2017-12-15T12:14:25.000067
Priscilla
clojurians
clojure
although for speed probably the best thing to do is to solve for the gravitational potential on a grid and then interpolate to get forces, depending on how many planets you have
2017-12-15T12:16:13.000338
Priscilla
clojurians
clojure
i doubt there's a good poisson library in javascript, haha
2017-12-15T12:16:31.000341
Priscilla
clojurians
clojure
<@Priscilla> I am, I am trying to reimplement this: <https://github.com/raisoman/de-for-children/blob/master/processingjs/p5/mars-trip.html> in cljs.
2017-12-15T12:17:23.000155
Kennith
clojurians
clojure
ya, from a physics POV, that code would be better if it accumulated `xpp` and `ypp` in arrays
2017-12-15T12:21:19.000672
Priscilla
clojurians
clojure
and only actually moved the planets after it had calculated that for all of them
2017-12-15T12:21:51.000210
Priscilla
clojurians
clojure
splitting hairs, probably; the errors from doing it as linked take many orbits to be visible
2017-12-15T12:22:33.000221
Priscilla
clojurians
clojure
`(comp (map #(update-position planets)) (map get-force))`
2017-12-15T12:24:09.000199
Priscilla
clojurians
clojure
would give you pretty much what you need
2017-12-15T12:24:25.000681
Priscilla
clojurians
clojure
<@Priscilla> I also had a sneaking suspicion that my original was actually more correct, but the constants are calibrated to work with the js version, which is quite sensitive to starting conditions since it is inserting a tiny space-ship into orbit around mars. Not that I really understand the physics very well :slightly_smiling_face:
2017-12-15T12:27:32.000343
Kennith
clojurians
clojure
``` (def queue (agent [] :error-mode :continue :error-handler (fn [a ex] (l/error ex "slack agent failed")))) ``` Is there easy and simple way to achieve `:error-mode :retry` ? :slightly_smiling_face: Just from time to time sending messages to slack fail and I don’t want lose them. * It can be achieve in whatever way. `:retry` example was to easy describe my needs.
2017-12-15T12:40:55.000124
Gladys
clojurians
clojure
`(send-off ... (retry fn) ...)`
2017-12-15T12:51:46.000162
Rebeca
clojurians
clojure
``` (defn retry [f] (fn x [&amp; args] (try (apply f args) (catch Throwable t (apply x args))))) ```
2017-12-15T12:53:02.000028
Rebeca
clojurians
clojure
there’s a gotcha also if you use defrecord, defprotocol, gen-class etc. because that creates classes in the default package which is poorly behaved on the jvm right?
2017-12-15T13:09:40.000144
Margaret
clojurians
clojure
or are clojure’s classes exempt from those problems?
2017-12-15T13:09:53.000287
Margaret
clojurians
clojure
eg. class loading problems if two deftypes both use the default package…
2017-12-15T13:13:19.000654
Margaret
clojurians
clojure
I just tried, using deftype and gen-class with namespaces producing items in the default package and yeah it works (likely would have caused problems if I tried to use import though)
2017-12-15T13:30:39.000220
Margaret
clojurians
clojure
inside a (fn [] .... ) is there a way to "refer to self, i.e. the function being defined" -- and this is not via recur
2017-12-15T14:16:27.000354
Berry
clojurians
clojure
Why are you not able to use recur?
2017-12-15T14:17:24.000347
Erlene
clojurians
clojure
you can name a fn (fn f [] …)
2017-12-15T14:17:41.000393
Felix
clojurians
clojure
because I need to call the function two/three times, in a tree like fashion, it's not a loop
2017-12-15T14:23:25.000463
Berry
clojurians
clojure
yeah, that’s why the `(fn f [] ...)` syntax exists, it’s the straightforward way to do this
2017-12-15T14:24:01.000257
Margaret
clojurians
clojure
though if two functions need to do this mutually, `letfn` exists for that purpose and no other
2017-12-15T14:24:26.000167
Margaret
clojurians
clojure
ah, the `(fn f [] ...)` syntax gives it a name I can refer to it by; no idea howI missed it all these years; thanks!
2017-12-15T14:24:57.000354
Berry
clojurians
clojure
extra bonus - when you use (fn f [] …) the name “f” will show up in a stack trace
2017-12-15T14:25:19.000447
Margaret
clojurians
clojure
sometimes I name my fn even if it doesn’t self call just so my stack traces will make a little more sense
2017-12-15T14:25:44.000008
Margaret
clojurians
clojure
it makes me want versions of partial and comp and complement and fnil etc. that take a “name” parameter too frankly
2017-12-15T14:26:23.000407
Margaret
clojurians
clojure
How does the keyword-as-accessor syntax actually work in the language? E.g. `(:b {:a 1, :b 2})` Is this just special syntax built into the language or is there some reason why keywords can act as functions in this way?
2017-12-15T14:52:25.000211
Thu
clojurians
clojure
it is not a syntax, keywords are functions
2017-12-15T14:52:38.000151
Margaret
clojurians
clojure
symbols, hash-maps, sets, and vectors are also functions
2017-12-15T14:52:56.000412
Margaret
clojurians
clojure
at one point they argued about making regexes functions too but they opted not to do that
2017-12-15T14:53:22.000502
Margaret
clojurians
clojure
specifically, keywords implement IFn
2017-12-15T14:53:34.000307
Myles
clojurians
clojure
ah? do you remember when ?
2017-12-15T14:53:45.000343
Kareen
clojurians
clojure
@chris right when I say “is a function” about clojure that means “implements IFn”
2017-12-15T14:53:55.000391
Margaret
clojurians
clojure
no - I have seen discussion about it but forget the details
2017-12-15T14:54:16.000117
Margaret
clojurians
clojure
But there must be something special about them because there are an infinite number of them and they spring forth whenever you use them
2017-12-15T14:55:04.000548
Thu
clojurians
clojure
@Justin how’s that different from fn?
2017-12-15T14:55:22.000540
Margaret
clojurians
clojure
is that different from how a function works?
2017-12-15T14:55:27.000452
Myles
clojurians
clojure
haha
2017-12-15T14:55:31.000478
Margaret
clojurians
clojure
or a symbol
2017-12-15T14:55:35.000109
Kareen
clojurians
clojure
I've never seen serious discussion about it, just perennial whinging about how nice or how cool it would be if it was the case
2017-12-15T14:55:38.000435
Rebeca
clojurians
clojure
the reader interns symbols/keywords
2017-12-15T14:55:52.000366
Kareen
clojurians
clojure
yeah same
2017-12-15T14:56:04.000231
Kareen
clojurians
clojure
but symbols can have metadata so they do something different about the interning right?
2017-12-15T14:56:14.000285
Margaret
clojurians
clojure
yeah symbols just have their internal string interned
2017-12-15T14:56:42.000153
Kareen
clojurians
clojure
actually since a few versions ago that might not be true, I can't remember
2017-12-15T14:56:54.000228
Kareen
clojurians
clojure
one possible answer “pattern is a final class” <https://groups.google.com/forum/#!topic/clojure/LiWT7NIJOdQ>
2017-12-15T14:57:16.000751
Margaret
clojurians
clojure
and interning has nothing to do with being used as a function
2017-12-15T14:59:57.000518
Rebeca
clojurians
clojure
true, I was just answering how they "pop out of existence"
2017-12-15T15:00:53.000048
Kareen
clojurians
clojure
`(foo a b c)` in clojure is something like `((IFn)foo).invoke(a, b, c)` in java
2017-12-15T15:01:09.000131
Rebeca
clojurians
clojure
I previously just thought of them as identifiers that had some concrete unique representation that allowed them to be used as keys in a map. But then they can also be used in the first position in a list (which I think of as “function” position but I’m sure it has a more precise name). I suppose the point is that they are instantiated as lookup functions the moment the reader sees them and the reference to that lookup function is what is used as a key?
2017-12-15T15:01:30.000144
Thu
clojurians
clojure
they are instances of clojure.lang.Keyword
2017-12-15T15:01:53.000379
Rebeca
clojurians
clojure
which implements IFn
2017-12-15T15:01:59.000025
Rebeca
clojurians
clojure
clojure.lang.IFn
2017-12-15T15:02:08.000215
Rebeca
clojurians
clojure
oh right. okay got it
2017-12-15T15:02:26.000205
Thu
clojurians
clojure
thanks all
2017-12-15T15:02:29.000031
Thu
clojurians
clojure
@Justin also, regarding “allowed to use them as keys in a map” that’s true of literally any value in clojure
2017-12-15T15:02:40.000258
Margaret
clojurians
clojure
as an aside
2017-12-15T15:02:51.000187
Margaret
clojurians
clojure
`(:foo {:foo 1})` becomes something like `new Keyword ("foo").invoke ( {:foo 1 })`
2017-12-15T15:03:14.000202
Kareen
clojurians
clojure
any object on the jvm that doesn't replace Object's hashCode and equals with methods that throw execeptions
2017-12-15T15:03:24.000093
Rebeca
clojurians
clojure
which is implemented roughly as `{:foo 1}.get(this)`
2017-12-15T15:03:40.000638
Kareen
clojurians
clojure
clojure values just make better keys then most objects on the jvm
2017-12-15T15:04:07.000338
Rebeca
clojurians
clojure
immutability is a good idea™
2017-12-15T15:04:48.000444
Myles
clojurians
clojure
ahh right- you can use a mutable thing as a key, but if the mutation changes the hash or equality you will have a bad time haha
2017-12-15T15:05:32.000352
Margaret
clojurians
clojure
<@Margaret> Right that was phrased awkwardly. Keywords are a little interesting because unlike something like a let binding or a formal parameter, what you call the keyword actually changes something in memory. I guess that’s no different from a string literal but it has always felt unusual to me because a keyword looks like a formal name rather than data.
2017-12-15T15:06:07.000684
Thu
clojurians
clojure
At least I think that’s right.
2017-12-15T15:06:20.000370
Thu
clojurians
clojure
keywords are data, not labels
2017-12-15T15:06:31.000610
Kareen
clojurians
clojure
just like a string or a number
2017-12-15T15:06:48.000096
Kareen
clojurians
clojure
same with symbols
2017-12-15T15:07:08.000067
Rebeca
clojurians
clojure
Thanks yea that’s important to remember. Because to my C/C++/JS mind they look like names.
2017-12-15T15:07:24.000207
Thu
clojurians
clojure
(in fact they are listed under data_structures on <http://clojure.org|clojure.org>, <https://clojure.org/reference/data_structures>)
2017-12-15T15:07:34.000347
Rebeca
clojurians
clojure
apart from reader macros, there's no labels or language syntax that's not reified as a value
2017-12-15T15:08:14.000372
Kareen
clojurians
clojure
let bindings are sneaky to find, and even sneakier to do anything with as data haha but yeah <https://gist.github.com/noisesmith/3490f2d3ed98e294e033b002bc2de178>
2017-12-15T15:10:54.000346
Margaret
clojurians
clojure
omg
2017-12-15T15:11:35.000162
Thu
clojurians
clojure
Beyond the `(keys &amp;env)` I wouldn’t really consider let-bindings to be “reified” (officially) in clj
2017-12-15T15:12:15.000329
Petronila
clojurians
clojure
right - but that snippet proves they are reified
2017-12-15T15:12:34.000218
Margaret
clojurians
clojure
sort of
2017-12-15T15:12:42.000100
Petronila
clojurians
clojure
hah
2017-12-15T15:12:42.000420
Petronila
clojurians
clojure
no
2017-12-15T15:12:42.000454
Rebeca
clojurians
clojure
you are reading compiler state using the macro and generating code to reproduce it at runtime
2017-12-15T15:13:10.000104
Rebeca
clojurians
clojure
oh… that is different OK
2017-12-15T15:13:30.000012
Margaret
clojurians
clojure
what bronsa meant is `(let [a 1] a)` is not "syntax" as such, it is a list containing a symbol, a vector, and another symbol
2017-12-15T15:14:04.000290
Rebeca
clojurians
clojure
``` user=&gt; ((fn [x] ((x {:a {:a 1}}) x)) :a) 1 user=&gt; ``` might be interesting to puzzle out when learning about keywords
2017-12-15T15:19:43.000181
Rebeca
clojurians
clojure
anyone know why ```:1``` is a valid keyword but ```:foo/1``` is not?
2017-12-15T15:31:04.000518
Tuyet