This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-10
Channels
- # asami (2)
- # babashka (28)
- # beginners (91)
- # calva (38)
- # cider (7)
- # clj-kondo (20)
- # cljfx (3)
- # clojure (88)
- # clojure-austin (1)
- # clojure-australia (2)
- # clojure-bay-area (10)
- # clojure-europe (68)
- # clojure-france (8)
- # clojure-italy (14)
- # clojure-nl (4)
- # clojure-sanfrancisco (1)
- # clojure-uk (14)
- # clojurescript (37)
- # clojureverse-ops (14)
- # clojurewerkz (1)
- # clr (1)
- # conjure (13)
- # cursive (10)
- # datascript (30)
- # datomic (6)
- # emacs (13)
- # exercism (3)
- # fulcro (10)
- # graalvm (4)
- # graphql (2)
- # instaparse (5)
- # jobs (3)
- # kaocha (10)
- # off-topic (20)
- # pathom (17)
- # polylith (7)
- # re-frame (25)
- # remote-jobs (1)
- # shadow-cljs (60)
- # spacemacs (5)
- # specter (1)
- # startup-in-a-month (1)
- # tools-deps (48)
- # vim (4)
- # xtdb (11)
I’m getting an inexplicable error in the clojurewerkz/elephant library and would appreciate help
Looking at the library code,
(defn ^IPersistentMap create
[^IPersistentMap m]
(cnv/customer->map (Customer/create m)))
This is calling com.stripe.model.Customer, passing in the map. The codepath seems unrelated to the clj library. Have you tried inspecting the map and checking it is correct, and comparing it to the Stripe docs?Also the stacktrace seems to indicate the erroris when doing subscription creation. Can you give more context for: vendo.routes.home$create_subscription.invokeStatic(home.clj:62)
This is the create-subscription function:
(defn create-subscription [req]
(prn "request is " (:params req))
(prn "payment method is " (:payment-method-id (:params req)))
(let [customer (cust/create {"email" (:email (:params req))
"payment_method" (:payment-method-id (:params req))
})
subscription (esub/create customer {"items"
[{"price" (:price-id (:params req))}]
"expand" ["latest_invoice.payment_intent"]})]
(prn "subscription is " subscription)
)
(req-res/response "response"))
and the error is in the cust/create
in the docs under create a customer, there’s a payment_method parameter @UJA1Z6ZJ7
which is what I have as well
What’s the most efficient way to convert a string to a number without specifying the type of the number (Long, BigInt).
I was thinking of clojure.edn/read-string
but it will successfully reads strings that are not numbers.
Also, I am not sure that it’s the most efficient option.
you could look at how the reader does it. from memory a bit ago, it constructs a bigint from it and then if its sufficiently small turns that into a long
BigInteger bn = new BigInteger(n, radix);
...
return bn.bitLength() < 64 ?
Numbers.num(bn.longValue())
: BigInt.fromBigInteger(bn);
I found the code on Github https://github.com/clojure/clojure/blob/cbb3fdf787a00d3c1443794b97ed7fe4bef8e888/src/jvm/clojure/lang/EdnReader.java#L342-L344
@dpsutton what is this Numbers.num
?
static public Number num(Object x){
return (Number) x;
}
static public Number num(float x){
return Float.valueOf(x);
}
static public Number num(double x){
return Double.valueOf(x);
}
from /clojure/src/jvm/clojure/lang/Numbers.java
static public Number num(long x){
return Long.valueOf(x);
}
is what its doing in this case. its boxing it i think?Why boxing is required here?
this is reader code and the reader doesn't return primitives is my guess. but i'm very handwavy on boxing vs primitive. my work in Clojure normally doesn't depend on this stuff so i'm just surface level on that stuff
Thank you for your help!
I would actually like to have a core function for this and may even have created a CLJ ticket for it already
you can vote here: https://ask.clojure.org/index.php/4275/add-convenience-parse-int-parse-float-parse-short-functions
Seems like Jira exporter does some things wrong so that the resulting http://ask.clojure.org post looks off:
- Some code is enclosed in <code>
, as it should be; but some is just wrapped in {{...}}
and is left as a regular text
- Somehow parse-*
has become *} with a bunch of spaces
Voted like a responsible Clojure citizen
thx, this really does help raise visibility - we are looking at votes for prioritization
@U064X3EF3 Is github login the only form of authentication or am I missing something? I'd prefer to register separately but it's fine if not possible 🙂
the github auth does not grant access to anything except public info
I am implementing linting for the core.match macro. I'm running through its unit tests to see what clj-kondo can't yet understand. Now I've arrived at the :when
syntax:
(match [y]
[([_ (a :when even?) _ _] :seq)] :a0
[([_ (b :when [odd? div3?]) _ _] :seq)] :a1
:else [])
but I can't find docs on this, neither in the Basic usage nor in the Advanced usage wiki page. Is this undocumented behavior?but that multimethod allows for dynamic additions. I've got one like
(defmethod match/emit-pattern-for-syntax [:isa? :default]
[[_ parent]] {::match/tag ::isa? :parent parent})
so there's no way to encompass all statically i thinkits custom but defined in the source just like :seq
:or
:guard
:<<
etc. it uses a mechanism that is exposed for others to add syntax to match
"Handles patterns wrapped in the special list syntax. Dispatches
on the first or second keyword in the list. For example, the pattern
`(:or 1 ...) is dispatches as :or, and `(1 :as a)` is dispatched by :as."
docstring for emit-pattern-for-syntax
Haha, the advanced usage docs: > You should read Understanding the algorithm before reading the rest of this section. And then there is hardly any rest of this section ;).
hey people… I’ve been experimenting with finalize
on reified objects and I’ve noticed that finalize method is called twice for each object, which seems odd, since Java is supposed to call each finalize once.
(defn test1 []
(reify Object
(finalize [this]
(println "collected"))))
and this produces:
(do (test1) (System/gc))
collected
collected
=> nil
Seems odduser=>
(defn test1 []
(reify Object
(finalize [this]
(println "collected" this))))
#'user/test1
user=> (do (test1) (System/gc))
nil
collected user=> #object[user$test1$reify__179 0x5802c0da user$test1$reify__179@5802c0da]
collected #object[user$test1$reify__179 0x202cf2e7 user$test1$reify__179@202cf2e7]
logging this
shows there are different things involvedseems to imply reify call creates two objects?
yes further testing proves that’s the case:
(let [t (test1)] (System/gc) t)
collected
i browsed the code a little bit. I see that Object is cons onto the interfaces without checking if its already there. i wonder if its duplicating this stuff accidentally. Note this is cursory glance and I could easily be wrong
I am pretty sure the two instances are a result of the code the compiler emits to add any metadata attached to the reify form to the instance
added this bit to the cljdocs examples
I kinda feel like I only half understand the finer distinctions here, but in Clojure, is it correct to say that sequences are not collections? You can create sequences from collections. You can create collections from sequences. But sequences themselves are not collections? As far as official docs go, this page seems to imply that sequences are separate things from collections: https://clojure.org/reference/sequences e.g. these sentences on that page imply they are separate kinds of things: "Many of the functions in the seq library take one or more collections, call https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/seq on them, and then operate on the resulting seq. In other words, many of these functions take collections but operate on their seqs."
I've written a couple longer form things that might help: https://insideclojure.org/2015/01/02/sequences/ https://insideclojure.org/2016/03/16/collections/
Thanks for the links. If anyone has written more deeply on this topic, I figured it would be you 🙂
from a Java class pov, sequences ARE collections
ISeq extends IPersistentCollection
coll? returns true for seqs, etc
My question arises from wondering what an "authoritative" answer would be for explaining to someone why peek
throws an exception for at least some kinds of sequence inputs. peek
mentions a few collection types like vectors, lists, and queues explicitly, but then also says what it does for "collections" in general. If sequences are collections, then in some minds it might raise the question of whether sequences are collections, or not.
That might be just one of those corners of implementation or docs that is kinda near the hairy edge of these questions.
as usual, I think you should read absence of information as significance of undefined behavior
Ah, so perhaps the word "collection" in peek's doc string should be interpreted as "one of the aforementioned kinds of collection early in the doc string", not "any arbitrary kind of Clojure collection". That would make sense.
peek / pop really only make sense as a concrete sequential data structure operation, not as seq ops
In order to write linting for :when
in core.match, I'm trying to understand it.
@dpsutton already pointed me to the docs of the defmulti. it dispatches on the first or second keyword in the pattern.
But I'm also seeing expressions like:
(match [y]
[([_ _ :when even? _ _] :seq)] :a0
[([_ _ :when [odd? div3?] _ _] :seq)] :a1
:else [])
How do these get handled? The keyword :when
occurs in seemingly random place in the pattern?@dpsutton https://github.com/clojure/core.match/blob/fb3188934ab9b6df0249ba3092a888def3434eee/src/test/clojure/clojure/core/match/test/core.clj#L265-L289
Because it's a regular function. :)
user=> (source class)
(defn class
"Returns the Class of x"
{:added "1.0"
:static true}
^Class [^Object x] (if (nil? x) x (. x (getClass))))
nil
thank you, sorry for the stupid question, I am not a regular clojure user, was trying to understand some clojurescript, should have got a repl going
oh i never mean "you can answer this question yourself so don't ask it". i always mean great question and here's an authoritative answer
Indeed not stupid. But in case you have a lot of entry-level questions, you'll find #beginners to be a great place.
it's understandable now I know it's a clojure core function, someone in this library: https://github.com/groundedSAGE/konserve has some cljc files whic haven't been used under cljs for a long time so don't compile, because they include that function without a guard for :clj
I was slightly ambitiously trying to get them to compile/run under node in order to get a version of datahike working under node for a project I'm mostly working in typescript but want a node logic db as backend
Yeah, class
is not defined in CLJS at all - because the platform has no proper classes, I guess.