Fork me on GitHub
#beginners
<
2017-12-02
>
noisesmith06:12:24

that's not dereference, that's unquote-splicing

Wander06:12:23

[email protected] is an atom instead of combine two symbols?

noisesmith06:12:45

it is a reader macro - we don't use the term "atom" for that

noisesmith06:12:57

but yes, it 's a single reader macro with two characters

Wander06:12:38

see. thank you.

noisesmith06:12:20

hmm - maybe [email protected] should come before @ in that weird characters guide, so that if you are reading top to bottom you don't get misled...

rauh06:12:57

@wander4096 YOu can use read-string to see what the reader does with such forms ^

Wander06:12:58

thanks, though it displays the result with which I still know little about the underneath

Wander06:12:14

that is enough for me now, anyway

matan12:12:21

Does anyone recall why does clojure.test's is kind of fail to compare to false in cases like here?

user=> (is (= 1 2) false)

FAIL in () (form-init78938769099331712.clj:1)

expected: 1
  actual: 2

    diff: - 1
          + 2
         false

matan12:12:13

I know about the availability of using false? but still curious to recall

rauh12:12:04

@matan The syntax is: (is form message) 🙂

matan12:12:56

ah right! lol

New To Clojure15:12:03

@derpocious >lein test | grep Failed thanks!

Wander19:12:06

I wonder what nil-punning means( it’s only nil to me, no pun ), thus I reach http://www.lispcast.com/nil-punning#fn4

Wander19:12:20

it says “first has nothing to return if the seq is empty, and so it returns nil. Because nil is a seq, first works on nil, and returns nil. 6. rest works on nil as well, because nil is a seq.”

Wander19:12:43

(seq? ’()) ;; returns true

Wander19:12:57

(seq? nil) ;; returns false

noisesmith19:12:16

right, they are incorrect - nil is sequable but not a seq

noisesmith19:12:34

Clojure 1.9.0-RC1
+user=> (seqable? nil)
true
+user=> (seq nil)
nil
+user=> (filter even? nil)
()

noisesmith19:12:44

btw seq is a relatively limited type - many (most?) things we make seq out of are not seqs

+user=> (seq? [])
false

Wander19:12:49

that’s it. btw, how to create code snip like ^

noisesmith19:12:18

use ` - it's the same as markdown

Wander19:12:30

see. thank you

Wander19:12:33

=> (vector? [])
true
aha, is there type graph of clj?( I’m not sure if clj should have a ‘type graph’ )

noisesmith19:12:14

hmm... I think I know what you mean - you can look at things via supers - the way Clojure defines data types doesn't use nested inheritance or concrete inheritance - there's a number of Interfaces and Protocols (100% abstract) and a given data type implements some number of them

noisesmith19:12:20

so it's very flat, not much of a graph

noisesmith19:12:09

+user=> (pprint (supers (type [])))
#{clojure.lang.IPersistentCollection clojure.lang.IKVReduce
  java.lang.Runnable java.lang.Comparable clojure.lang.IHashEq
  clojure.lang.IPersistentVector clojure.lang.IMeta java.util.List
  clojure.lang.Seqable clojure.lang.IObj clojure.lang.Indexed
  clojure.lang.AFn java.util.Collection clojure.lang.APersistentVector
  clojure.lang.ILookup clojure.lang.Sequential clojure.lang.Counted
  clojure.lang.IReduce java.util.RandomAccess
  clojure.lang.IPersistentStack java.lang.Iterable
  clojure.lang.Associative java.io.Serializable
  clojure.lang.IEditableCollection clojure.lang.IFn
  clojure.lang.Reversible clojure.lang.IReduceInit java.lang.Object
  java.util.concurrent.Callable}
nil
+user=> (pprint (supers (type ())))
#{clojure.lang.IPersistentCollection clojure.lang.IHashEq
  clojure.lang.IMeta java.util.List clojure.lang.Seqable
  clojure.lang.IObj java.util.Collection clojure.lang.Sequential
  clojure.lang.Counted clojure.lang.IPersistentList
  clojure.lang.IPersistentStack java.lang.Iterable clojure.lang.ISeq
  java.io.Serializable java.lang.Object clojure.lang.Obj}
nil
+user=> (pprint (supers (type {})))
#{clojure.lang.IPersistentCollection clojure.lang.IKVReduce
  java.lang.Runnable clojure.lang.IHashEq clojure.lang.IMeta
  clojure.lang.Seqable clojure.lang.IObj clojure.lang.AFn
  clojure.lang.ILookup java.util.Map clojure.lang.IPersistentMap
  clojure.lang.Counted clojure.lang.APersistentMap java.lang.Iterable
  clojure.lang.Associative java.io.Serializable
  clojure.lang.IEditableCollection clojure.lang.IMapIterable
  clojure.lang.MapEquivalence clojure.lang.IFn java.lang.Object
  java.util.concurrent.Callable}
nil
+user=> (pprint (supers (type #{})))
#{clojure.lang.IPersistentCollection java.lang.Runnable
  clojure.lang.IHashEq clojure.lang.IMeta clojure.lang.Seqable
  clojure.lang.IObj clojure.lang.AFn java.util.Collection java.util.Set
  clojure.lang.Counted java.lang.Iterable java.io.Serializable
  clojure.lang.IEditableCollection clojure.lang.IFn
  clojure.lang.APersistentSet java.lang.Object
  java.util.concurrent.Callable clojure.lang.IPersistentSet}
nil

noisesmith19:12:26

the significance of each of the interfaces / protocols is that they each define a small number of methods, and the clojure built ins mainly use those methods

noisesmith19:12:50

@wander4096 you can look at the source to see what those do, but reflection can help too in the repl

+user=> (->> clojure.lang.Seqable (clojure.reflect/reflect) :members (map :name))
(seq)
+user=> (->> clojure.lang.IPersistentCollection (clojure.reflect/reflect) :members (map :name))
(count cons empty equiv)

noisesmith19:12:10

so that shows the names of the methods each of those interfaces define

noisesmith19:12:21

eg. clojure.core/conj is a function that calls the static method clojure.lang.Rt/cons which iirc calls the cons methodon IPersistentCollection

noisesmith19:12:21

aha - it uses the cons method, unless you give it nil, which it special cases to make a list (looping back to thestart of the convo) https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L667

noisesmith19:12:15

@wander4096 as an aside, things like this are why I get pedantic when people use the terms function and method interchangeably - it makes talking about how this stuff works harder than it needs to be

noisesmith19:12:31

then again, I think I am well out of "beginners" territory now - oops sorry for going off topic

noisesmith19:12:37

so on a less detailed / implementation level, and a more abstract introductory level: the way I think of them, clojure's types don't form a graph, they each have a subset of the clojure interfaces they implement (maybe it would be useful to make a graph with edges for each shared interface between the types though? not sure)

alexmiller20:12:07

I think this is a good way to think about them: interfaces are sharded traits where concrete classes implement the necessary traits. A fun thing to contemplate is whether the ideal number of methods per trait should be 1.

alexmiller20:12:10

and I have one in ch 2 of Clojure Applied that is tailored specifically to the collection apis and their mapping to the polymorphic collection functions in core

New To Clojure20:12:48

Hey folks, how to create anonymous function which returns it's parameter unchanged? (#(%) "a") throws ClassCastException java.lang.String cannot be cast to clojure.lang.IFn unfortunately.

noisesmith20:12:23

@ghsgd2 the function identity does this, but we can look at why that happens too

noisesmith20:12:44

+user=> '#(%)
(fn* [p1__231#] (p1__231#))

noisesmith20:12:09

#() expands to an anonymous function (I used ' to quote it above so that we would see the reader expansion instead of just the function that is generated)

noisesmith20:12:27

if we rename the weird variable, we get (fn [x] (x))

noisesmith20:12:41

if it didn't expand that way, #(println %) would break - maybe it would need to be #((println %))` which is weird

noisesmith20:12:46

+user=> '#(println %)
(fn* [p1__234#] (println p1__234#))

New To Clojure20:12:50

('#(%) 1)
ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.IFn
looks like the only way is to use (fn [x] (x)) or identity. Thank you @noisesmith!

noisesmith20:12:09

@ghsgd2 to be clear, what ' does, is it prevents evaluation

noisesmith20:12:18

so it returns a list, instead of compiling that list

noisesmith20:12:37

so '(fn [x] (f x)) isn't a function, it's a list that would make a function if we evaluated it

New To Clojure20:12:25

>so it returns a list, instead of compiling that list I know, it's just not clear where to put quote to avoid treating x or % as a function instead of return value. oh,

((fn [x] (x)) 1)
ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn

New To Clojure20:12:02

now it works! 🙂

> ((fn [x] x) 1)
1

Wander20:12:22

@noisesmith thanks a lot.

noisesmith20:12:39

@ghsgd2 right, () indicates you want to call something, except when unevaluated it gives you a list, but to use a value instead of calling or making a list containing its name you can use the item without the parens

noisesmith20:12:10

And #() inserts parens so that things like #(f %) work as expected

Bravi23:12:19

how can I make an http call in ring and return the result to the client? when I do this

(defn get-orders [req]
  (let [{:keys [sig uri]} (api-signature :get-orders)]
    (client/get uri
                {:async? true}
                (fn [response] {:body "something"})
                (fn [exception] {:body "error"}))))
it gives me this error
No implementation of method: :render of protocol: #'compojure.response/Renderable found for class: org.apache.http.impl.nio.client.FutureWrapper

seancorfield23:12:26

@bravilogy I answered that in #clojure -- feel free to follow-up in either channel (but not both).

gilmar23:12:59

Hello guys… Are you have meetup in your country?

gilmar23:12:22

Are you work using clojure?

seancorfield23:12:34

Hi @linux.soares! I live in the San Francisco Bay Area and we have a couple of Clojure meetups every month, and many companies here are using Clojure in production...

raheel23:12:49

hi Sean: are these in Palo Alto? anything in SF or east bay?

seancorfield23:12:17

...my company has had Clojure in production since 2011 and we have about 75,000 lines of Clojure code now (about 20,000 is tests).

seancorfield23:12:11

Where are you based? Six hours time difference... so Brazil?

gilmar23:12:54

Thanks @seancorfield. I live in Brazil, São Paulo. In my company we are using Python in 90% of systems. There is a meetup here, but only from Scala, Python that I know… I’m thinking of starting a Clojure meetup around here. I wanted to know how the adoption is outside Brazil.