This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-19
Channels
- # aws-lambda (1)
- # bangalore-clj (4)
- # beginners (66)
- # boot (13)
- # cider (9)
- # cljs-dev (44)
- # cljsjs (3)
- # clojure (181)
- # clojure-austin (2)
- # clojure-greece (6)
- # clojure-italy (2)
- # clojure-russia (64)
- # clojure-sg (1)
- # clojure-spec (68)
- # clojure-uk (60)
- # clojurescript (66)
- # conf-proposals (12)
- # cryogen (1)
- # cursive (3)
- # datomic (44)
- # graphql (1)
- # hoplon (2)
- # jobs (2)
- # jobs-discuss (3)
- # keechma (2)
- # liberator (6)
- # luminus (2)
- # nyc (1)
- # off-topic (92)
- # om (10)
- # onyx (17)
- # parinfer (39)
- # pedestal (8)
- # proton (11)
- # re-frame (110)
- # reagent (2)
- # remote-jobs (11)
- # ring-swagger (9)
- # rum (2)
- # sql (2)
- # test-check (6)
- # untangled (138)
in this macro, into []
is slow. But if it's a sequence, it would try to evaluate and get an error. Is there a better solution for this?
@jiyinyiyong (vec children)
might work faster I guess.
dominicm: https://stackoverflow.com/a/12044502/883571 it sounds like they are the same
For small lists, vec has different behaviour. It will do less work based on my reading there.
have you imported the Math namespace? Or does the Math package you imported have a round function?
Yeah I was passing it like (get-point-percentage 19/20)
. So its either (get-point-percentage 0.95)
or (get-point-percentage (float 19/20))
. Thanks @guy
so it’s Math/round vs. math/round
and use double
instead of float
for floating point coercion btw
unless you really prefer 32 bit precision over 64
right
because ratio doesn’t implement an interface that the Math lib understands
funny that things in java.lang.Math wouldn’t know what to do with a java.lang.Number, but there we go
Btw, @simon #(:distance %)
is redundant, could be just (into [] (map :distance tryme3))
i have a bug that’s hard to debug because i represented some app state as anonymous functions and java objects. for example: this
{:name "cash" :amount 5000 :contribution-period (fn [date] (time/plus date (time/months 1))) :start (time/date-time 2017 6 1) :contribution-counter (time/date-time 2017 6 13)}
when entered into the repl, is this
{:name "cash", :amount 5000, :contribution-period #function[user/eval52021/fn--52022], :start #object[org.joda.time.DateTime 0x287be984 "2017-06-01T00:00:00.000Z"], :contribution-counter #object[org.joda.time.DateTime 0x5ac23eaf "2017-06-13T00:00:00.000Z"]}
say i want to do
(def fixture-data {:name "cash", :amount 5000, :contribution-period #function[user/eval52021/fn--52022], :start #object[org.joda.time.DateTime 0x287be984 "2017-06-01T00:00:00.000Z"], :contribution-counter #object[org.joda.time.DateTime 0x5ac23eaf "2017-06-13T00:00:00.000Z"]})
i get a bunch of runtime exceptions saying unmatched delimiter: )
and ]
which are from the #object[...
I can’t see a theoretical justification for forbidding the reader from reading anonymous things. And because this is a LispReader$ReaderException
, i’m inclined to think that this is the reader not being sophisticated-enough to handle an object’s and anonymous function’s syntax. Am I off base?Yes, the reader can’t read back arbitrary objects and functions.
I mean, yes, you’re right 🙂
why not? i mean, they’re there. i tried googling for an explanation from an authoritative source, and couldn’t find one.
clojure functions aren’t intended to be readable, it’s simply not a supported feature. the object identity will be a different hex code on each recompile, which will usually be each run of your code
very well. the mere fact that my app-state is now full of #objects
and #function
s was giving me pause. i’ll grudgingly do something else. thanks! : )
if you convert the joda.time.DateTime to a java.util.Date that does serialize
or you could add a data reader for that type I guess
FWIW, I've been there before. I once had this grand plan to pass around function objects as a cheap way of doing distributed computing. Unfortunately it was a bust. Functions aren't quite as serializable as it sometimes seems they should be in a lisp.
You could pass around code as data, then eval it when you want to use it. {:some-fn '(fn [x] (inc x))}
. You'd need some way of specifying the environment, requires, etc though. IIRC that's what datomic does for database functions.
Also, in my plan, you'd write your code like normal and it would get converted into data on the fly. That turned out to be not so straight-forward.
So it would kind of suck to have to write your code as lists first. It would be another layer of misdirection.
At the time (this is an old project) I was hoping for a lisp that would be a theoretically fully serializable environment.
whats the difference between a macro and a function. i.e. why are and
and for
macros and not functions?
Macros don’t evaluate their arguments, but functions do. This is useful for forms like and - because it only evaluates the arguments until it finds one false. And one false in series of arguments to “and”, will generate a false
The main difference however is, macros generate code that is evaluated, while functions are evaluated outright
@vitruvia In the expression, (and (= 1 1) (= 2 3) (= 3 4)) only expressions until (= 2 3) are evaluated (and they are evaluated left to right) - because (= 2 3) is false, the evaluator doesn’t even get to look at (= 3 4)
You can imagine a more complex expression, that for example generates 100 digits of pi and checks it against this value in the arguments - (= (generate-pi 100) 3.14……….)
In this case generate-pi will never be called, saving the cpu time
You can use macroexpand-all
to see the full output of a macro too: https://clojuredocs.org/clojure.walk/macroexpand-all