This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-30
Channels
- # asami (10)
- # babashka (14)
- # beginners (71)
- # calva (56)
- # cider (8)
- # cljs-dev (3)
- # clojure (111)
- # clojure-australia (1)
- # clojure-europe (19)
- # clojure-nl (4)
- # clojure-uk (147)
- # clojurescript (4)
- # cursive (8)
- # datalog (1)
- # datomic (19)
- # emacs (4)
- # graalvm (32)
- # helix (14)
- # jackdaw (7)
- # jobs-discuss (10)
- # juxt (4)
- # lsp (3)
- # malli (47)
- # meander (6)
- # off-topic (29)
- # portal (6)
- # re-frame (1)
- # react (3)
- # reitit (24)
- # releases (1)
- # remote-jobs (4)
- # reveal (33)
- # rewrite-clj (3)
- # shadow-cljs (5)
- # sql (10)
- # tools-deps (4)
- # vim (7)
- # xtdb (151)
Does anyone recall if there’s been a discussion of added a goto primitive to Clojure? Apparently there is such an instruction in the JVM. Obviously you don’t need goto for high level user code. But sometimes it is good to have in macro expansions, if you want the macro to create extremely efficient code. Also when transcribing Knuth algorithms verbatim.
One example is when serializing a finite state machine into clojure code, it is extremely efficient to translate it into labels and goto, especially in light of the fact that tail call optimization is not an option.
Another example is discrimination nets where the code represents a binary tree of if/then/else nodes. it might be the case that you want some of the nodes to be identical, copying the code causes an exponential explosion of code size, a goto would divide the code size by 2 every time it is used.
again, that would be for machine (macro) generated code.
with jvm clojure you always have an option to write low-level java code (with GOTO instructions if you like) and use it in clojure code.
can I have a clojure macro expand to low level java code? or better, expand to JVM instructions?
you can (to some degree) use https://clojure.github.io/tools.emitter.jvm/
but I don’t think it will have any significant improvements
forget that, it is for introspection, not for comsuming
Anyway, having some primitive operations directory in clojure would be useful. Humans aren’t the only ones who write code.
I’ll create a thread in clojureverse.
right, not only, but I don’t think clojure team prioritize towards machines instead of humans.
better to start from http://ask.clojure.org
done https://ask.clojure.org/index.php/10547/is-it-possible-to-implement-label-goto-mechanism-in-clojure
@jimka.issy One relevant issue is some work done around recur-to
which is a mechanism in loop
which allows different recur targets
very interesting. Thanks for the link. Would you mind also commenting on the askclojure thread?
I’ll take a look at the presentation, but I can’t imagine how a DFA could be implemented with concentric loops. I’ll keep an open mind when I watch the video.
Deterministic Finite Automata, usually
As opposed to nondeterministic ones, or NFA
Can someone help me with human-speak terminology. I want to describe to an audience who is not clojure-savvy what kind of call-site argument lists are compatible with a function such as: (fn [a [b c] d e) ...)
. How should I describe what type the 2nd argument is expected to be. Should I say tuple ?
tuple is not the best way to describe because you can pass any sequential object longer (or even shorter) than destructuring form
it can take a list, or cons, or vector, or lazy sequence, or or or or
a tuple is constrained on size, while destructuring just accepts anything really, what p-himik says
so is there a word which describes all objects supported by nth ?
perhaps sequentials ?
Returns the value at the index. get returns nil if index out of
bounds, nth throws an exception unless not-found is supplied. nth
also works for strings, Java arrays, regex Matchers and Lists, and,
in O(n) time, for sequences.
but that also doesn't quite cover it since sets are seqable but not compatible with nth
(defn seqable?
"Return true if the seq function is supported for x"
{:added "1.9"}
[x] (clojure.lang.RT/canSeq x))
I think what p-himik says is best: ordered things, like sequential collections, strings and arrays
In wide-audience-speak you could even say "array-like things" or "list-like things"
yes everyone will vaguely understand sequence-like or array-like
Is that a typo in the docstring of nth
? or is that really intended “get returns nil if index out of bounds” ?
(defn nth
"Returns the value at the index. get returns nil if index out of
bounds, nth throws an exception unless not-found is supplied. nth
also works for strings, Java arrays, regex Matchers and Lists, and,
in O(n) time, for sequences."
{:inline (fn [c i & nf] `(. clojure.lang.RT (nth ~c ~i ~@nf)))
:inline-arities #{2 3}
:added "1.0"}
([coll index] (. clojure.lang.RT (nth coll index)))
([coll index not-found] (. clojure.lang.RT (nth coll index not-found))))
ahh, the meaning is *Whereas get returns nil …, nth throws an exception.” is that the meaning?
tuple is not the best way to describe because you can pass any sequential object longer (or even shorter) than destructuring form
the only thing you can say for sure about that form (fn [a [b c] d e] ...)
that this is a function of 4 arguments.
and that it will crash on an argument which does not work with nth
in the second position
@delaguardo, exactly the kind of subtleties in trying to describe what is happening. especially to a non-clojure-savvy programmer
other constrains probably should sit on top of the function via spec for instance
in my opinion, since there are soooooo many useful type-like predicates in clojure core, int? number? sequential?, and since destructuring is so fundamental to how clojure works, there should be a predicate destructurable? which captures this nth-compatibility question.
you could sketch out it’s interface and propose in http://ask.clojure.org
“destructuring” is a process of extracting and binding information from structured data described by entity called desctructuring form
which should follow some rules described in https://clojure.org/guides/destructuring
that’s my attempt to describe what is going on 🙂
Hello! I created some lib for using on developing my work projects, but I don't want to add it as a dependency in project.clj or deps.edn. Althow I want to be it allowed at every namespace in repl. I found a way:
lein repl
(load-file "my_lib.clj")
once on repl start and then in any repl ns eval
(do
(use '[my-lib :as ml])
(ml/my-fn ....))
Is there any other convinient way of doing it? Or just altering standart classpaths? Maybe starting lein repl
with some classpath parameters?Thanks, good way. But it's already created and added to git, and I dont want to alter it - if I'l require my lib there, then I'l have to send my lib to all my colegues, but they dont need it
(defproject hello "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url ""
:license {:name "Eclipse Public License"
:url ""}
:dependencies [[org.clojure/clojure "1.5.1"]]
:source-paths ["dev"])
We have common project.clj
and it's not git ignored. Can I create another one? I'm not sure what do you suggest, sorry
"If you want to access dependencies or plugins during development time for any project place them in your :user
profile. Your ~/.lein/profiles.clj
file could look something like this:"
https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md#default-profiles
@jimka.issy There is also a destructure
function which is used when destructuring, maybe helpful in some way
But since you are speaking to a wide audience, maybe it's better to not get into too much detail
@borkdude, I took a look at the code for destructure
… it is shocking
a bit aggressive ) maybe worth to add more details?
what particular you found shocking?
sorry, don’t mean to be agressive. just when I look at the function, it appears to be an internal function having no docstring or comment explaining what it does. it’s not easy to understand what the function does.
I suppose the function is not really intended for public consumption.
nothing essentially wrong with hard to understand code, especially when not intended for general consumption.
Sorry if my words come across like I’m an ass. I’m really a sweat guy. just sometimes not skilled in serializing my thoughts.
no hard feelings ) and yes, destructure
function is for advanced usage which usually assume you are writing a complex macro
it's public in case other implementors need to leverage it, but not generally intended for public use
the absence of docstring is to prevent it from showing up in the api docs
having spent many hours in that function, I agree that it is far more painful to read/understand that it should be
and I apologize for the additional trauma I have inflicted upon the code and future readers :)
I have ripped off this function in sci, and merged it with the CLJS version to make it a .cljc version
just for mild curiosity's sake, when might one want to use destructure
:thinking_face:
Usually you don't need it, but it can be handy for debugging as well, to see how clojure destructures things
potentially if you were writing a macro or something you could explicitly call it, but really most macros just expand to a let
or something else that will call it for you, so it is pretty rare to need to call it directly
You (concerned developer with commit rights) might want to add a comment to the destructure source to mention "destructure() is public in case other implementors need to leverage it, but not generally intended for public use. The the absence of docstring is to prevent it from showing up in the api docs" .... at or near https://github.com/clojure/clojure/blob/clojure-1.10.1/src/clj/clojure/core.clj#L4389
Hi Everyone :) I am trying to see how feasible it is to try creating a thin wrapper around optaplanner https://quarkus.io/version/1.7/guides/optaplanner .
However, based on the example it seems like the set up for it can be very heavy on class creation - some of which have several annotations.
Is there any similar project that I can take reference from? / Any advice for such interop?
I understand that I might need gen-class
and I do understand that so far, this undertaking seem a bit out of reach at my current proficiency levels ><
this seems like a pretty good example of the kind of lib clojure tends to have trouble with
Any suggestions on how I should document it though? @U3JH98J4R
As of now I've been trying to do a one to one translation of the code from java to clojure
fyi, deftype supports annotations https://clojure.org/reference/datatypes#_java_annotation_support
I like this rule a lot https://guide.clojure.style/#function-length even though I admit I sometimes fail to follow it
Here is a link to the draft of a https://drive.google.com/file/d/1jcBy0Hu59wDVWHIyvl6g4CWPR-9GMbbc/view?usp=sharing which will accompany my upcoming ELS (european lisp symposium) talk. If anyone sees anything horribly wrong, there’s still time for me to fix it.
First feedback: you call multi-arity functions "variable arity". I think this is confusing since we call (fn [& xs])
a varargs function and "variable arity" might be confused with that. Instead, I would use "single arity" and "multiple arity" or "multi-arity"
These are the terms used by http://clojure.org: https://clojure.org/guides/learn/functions#_multi_arity_functions https://clojure.org/guides/learn/functions#_variadic_functions
What is the trick you are using to go to the next page? Just layout the code so it works when you navigate page down, or is this an elisp package?
@borkdude not sure what he's using to navigate pages, but Emacs does understand the form feed character ... So maybe that? http://ergoemacs.org/emacs/modernization_formfeed.html
@jimka.issy pretty clear;
One note: you have something called (satisfies …)
. For a moment I got confused that this is (clojure.core/satisfies? …)
https://clojuredocs.org/clojure.core/satisfies_q