Fork me on GitHub
#clojure
<
2016-06-22
>
bsima00:06:51

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>

bsima00:06:07

clojure 1.9alpha7

hiredman00:06:45

the doc string says it returns the number of milliseconds since the epoch

bsima00:06:12

i suppose it does

hiredman00:06:20

the number of something is another way of saying the "count" of something, and the count of something is a number

bsima00:06:42

mm, okay, I misunderstood, thanks hiredman

hiredman00:06:13

also, to get pedantic, nothing can return a literal of anything

hiredman00:06:58

a "literal" is a sort of serialized representation of a thing

andmed05:06:25

why is that?

(read-string "04")
=> 4
(read-string "09")
NumberFormatException Invalid number: 09  clojure.lang.LispReader.readNumber (LispReader.java:330)

alfkristian06:06:30

Numbers prefixed with 0 are octal numbers, same as in Java:

(read-string "07")
=> 7
(read-string "010")
=> 8

pesterhazy07:06:44

@andmed: for shits and giggles, try ping 010.010.010.010 from your terminal

andmed07:06:35

@pesterhazy: google everywhere

lmergen09:06:25

do people actually use a REPL for production servers? why/why not?

lmergen09:06:44

i'm considering going that route since it would be great for quick debugging purposes

lmergen09:06:09

but at the same time, i feel like it's a huge risk, in the same way that logging into your production db is

robert-stuttaford09:06:31

we use it occasionally. most of the times, it's to transact something once-off into the Datomic db

robert-stuttaford09:06:47

or to compile extra logging into a function to debug something

dm311:06:01

@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

lmergen11:06:30

yes, but that's also the case for, say, a database port, right?

lmergen11:06:45

in that sense, is it safe to say that the two are somewhat equal?

dm311:06:48

databases have authentication

dm311:06:54

(the good ones)

lmergen11:06:09

ah yes that is correct

Chris O’Donnell11:06:14

you can close the repl port to outside access and only allow access through an ssh tunnel

okal13:06:52

I don’t know if this has been discussed before, but does the behaviour of every? strike anyone else as odd?

okal13:06:21

It means (every? nil? nil) and (every? #(not (nil? %)) nil) both return true.

bronsa13:06:57

what's the alternative?

okal13:06:24

@bronsa Is that addressed at me, or the earlier discussion?

bronsa13:06:16

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

okal13:06:34

Let me explain my thinking

bronsa13:06:24

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

okal13:06:37

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.

val_waeselynck13:06:12

@okal: disjunction (AND) over an empty set should be true, yes

okal13:06:42

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.

val_waeselynck13:06:46

there's many ways to look at the question of why that is, but it's accepted by all logicians

okal13:06:52

Perhaps nil?

okal13:06:06

@val_waeselynck: Hm. I didn’t know that. Thanks.

bronsa13:06:24

@okal: what you'd like is impossible

okal13:06:46

Yes. I’ve only just realised that. Which is what I meant by “no meaningful value can be returned"

okal13:06:33

Still wonder if there’s a way to indicate that fact than to return somewhat misleading information.

okal13:06:18

Thanks @val_waeselynck Makes perfect sense now.

ilukinov13:06:25

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 )

ilukinov13:06:12

well, that was sent before I ended writing it

dm313:06:51

is there an idiom like (or (seq possibly-empty-coll) default-coll) but for maps?

dm313:06:32

not-empty!

ilukinov13:06:50

But still i surrender, get berried under streams and buffers and Pipedstreams and channels

ilukinov13:06:31

yes used that one

ilukinov13:06:39

Cant figure out how to send another cmd to opened 'shell-chanel’

dm313:06:52

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)))))))

dm313:06:15

does it work if you use the snippet from the readme?

ilukinov13:06:47

yes it works

pesterhazy16:06:19

@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)

josh.freckleton16:06:21

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.

josh.freckleton16:06:30

(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"))

josh.freckleton17:06:27

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"))

josh.freckleton20:06:13

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!

lewix20:06:54

feedbacks please

lewix20:06:36

(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])

lewix20:06:50

nwjsmith: an attempt

nwjsmith20:06:39

Awesome, I'll play around with it, the code seems really clear.

nwjsmith20:06:10

Have you seen the lazy quicksort in the Joy of Clojure book?

lewix20:06:12

nwjsmith: I haven't read the book

nwjsmith20:06:36

I mention it because I think it might be possible to have a lazy selection sort

lewix20:06:54

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

lewix20:06:26

nwjsmith: I see, would you recommend the book?

nwjsmith20:06:34

@lewix: Absolutely, yeah, it's a great book

seancorfield21:06:06

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!

lwhorton22:06:19

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)}?

lwhorton22:06:42

where my ‘root shape’ can have a key/val pair

ddellacosta22:06:42

you mean you want the :key to be optional?

ddellacosta22:06:01

so :some-shape is a required key, but :key is not?

lwhorton22:06:16

and the value for :key might be a whole ‘nother schema (but that’s irrelevant I think)

ddellacosta22:06:44

yeah, there's an example here assuming I understand what you want: https://github.com/plumatic/schema#map-schema-details

ddellacosta22:06:55

{(s/optional-key :foo) s/Keyword
  s/Str s/Str})

lwhorton22:06:34

heh, oops. i got so caught up in cond-pre and pred, etc. that i wasn’t looking for the obvious.

lvh22:06:08

huh, so apparently type hints work fine if they’re symbols? I.e. the compiler can resolve both actual types and symbols?

lvh22:06:17

although those are obviously not equivalent

hiredman22:06:41

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

hiredman22:06:01

which results in things like foo in (def ^boolean foo true) having a :tag it its metadata that is the clojure.core/boolean function

hiredman22:06:52

user=> (def ^boolean foo true)
#'user/foo
user=> (meta #'foo)
{:tag #object[clojure.core$boolean 0x56928307 "clojure.core$boolean@56928307"], :line 1, :column 1, :file "NO_SOURCE_PATH", :name foo, :ns #object[clojure.lang.Namespace 0x4b23c30a "user"]}
user=> 

hiredman22:06:07

had to double check and make sure I did remember that