Fork me on GitHub
#beginners
<
2016-03-29
>
mbarbieri09:03:49

Hi, I'm going to give a brief Clojure introduction (20/30 mins) in a local meetup. Any advice about what to tell, reference slides etc? Audience are devs, both backend and frontend, various languages. Main goal I think should be to try raise interest on it

rauh09:03:59

@mbarbieri: cognitect has on their github a gorilla repl project: https://github.com/cognitect/clojure-lab/

slipset09:03:15

@seancorfield: one could maybe argue that having (reverse “hello”) => “olleh” be the default would be a better solution than having a surprising default which is a wee bit faster

slipset09:03:28

I also guess that if Clojure were implemented in terms of protocols, you’d have IReversible (which does exist in Clojurescript) which could be extended to java.lang.String at a slight performance penalty

seancorfield14:03:44

@slipset: I believe there’s a strong argument that "everyone" shouldn’t be forced to pay for "someone" else’s performance — so reverse being "as fast as possible" on sequences at the expense of needing clojure.string/reverse is reasonable.

seancorfield14:03:05

That’s probably more applicable to other core functions than to reverse but I suspect if Rich had the chance to "do over" there would be no core functions that worked on strings (except "by accident") and all the string functions would be in clojure.string instead…?

slipset15:03:25

I see your point, but it'd be interesting to see some benchmarks. Also in cljs it seems to me that we're already dispatching on type, so including string shouldn't be that much of a penalty.

seancorfield15:03:25

But you want functional compatibility between Clojure and ClojureScript so that you can reuse code via cljc files. Having reverse work on strings in ClojureScript but not Clojure would be a dangerous trap.

seancorfield15:03:57

If you think it's a worthwhile change -- in both languages -- you should advocate to Clojure/core about it. But unless I'm misreading some of their comments about string handling vs collection handling, I don't think they'll accept it.

seancorfield15:03:09

The issue is that a lot of collection functions work on strings-as-sequences but produce sequences as results. Consider map for example, which takes any collection as input but produces a sequence: (map inc [1 2 3]) is (1 2 3), not [1 2 3]. Same with filter and many others. Clojure isn't a type-preserving language (in the same way that Scala's collections library aims to be).

seancorfield15:03:34

If you argue that (reverse "Hello") should produce "olleH", then it's reasonable to argue that (map Character/toUppercase "Hello") should produce "HELLO" -- but that's starting down the path of changing a lot of functions...

seancorfield15:03:24

...and if (map char-func some-string) preserves the type of the collection (`String`) then folks will argue that (map some-func some-vector) should also preserve the type and produce a vector and so on.

urbanslug16:03:46

Isn’t there something like is-not on clojure?

seancorfield17:03:48

Not sure what you mean? There's not and complement and things like if-not and when-not...