Fork me on GitHub
#beginners
<
2021-11-14
>
introom02:11:07

Out of my expectation, why (counted? "asdf") gives false?

introom02:11:31

Or to say, the call (counted? "asdf") itself is meaningless as “asdf” is not a clojure land type. Most clojure functions is only meaningful for clojure specific types that implements some clojure interfaces.

seancorfield03:11:18

Several of Clojure's type-testing predicates simply test whether an object is an instance of a specific Clojure implementation interface. In this case, clojure.lang.Counted. They are not always very useful tests.

seancorfield03:11:56

seq? for example tests if something is an instance of clojure.lang.ISeq which tells you very little.

seancorfield03:11:51

sequential? is a similar, narrow type-testing predicate. seqable? on the other hand is actually useful 🙂

Little Mose04:11:51

hello, I'm a beginner for Clojure

Little Mose04:11:31

For a new project created with lein, how to resolve this lint? 'Unresolved Symbol' : http-server

djblue07:11:25

You will generally need to add a custom rule anytime you are dealing with macros that introduce bindings

Little Mose05:11:22

currently, I'm disable all the linter

Little Mose05:11:23

{:linters  {:unresolved-symbol   {:level :off}}}

Shmarobes09:11:19

Hello. I'm currently looking at the for macro and trying to understand how its modifiers work. As I understand it, the intention is for :while test to take elements of the resulting sequence until (test x) becomes false, and :when test should behave similarly to calling filter on the resulting seq. However, the following example produces unexpected output:

(for [x (range 3) y (range 3) :while (> x y)] [x y]) => ([1 0] [2 0] [2 1])

(for [x (range 3) y (range 3) :when (> x y)] [x y]) => ([1 0] [2 0] [2 1])
So these two forms evaluate to the same seq. Shouldn't the :while one stop when it encounters the first pair where x =< y, namely [1 1]? Could someone please explain what actually happens? I've looked at examples at clojuredocs, but still don't get it.

1
Martin Půda10:11:23

:while after y sequence stops iterating over y values and moves to next x value. x = 0, [0 0] stops iterating over y x = 1, first result is [1 0], [1 1] stops iterating over y x = 2, other two results are [2 0] and [2 1], [2 2] stops iterating over y :while after x sequence checks the x: (for [x (range 3) :while (not= x 2) y (range 3)] [x y]) And you can do both: (for [x (range 3) :while (not= x 2) y (range 3) :while (not= y 2)] [x y])

👍 1
Shmarobes10:11:13

Oh, this makes a lot of sense. Thank you!

Benjamin11:11:11

What is the rational to implement when-let with only accepting 1 binding? Wouldn't be the less surprising way if it worked like let (aka " when-let* "

cjsauer15:11:10

There's an open issue for this, although it's pretty inactive now. There are implementations there if you want to try them. https://clojure.atlassian.net/plugins/servlet/mobile?originPath=%2Fbrowse%2FCLJ-2213#issue/CLJ-2213

andy.fingerhut20:11:21

The main question is: how should each of the bindings affect the truth or falseness of the condition used by the when? There isn’t necessarily one answer that all agree is the obvious one. With a single binding it is obvious

Benjamin10:11:17

I see thanks. Imo it makes most sense that it'd be the same as nesting when-let s