This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-26
Channels
- # ai (1)
- # announcements (7)
- # babashka (2)
- # beginners (23)
- # biff (3)
- # calva (1)
- # chlorine-clover (3)
- # cider (2)
- # clj-kondo (12)
- # clojure (25)
- # clojure-brasil (4)
- # clojure-europe (33)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-uk (1)
- # clojurescript (30)
- # clr (6)
- # consulting (1)
- # cursive (14)
- # data-science (1)
- # datalevin (4)
- # datomic (3)
- # events (4)
- # graphql (1)
- # gratitude (2)
- # hoplon (10)
- # inf-clojure (3)
- # interceptors (1)
- # introduce-yourself (1)
- # off-topic (13)
- # pathom (2)
- # pedestal (12)
- # rdf (14)
- # releases (6)
- # sci (17)
- # shadow-cljs (12)
What am I doing wrong? Here’s the function declaration:
(defn find-by-last-name
"Find users by str-last-name"
[db {:keys [last-name limit] :or {limit 200} :as params}]
(core/find-by-last-name db params))
But there is no :limit
key in params. I think it always worked beforeNope, it has never worked that way.
params
is exactly what you've passed in (coerced to a map in some cases).
:or
affects only the bindings creates by :keys
.
I see, thanks!
That makes a lot of sense, actually, now that I think about it
So I just did this, for the record:
(defn find-by-last-name
"Find users by str-last-name"
[db {:keys [last-name limit] :or {limit 200}}]
(core/find-by-last-name db {:last-name last-name :limit limit}))
(def defaults
{:limit 200})
(defn find-by-last-name
[db opts]
(call-your-func db (merge defaults opts)))
or thisThanks!
But the way I did it you can see the default parameter value in function documentation
just a warning:
(let [{:keys [limit] :or {limit 1}} nil] limit) ;; => 1
(let [{:keys [limit] :or {limit 1}} {:limit nil}] limit) ;; => nil
if the key is present but the value is nil you won't get your default, @U02F0C62TC1 , the same is true for merge, no? A nil
value in opts
will overwrite the default value
yes you're right, I guess my initial point was that :or
has not the same behviour as or
but the merge part is a mistake
SOLVED
Hello — I have an S-expression that seems to be too big for the Clojure reader! It’s about 2,025 lines long. lein run
on the gist linked below gives me
┌─(~/tmp/reader-test)────(brian@Golf37:s011)─┐
└─(09:28:14)──> lein run 1 ↵ ──(Fri,May26)─┘
Syntax error (IndexOutOfBoundsException) compiling fn* at (reader_test/core.clj:1:166).
Method code too large!
Full report at:
/var/folders/cp/df32wpxn1ps8dmn6w_tydwdr0000gn/T/clojure-7617868419525093815.edn
and that seems to be an unavoidable Java limitation.
The S-expression is a vector, so I can break it up manually. Or I could write a preprocessor in some other lisp, say SBCL. But I’m looking for ways to ingest it and break it up with Clojure code. I’ll be grateful for any of your kind advice!
https://gist.github.com/rebcabin/7b2f14fc83149181feaa6ee136953012it isn't too big for the reader, the problem is you are passing it through the compiler
the compiler emits jvm byte code, and the jvm has a limit on how large method bodies can be
the easy solution for this is don't include it as a literal in your source code, keep it has a resource file and load it at runtime from there
exactly when you hit the too large method limit is going to be very context dependent, the def thing may punt it down the line until you add a few more items
like for example def is handled specially at the repl, so you may not see the error at all there
these give me good ideas to try … more later
i definitely need to compile it! I’m doing syntax checking on it via clojure.spec. It’s intermediate rep for a Python compiler.
Not sure how the need to compile follows from the usage of either spec or Python. You can definitely check dynamically created data with spec.
working on it …