Fork me on GitHub
#clojure
<
2019-09-15
>
Thomas Deniffel07:09:35

Hello! In coordination with the original authors, I am writing a Clojure Version of the legendary "Structure and Interpretation of Computer Programs" (SICP) since about one year. I expect to finish the first draft in a few months. Is anyone willing to review early versions? / Where should I ask this question? 🙂

🔥 12
8
jumar07:09:08

Hi, I'm happy to check that if you're interested.

jumar07:09:30

I think https://clojureverse.org and clojure mailing list may also be good places to ask

Thomas Deniffel08:09:19

nice, I add you to my list and notify you on updates

👍 4
tengstrand13:09:00

I may be interested!

jjttjj13:09:03

I'm interested

Thomas Deniffel14:09:37

great! I add you as well

Jakub Zika14:09:17

Me too, thanks.

Danny Almeida23:09:21

i would love to review it ...just recently started reading SICP, but would be fun to do it in clojure 🙂

Thomas Deniffel05:09:39

I will notify you on the progress 👍

johnj03:09:42

Original authors of SICP?

johnj03:09:33

for how long have you been using clojure?

Thomas Deniffel05:09:22

For a while now. Is the next question, how I handled TCO in Chapter 1.2? 😅

lread19:09:52

By coincidence, I am totally enjoying the MIT course on this right now https://www.youtube.com/playlist?list=PLE18841CABEA24090

lread01:09:12

Oh cool! Thanks!

roklenarcic13:09:58

Hey guys, I want to extend a protocol I have for some classes in case the person who loaded my library loaded also some other library

roklenarcic13:09:20

I used (Class/forName ... to check if the other library is present

roklenarcic13:09:53

but the problem is that my (extend-protocol sentence has direct references to the classes

roklenarcic13:09:00

which fails to compile

dominicm13:09:29

@roklenarcic you'll need to use a macro, clojure.core has examples of doing this.

dominicm13:09:04

it's called "when-class" and is private, but you could copy the implementation yourself.

vemv15:09:36

I've noticed that generally (not= (class (reify)), (class (reify))). I find this desirable behavior. However, certain contrived reify returned by a defn always returns the same class. It's as if the underlying reify's class was cached. Wondering what triggers this and how to control it?

vemv15:09:26

minimal repro 🙂

(defn foo []
  (let [a (atom {})]
    (reify)))

andy.fingerhut17:09:51

I haven't seen anything in reify's doc string that mentions the class of the returned objects, so it seems to promise nothing in that regard. Did you see anything about it?

vemv17:09:06

Funnily enough, the docstring doesn't say what reify is/does at all 🙂 I've always taken it as "make a class+object in runtime", but yeah, sure, there's no such contract.

andy.fingerhut17:09:27

I suspect if it had a sentence or three added saying what it does (yes, weird that is not there), it might be "make an object", but not mentioning class.

👍 4
emccue17:09:17

(eval `(reify Object)) should get you a unique class

vemv17:09:13

@emccue yes, but evaled code cannot access the let bindings. I tried to hack it with binding, but the bindings will be gone after reify evaluation (i.e., reify methods cannot access the eval-time binding)

hiredman18:09:09

The class returned by reify is generated at compile time, functions compiled once and invoked multiple times, so the class will always be the same

vemv18:09:41

Verified that my assumption was wrong, thanks @hiredman 🙂

borkdude18:09:28

is the ^int type tag deprecated in favor of ^long?

user=> (defn foo [^int x])
Syntax error (IllegalArgumentException) compiling fn* at (REPL:1:1).
Only long and double primitives are supported

vemv18:09:40

I would say that it's not deprecated, since you still can need ^int for avoiding reflection elsewhere defn primitive annotation has the stated constraint (`Only long and double primitives are supported`). That doesn't deprecate all the entries you can see in https://clojure.org/reference/java_interop#TypeAliases

hiredman18:09:22

It is complicated

hiredman18:09:45

You can only use long or double on function arguments

andy.fingerhut19:09:54

and as primitive return types.

andy.fingerhut19:09:03

and although the docs are a little lacking on this minor detail, you can only get in compiled code long or double primitives for loop-bound symbols. If you try to make it int, you get long instead. If you try to make it float, you get double instead.

emccue23:09:40

Are there any big gotchas with aot nowadays?

seancorfield23:09:30

The same as there always have been @emccue 🙂

seancorfield23:09:53

It's "OK" to do AOT on everything as the last step when building an uberjar if you want the startup time improvement it can bring, but most other cases can introduce problems so it's best avoided unless you must do some AOT (`gen-class` for example).

seancorfield23:09:22

And even for gen-class, the advice I seem to hear most is "use a Java shim instead" if you can (and use Clojure's "Java API" from that shim to load Clojure code).

seancorfield23:09:24

I have one project that relies on gen-class for one namespace and that has no dependencies outside clojure.core and clojure.string, and my deps.edn file looks like this

{:deps {org.clojure/clojure {:mvn/version "1.8.0"}}
 :paths ["classes" "src"]
 :aliases
 {:compile {:main-opts ["-e" "(compile,'cfml.struct)"]}
  :test {:extra-paths ["test"]
         :extra-deps {expectations/clojure-test {:mvn/version "1.1.1"}
                      org.clojure/test.check {:mvn/version "0.10.0-RC1"}}}
  :runner {:extra-deps {com.cognitect/test-runner
                        {:git/url ""
                         :sha "3cb0a9daf1cb746259dc8309b218f9211ad3b33b"}}
           :main-opts ["-e" "(compile,'cfml.struct)"
                       "-m" "cognitect.test-runner"
                       "-d" "test"]}
  :build {:extra-deps {seancorfield/depstar {:mvn/version "0.2.3"}}
          :main-opts ["-e" "(compile,'cfml.struct)"
                      "-m" "hf.depstar.jar" "cfml-interop.jar"]}}}
so it explicitly compiles that one ns for each top-level path in the aliases.

seancorfield23:09:03

(it's an implementation of clojure.lang.APersistentMap that has case-insensitive keys... because CFML...)

emccue23:09:41

Yeah, just considering it for making the uberjar for my class

emccue23:09:01

I talked the strangers I need to work with into using clojure so I'm pumped

💯 4
4