This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-22
Channels
- # beginners (8)
- # boot (41)
- # cider (1)
- # cljsrn (2)
- # clojure (91)
- # clojure-dev (34)
- # clojure-gamedev (3)
- # clojure-germany (6)
- # clojure-greece (324)
- # clojure-japan (2)
- # clojure-miami (4)
- # clojure-nl (6)
- # clojure-quebec (3)
- # clojure-russia (26)
- # clojure-spec (50)
- # clojure-uk (19)
- # clojurescript (147)
- # core-async (5)
- # css (2)
- # cursive (15)
- # datascript (7)
- # datomic (6)
- # hoplon (1)
- # jobs (4)
- # lein-figwheel (17)
- # off-topic (4)
- # om (52)
- # om-next (10)
- # onyx (1)
- # planck (19)
- # proton (1)
- # re-frame (81)
- # reagent (61)
- # spacemacs (1)
- # specter (46)
- # spirituality-ethics (7)
- # untangled (7)
- # yada (17)
am I missing something or should inst-ms
return an #inst ...
literal?
user> (type (inst-ms (new java.util.Date)))
java.lang.Long
user> (inst? (inst-ms (new java.util.Date)))
false
user>
the number of something is another way of saying the "count" of something, and the count of something is a number
why is that?
(read-string "04")
=> 4
(read-string "09")
NumberFormatException Invalid number: 09 clojure.lang.LispReader.readNumber (LispReader.java:330)
Numbers prefixed with 0 are octal numbers, same as in Java:
(read-string "07")
=> 7
(read-string "010")
=> 8
@andmed: for shits and giggles, try ping 010.010.010.010
from your terminal
@pesterhazy: google everywhere
i'm considering going that route since it would be great for quick debugging purposes
but at the same time, i feel like it's a huge risk, in the same way that logging into your production db is
we use it occasionally. most of the times, it's to transact something once-off into the Datomic db
or to compile extra logging into a function to debug something
@lmergen: it's a huge risk if you have people on the team that you can't trust or you're exposing the REPL port in the prod deployment
you can close the repl port to outside access and only allow access through an ssh tunnel
I don’t know if this has been discussed before, but does the behaviour of every?
strike anyone else as odd?
the only two values every?
can return are true
and false
on nil/empty coll you either return true
or false
, but the "issue" will be the same in any case
usually when no meaningful value can be returned, those types of functions/macros return the identity value for that operation, which is true
in this case
If you treat the collection as a zero-length collection, it means the predicate has been executed 0 times, right? Whatever the returned boolean might be.
@okal: disjunction (AND) over an empty set should be true, yes
I feel (fuzzy word, I know) that it should behave differently on the opposite. But I see your point on how no meaningful value can be returned here.
there's many ways to look at the question of why that is, but it's accepted by all logicians
@val_waeselynck: Hm. I didn’t know that. Thanks.
Yes. I’ve only just realised that. Which is what I meant by “no meaningful value can be returned"
Still wonder if there’s a way to indicate that fact than to return somewhat misleading information.
Thanks @val_waeselynck Makes perfect sense now.
ok, I surrender. This programming of yours is complicated as hell. I’m trying to do simple thing (at least I thought so at the beginning) -> open ssh connection to remote server and use it to run some bash scripts. To be exact plan was(and still is ) to: 1. Connect to ssh 2. Run command and get response imidiatly line by line, and not after command will return on the server 3. Keep session and shell channel alive for some amount of time (say 5 min) 4. If user wants to send more commands to server then same session and shell channel is used(if it is in )
But still i surrender, get berried under streams and buffers and Pipedstreams and channels
@ilukinov: did you try https://github.com/hugoduncan/clj-ssh?
I mean:
(let [agent (ssh-agent {})]
(let [session (session agent "host-ip" {:strict-host-key-checking :no})]
(with-connection session
(let [result (ssh session {:in "echo hello"})]
(println (result :out)))
(let [result (ssh session {:cmd "ls"})]
(println (second result)))))))
@dm3, those idioms are great, didn't know that not-empty returns coll if not empty (also didn't occur to me to use seq in conjunction with or)
In core.match
, list
syntax is reserved, is there still a way to match on a list
? (eg, not a vec
)
for reference:
> The list syntax () is reserved for special uses. It does not match a literal list.
(let [val '(:a)] ; doesn't work
(match [val]
['(:a)] "A"
['(:b)] "B"))
(let [val '(:a) ; does work
val (vec val)]
(match [val]
[[:a]] "A"
[[:b]] "B"))
Never mind, I just found the :seq
tag, that could be more obvious, but it works!:
for those who were wondering:
(let [val '(:a)]
(match [val]
[([:a] :seq)] "A"
[([:b] :seq)] "B"))
I just made a helper function for cider
, cider-eval-next-sexp
, I've been craving this functionality for a while, and hopefully it helps someone else's efficiency!
(defn swap-elements [element-a element-b coll]
(let [index-a (.indexOf coll element-a)
index-b (.indexOf coll element-b)]
(assoc coll index-b (coll index-a) index-a (coll index-b))))
(defn min-val-in-first-position [[x & more :as all]]
(loop [loop-ls all loop-rest more]
(let [first-position (first loop-ls)
next-position (first loop-rest)]
(if (empty? loop-rest)
loop-ls
(if (< first-position next-position)
(recur loop-ls (rest loop-rest))
(recur (swap-elements first-position next-position loop-ls) (rest loop-rest)))))))
(defn selection-sort [ls]
(loop [loop-ls ls loop-rest ls last-sorted []]
(let [[y & more-y] loop-ls
sorted (conj last-sorted y)]
(if (= 1 (count loop-rest))
sorted
(recur (min-val-in-first-position (vec more-y)) (rest loop-rest) sorted)))))
(selection-sort [1 2 5 6 673 2 678 5 4000 12 3])
@lewix this is an implementation of https://en.wikipedia.org/wiki/Selection_sort?
now I'm gonna try and compare my solution with others out there. I haven't had a look how it's usually implemented either
Yeah, I'll second the Joy of Clojure recommendation! It's not intended as a first Clojure book but it's great for the "why" of Clojure and thinking functionally once you have the basics under your belt!
perhaps not the right channel to ask this, but I cannot find an example of how to do this in prismatic/schema - anyone know? test {:some-shape s/Num (optional :key value)}
?
you mean you want the :key
to be optional?
so :some-shape
is a required key, but :key
is not?
and the value for :key might be a whole ‘nother schema (but that’s irrelevant I think)
yeah, there's an example here assuming I understand what you want: https://github.com/plumatic/schema#map-schema-details
{(s/optional-key :foo) s/Keyword
s/Str s/Str})
heh, oops. i got so caught up in cond-pre and pred, etc. that i wasn’t looking for the obvious.
huh, so apparently type hints work fine if they’re symbols? I.e. the compiler can resolve both actual types and symbols?
the compiler, if I recall, and Bronsa will correct if I don't, effectively calls resolve on type hints, which for symbols will resolve to a class through the current value of ns
which results in things like foo in (def ^boolean foo true)
having a :tag
it its metadata that is the clojure.core/boolean function