Fork me on GitHub
#beginners
<
2018-04-02
>
schmee12:04:58

@elena.caraba in Clojure only false and nil are considered falsey, so if coll is empty (count coll) returns 0, which is truthy

Elena12:04:35

Is there a way to still use if-let?

schmee12:04:45

probably, but I would just write a separate let and if statement 🙂

Elena12:04:41

Got it! Thank you @schmee

danielo51513:04:03

I just created a stack-overflow question detailing my problems at organizing cljs code, if anyone wants to help me there I will be very grateful

sundarj23:04:48

defn is a macro that expands to def + fn. if you don't want to create a top-level function, you can just use fn by itself.

boot.user=> (macroexpand '(defn foo [] 42))
(def foo (clojure.core/fn ([] 42)))

sundarj00:04:22

it is quite possible to write the equivalent clojurescript to that javascript

sundarj00:04:11

(fn [name] (.get client (str "resources/" name)) could also be replaced with #(.get client (str "resources/" %)) for extra concision

sundarj00:04:11

partial itself returns an anonymous function with fn (you can do (source partial) in a repl to see that)

cesarmarinhorj14:04:52

Hi all....swapping from php and wanna do my web work with clojure. What's the best framework for something like a blog...luminous, pedestal, other? Thanks

Alex Miller (Clojure team)14:04:05

but may be too good if your goal is to build a web app :)

cesarmarinhorj14:04:25

I loved it...thanks! It has plugins? I could not found ones...

cesarmarinhorj14:04:13

Which one did you use???? For web app....

cesarmarinhorj14:04:18

I saw that luminus has great acceptance in github. Compojure is great too... :-)

leongrapenthin14:04:24

Write a (defn not-zero [x] (if-not (zero? x) x)), then (if-let [x (not-zero x)] ...)

👍 4
manutter5115:04:00

I would not do this personally, but just for the fun of the challenge, you could do

(if-let [coll-count (and (seq coll) (count coll))] ...

manutter5115:04:01

If all the arguments to and are non-nil, it returns the last arg, but if you pass an empty collection to seq it will return nil, which will cause the and to short-circuit and return nil.

manutter5115:04:32

The reason I would not actually do that is because a month from now, I just know I’d come back to that code and wonder why the heck I was using that odd construction. An if-let inside a let would be much easier to read and quicker for me to understand as a code maintainer.

👍 4
Elena15:04:20

@manutter51 I ended up using (seq coll) and taking out (count coll)

rauh15:04:44

@elena.caraba Why not just (if (empty? coll) 0.0 ...)

Elena15:04:25

Because my fellow developers are stuck with if-let

leongrapenthin23:04:07

@elena.caraba if its coll I recommend not-empty over seq, because it doesn't change collection type.

Elena12:04:38

Thank you, I'll give that a try.