This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
(def credential (with-meta 'crendetial {:type :ratom}))
works. But I really like the following to work:
(def credential ^{:type :ratom} 'crendetial)
Saw this once again: https://stackoverflow.com/a/21443241/855160
Is there a library that defines, these?
(defn less? [a b] (neg? (compare a b)))
(defn less-equal? [a b] (not (pos? (compare a b))))
So something like <
and <=
that also work on non-numbers?
Why do you need these predicates? Where would you use them?
I use them on characters currently, but I’ve had other uses for them. They’re analogous to least
and greatest
from medley
.
I'm not aware of any library that offers these but I feel that maybe it's an XY problem. > I use them on characters currently Yes but to what end? I mean maybe there's a better way to solve your actual problem without resorting to manual comparisons. E.g. to sort arbitrary data it would be better to https://clojure.org/guides/comparators
I’m writing a interval set for character ranges, for instace i have. a function:
(defn in [x [a b]]
(and (less-equal? a x) (less-equal? x b)))
to test if a character is within an interval.So you have a set of discrete values and a character and you want to do a membership check.
I would:
1. build the set of characters based on the interval bounds
2. run (charset x)
That way if charset
is #{\b \d \c \e}
and x
is \e
the result will be truthy, if charset
is #{\b \d \c}
, the result will be falsey.
Thank you. I want to avoid representing each character as this is for a regex engine and a interval set could potentially represent all characters.
Oh alright, I assumed ASCII 🙂 I think your solution is fine for bigger character sets. (Still, I'm not sure how meaningful Unicode ordering is, like should a smile emoji be greater than the plus sign emoji?)
I haven't tried but I would assume regex character classes us codepoint ordering.
Hey, I'm trying to rewrite some Java code to Clojure but bumping into some issues (maybe this can't be done in Clojure?). Basically I have a Go Library which I'm trying to import and call in Clojure. This works with the following Java code:
public interface GoTest extends Library {
long Add(long x, long y);
}
public static GoTest GO_TEST;
static {
String lib = System.getProperty("user.dir") + "/bin/foo.so";
GO_TEST = (GoTest) Native.loadLibrary(lib, GoTest.class);
}
I'd like to avoid Java if possible. I wrote the following piece of Clojure:
(import '(com.sun.jna Library Native))
(definterface GoTest
(Add [this x y]))
(extend GoTest Library)
(defn load-library []
(let [lib (str (System/getProperty "user.dir") "/bin/foo.so")]
(Native/loadLibrary lib GoTest)))
but I get the following error:
Interface (GoTest) of
library=/home/user/clojure-go/bin/foo.so does not
extend Library
Any ideas? Or is this just not possible in Clojure?Not sure whether it'll work but try
(definterface GoTest
(Add ^long [this ^long x ^long y]))
Indeed, definterface
by itself doesn't have that ability.
But you can use gen-interface
.
Oh, and also - my bad for not realizing this - methods you specify in definterface
don't accept this
. So also remove this
from there.
Awesome! This works:
(gen-interface :name "clojure_go.core.GoTest"
:extends [com.sun.jna.Library]
:methods [[Add [Long Long] Long]])
@UG9U7TPDZ you could also consider implementing a golang pod so you can call it through the babashka.pods library which also works in the JVM. No native stuff :)
Interesting idea :thinking_face: But you would have a communication bottleneck I think. But maybe that would be really minimal
it depends on if you have: 1. many function calls 2. big sized arguments (as they are serialized) So if the overhead of the function call serialization is small compared to the actual work happening in Golang per function call then it would be a good fit. E.g. the sqlite3 pod and file watcher pod fall into this category
Right, for my usecase this might actually be a good fit. Not sure how I'd implement this though. Also I haven't gotten my own example working in GraalVM yet lol
there has to be no graalvm involved. you can look at the existing babashka pods in golang here: https://github.com/babashka/pod-registry
@UG9U7TPDZ Another option might be to use #coffi and project Panama on JVM 17
If you're targeting graalvm, then I think dtype.next is the best option. I don't think coffi works with graalvm. If it does, that would be good to know!
But does @UG9U7TPDZ target graalvm native? I haven't read that he did... Please don't leave us in suspense!
> The reason I want to call Go is for performance I'm not sure if I understand that one. Go in general shouldn't be more performant than Java, or is it?
dtype next isn't too bad once you set it up. Here's some examples • https://github.com/phronmophobic/grease/blob/7a9a17e78e91d55cca2a3895acb61c4c56710504/src/com/phronemophobic/grease/objc.clj#L25 • https://github.com/phronmophobic/grease/blob/7a9a17e78e91d55cca2a3895acb61c4c56710504/src/com/phronemophobic/grease.clj#L63
I'm happy to answer any questions. clojure <-> c interop unlocks a lot of potential!
although I agree with @U04V15CAJ that if the goal is performance, I'm not sure calling go from clojure will give you any better results than either calling java or optimizing your clojure code.
I was under the impression that Go did have a bit of an edge in terms of performance from the benchmarks I've seen, but maybe that's a bit misleading
Measure for your specific problem and in the typical scenario you're using it. Performance is hard to speak about in general is usually very contextual.
import-vars of potemkin exposes values and macros, is it possible to expose a namespace?
You want to import all vars (defs, functions, and macros) from one namespace into another and then export them as if they are defined in the second namespace?
In ns a
, i’d like to import ns b
and define b
as a.b
. so that, from ns c
, it can access a.b
by importing ns a
only.
Oh hmm. I don’t think that's possible. Why not just require ns b
from within ns c
? Namespace aren't private or hidden, so if ns a
can require it, so can ns c
.
clojure.data.xml does that: https://github.com/clojure/data.xml/blob/master/src/main/clojure/clojure/data/xml.clj#L34-L39
I will say tho: The reason I know this is I purposefully circumvent it in my code because it messes with cursive symbol resolution.
If you were to make a runtime basis, but it did not include flags - just dependency and repository information - what would you call that?
Is there a way to tell iterate to end? Or I guess a lazy-seq in general? Does returning reduced work for that?
I found a workaround:
(->> (iterate (fn [x] ...))
(take-while (complement reduced?)))
That lets me return a reduced from the iterate fn and it'll stop. But I'm still curious, like how does take-while short-circuits the infinite seq to make it finite?
Hum... right so with lazy-seq, nil short-circuits, but I guess nothing can make iterate short-circtuits so you need to wrap it and not poll it anymore