Live data from Hacker News

Clojure by Example (2015)

kimh.github.io

41–46 of 46 posts

Re: Clojure by Example (2015)

#41
post #33

Earlier quoted context omitted.

You need to be familiar with Java types and differences between them (Integer, BigInteger) and how Math.pow() behaves with different types. This is more up to Java, rather than Clojure. No need to pull the library for this, Clojure already has (biginteger) for that: user=> (.pow (biginteger 33) 33) 129110040087761027839616029934664535539337183380513

Didn't Clojure use the N suffix for big integers at one point? I don't see one on that output.

The N suffix is for clojure.lang.BigInt, which are created with (bigint) which was added in Clojure 1.3 and still work to this day (I did these examples in the latest 1.10.3 release)

  user=> (bigint "129110040087761027839616029934664535539337183380513")
  129110040087761027839616029934664535539337183380513N
  
  user=> (type *1)
  clojure.lang.BigInt
The Java-platform bigint is java.lang.BigInteger which are created with (biginteger) which was added in Clojure 1.0. Printing one of these will not include an N suffix:

  user=> (biginteger "129110040087761027839616029934664535539337183380513")
  129110040087761027839616029934664535539337183380513
  
  user=> (type *1)
  java.math.BigInteger
Clojure BigInts are supposed to involve less unboxing and therefore be more performant. If you provide an integer literal that's too large to fit in a java.lang.Long, the reader will use a BigInt instead:

  user=> 129110040087761027839616029934664535539337183380513
  129110040087761027839616029934664535539337183380513N
  
  user=> (type *1)
  clojure.lang.BigInt
  
  user=> 12345
  12345
  
  user=> (type *1)
  java.lang.Long
If all this seems like a mess, well it sort of is. Clojure has a very strong commitment to backwards compatibility, so when the Clojure-specific big int representation was added, the old JDK-based one was not removed, because the operations that the two support are different.

Re: Clojure by Example (2015)

#42
post #19
post #8

Earlier quoted context omitted.

The very next sentence of the article points out that you can leverage Clojure's interop to invoke Math.pow(), but that's still limited to casting its arguments down to java.lang.Double and suffering the limits therein If you instead used the library org.clojure/math.numeric-tower [1] you can get much more precise answers, for example # start a repl with an extra dep $ clj -Sdeps '{:deps {org.clojure/math.numeric-tow…

> The very next sentence of the article points out that you can leverage Clojure's interop to invoke Math.pow() Hum, ok, to my defense it's not the very next sentence, it's much later at the very end when talking about Method invocation, so I hadn't read that far. +1 for linking to the numeric tower though

My apologies. I searched for Math/pow, saw that the sentence there started with "Clojure doesn't", and missed that we were looking at two different parts of the document :)

Re: Clojure by Example (2015)

#43
post #10

Earlier quoted context omitted.

For sure, but “Clojure doesn't provide built-in function for exponential operation” is still an objectively true assertion. If your point is that it’s wrong in spirit, I totally agree, and I think this is yet another example of the limits of this “cheat sheet” approach. If you’re coming from another language, the concept of easy, well integrated interop with a host language platform would be fairly foreign, so the im…

Think it might just be quibbling on the nature of 'built-in' at that point.

Well yes hence the “/pedantic” tag. I was quibbling with someone who went out of their way to “correct” a true fact. Quibbling with quibbling if you will. Sort of like you’re doing. But hey they started it ;)

Re: Clojure by Example (2015)

#44
post #18
post #6

Learning a new language by mapping constructs from another language you know better is certainly expedient. But the trade off is you short change yourself on learning core philosophical beliefs underpinning the design of the language. Understanding these poorly means you will not exploit the language very well and arguably should just stick with the prior language. Clojure more than most languages is built around som…

Are there any other resources that you'd recommend to people coming from languages like Python or JavaScript? I'm assuming 'Clojure for the Brave and True'?

Yes, I came from python and ruby and that book helped me a lot. You can read or free on the website, I also bought the Apple Books version.

I’d second the person who suggested watching some Rich Hickey talks on YouTube, or at least trying one and seeing if it agrees with you (that is, don’t force it if you’re miserable 10m in but I find him a compelling speaker and others seem to as well).

In descending order of preference I’d suggest (all are on YouTube):

- Effective Programs - 10 years of clojure (great overview of overall thinking behind clojure, touches a lot of key points, and a fun talk)

-Are We There Yet - this one resonated with me but not in most people’s top lists it would seem - a head on critique of OOP and dive into what makes functional and Clojure in particular better

-Simple Made Easy 2011 (there’s a 2012 where the audience is kind of a drag) - one of his most popular, his vision of what simplicity really means and how to achieve it in code

-the value of values - deep dive on clojures data philosophy

Re: Clojure by Example (2015)

#45
post #36
post #18

Earlier quoted context omitted.

Are there any other resources that you'd recommend to people coming from languages like Python or JavaScript? I'm assuming 'Clojure for the Brave and True'?

At work we would give new hires "Living Clojure". There is also the site https://www.4clojure.com/ if you are looking to do some exercises.

If you're comfortable sharing, where do you work that uses Clojure? I'm still a bit junior myself (Java dev), but I've been interested in FP and especially LISP for a while

Re: Clojure by Example (2015)

#46
post #36

Earlier quoted context omitted.

At work we would give new hires "Living Clojure". There is also the site https://www.4clojure.com/ if you are looking to do some exercises.

If you're comfortable sharing, where do you work that uses Clojure? I'm still a bit junior myself (Java dev), but I've been interested in FP and especially LISP for a while

I'm sorry but I am not comfortable sharing, however, here is a list of companies that I know use Clojure.

- Arena Analytics: https://arena.io/

- Reify Health: https://www.reifyhealth.com/

- Guaranteed Rate: https://www.rate.com/

- OppLoans: https://www.opploans.com/

- LookingGlass Cyber Solutions: https://lookingglasscyber.com/

I also believe that DRW (https://drw.com/) also use Clojure but not 100% sure on that. I know they use some Elixir though.

Post reply on HN