> and Clojure’s syntax is pretty limited Erm, what? I am confused by the use of the word 'limited' in this context.
I confirm: the syntax is limited. There are only a few keywords and langage constructs. The power is in the number of functions made available, or the ones you create for yourself.
Learning Clojure: comparing with Java streams
11–20 of 46 posts
Re: Learning Clojure: comparing with Java streams
#12Earlier quoted context omitted.
I confirm: the syntax is limited. There are only a few keywords and langage constructs. The power is in the number of functions made available, or the ones you create for yourself.
Doesn't Clojure have reader macros? The whole point of lisps is that you can extend them.
Re: Learning Clojure: comparing with Java streams
#13The equivalent of `flatMap` is not `flatten`. Semantically `flatMap` is equivalent to `(comp flatten map)` – hence the name! – but Clojure does offer it as a single function named `mapcat` (”map and catenate”).
With the caveat that `flatten` is recursive and can handle a mix of collections and non-collections, while `mapcat` is non-recursive and every value returned by the mapcatted function must be a collection or nil.
(Identity returns its argument.)
(flatten [1 [2 3] [[4 5 6]]])
> [1 2 3 4 5 6]
(mapcat identity [1 [2 3] [[4 5 6]]])
> IllegalArgumentException Don't know how to create ISeq from: java.lang.Long
(mapcat identity [[1] [2 3] [[4 5 6]]])
> (1 2 3 [4 5 6])
(flatten [nil [1 2 3]])
> (nil 1 2 3)
(mapcat identity [nil [1 2 3]])
> (1 2 3)Re: Learning Clojure: comparing with Java streams
#14The equivalent of `flatMap` is not `flatten`. Semantically `flatMap` is equivalent to `(comp flatten map)` – hence the name! – but Clojure does offer it as a single function named `mapcat` (”map and catenate”).
Re: Learning Clojure: comparing with Java streams
#15Earlier quoted context omitted.
I confirm: the syntax is limited. There are only a few keywords and langage constructs. The power is in the number of functions made available, or the ones you create for yourself.
Doesn't Clojure have reader macros? The whole point of lisps is that you can extend them.
Re: Learning Clojure: comparing with Java streams
#16Earlier quoted context omitted.
Doesn't Clojure have reader macros? The whole point of lisps is that you can extend them.
Actually, Clojure does not have reader macros, because it was thought to be the biggest cause of the lisp curse.
Re: Learning Clojure: comparing with Java streams
#17> and Clojure’s syntax is pretty limited Erm, what? I am confused by the use of the word 'limited' in this context.
Re: Learning Clojure: comparing with Java streams
#18> and Clojure’s syntax is pretty limited Erm, what? I am confused by the use of the word 'limited' in this context.
No pun intended, by "value" I mean "things that are worthwhile". Clojure is totally into "values". :-D
Re: Learning Clojure: comparing with Java streams
#19Also, this bit: (->> justice-league (map #(:vehicles %)) (filter #(not (nil? %))) (flatten)) can be simplified to just `(mapcat :vehicles justice-league)`
- Keywords (i.e. `:vehicles`) can be used as getter functions, as covered in the OP.
- mapcat (like most collection functions in clojure) treats `nil` as an empty sequence
Re: Learning Clojure: comparing with Java streams
#20Earlier quoted context omitted.
Actually, Clojure does not have reader macros, because it was thought to be the biggest cause of the lisp curse.
Nit: Clojure does not have user-defined reader macros. There are quite a few built-in reader macros, including #? added for reader conditionals.