This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # beginners (59)
- # calva (20)
- # cider (25)
- # clj-kondo (12)
- # cljdoc (3)
- # cljsrn (15)
- # clojure (104)
- # clojure-europe (4)
- # clojure-italy (10)
- # clojure-nl (3)
- # clojure-spec (14)
- # clojure-uk (13)
- # clojurescript (33)
- # code-reviews (26)
- # core-async (1)
- # cursive (5)
- # data-science (3)
- # datomic (8)
- # emacs (3)
- # fulcro (5)
- # graphql (3)
- # hoplon (1)
- # jobs-discuss (4)
- # kaocha (14)
- # nyc (1)
- # off-topic (33)
- # pathom (4)
- # pedestal (2)
- # quil (1)
- # re-frame (5)
- # reagent (10)
- # reitit (6)
- # rewrite-clj (3)
- # shadow-cljs (173)
- # specter (7)
- # sql (4)
- # vim (58)
- # yada (3)
why is it (ns foo.bar (:require.. and not (ns foo.bar ('require... why keywords and not symbols? If keywords as list first arg usually mean map indexing
this syntax, as central as it is, was not deeply considered - it was actually one of the first significant external contributions to Clojure
Hehe last week I hosted a coding dojo about clojure, for people new to it, and the
ns form was indeed puzzling to most, and I was not able to clarify much 🙂
Yeah I'm always been puzzled as well, how did you declare a namespace before that by the way?
I do not recall, but note that you can implement the effect of an
ns form with a combination of
import calls (probably with a few exceptions I am forgetting about, that require a few other calls to implement).
Let's say I place a nonsensical type hint, shouldn't that cause a runtime error?
(let [^String a (fn  42)] (.invoke a))
@vemv fwiw, that generates a reflection warning:
user=> (set! *warn-on-reflection* true) true (let [^String a (fn  42)] (.invoke a)) Reflection warning, NO_SOURCE_PATH:3:3 - reference to field invoke on java.lang.String can't be resolved. 42
yup, I would normally get the warning as well but I was concerned that placing useless/wrong info can be compiled successfully IIRC under certain circumstances, placing the wrong hint would cause a runtime error? I'd appreciate such behavior, always
https://stackoverflow.com/questions/34963349/why-doesnt-the-clojure-compiler-throw-an-error-for-an-incorrect-type-hint Notably this comment: > quick demo of what you're saying about hints and errors user=> (.length ^String [1 2 3]) 3 user=> (defn strlen [^String s] (.length s)) #'user/strlen user=> (strlen [1 2 3]) ClassCastException clojure.lang.PersistentVector cannot be cast to java.lang.String user/strlen (NO_SOURCE_FILE:4) – noisesmith Jan 23 '16 at 13:53
Interestingly, it looks like that's only for caller errors, not hinting errors. For example, if you do:
That's not gonna blow up, probably because the code generated was reflection. But in the length example above it does because the bytecode was generated against String.
user=> (defn foo [^String a] (.invoke a)) #'user/foo
Good links / examples!
Probably what I want is simply not implemented - what I remembered (`IIRC [...]`) was an instance of a caller error, not a hinting error.
I wish there was a
*throw-on-reflection* option - or at least a weaker variant:
Hello, I need to build up a string and then make it a regex. I can do this by re-pattern, but I’m struggling with ‘unallowed escape character’ for the string parts. Prefixed with
# they are ok, but not when they are strings.
#"\-" is ok, but
"\=" (as a string), isn’t
how to transform the latter into a string that, when used in
re-pattern, wil produce the former?
hm i thought i ’ve tried that (this is a simplified example of course), but that’s the way to go?
We need more volunteer mentors for http://Exercism.io https://exercism.io/, helping folks who want to learn Clojure. Perhaps you can help us? Once you get going, it doesn't need to take more than few minutes per review. (Ideally 1h/week but any contribution will help us fight the growing queue)! Thanks!
I'd be interested in participating in this! I haven't worked professionally in Clojure for about 6 months, and have been itching to get back into it in some capacity! How do you become a mentor? I signed in but think I may be restricted to just the mentee role?
I discovered a tab on the upper right corner that says become a mentor. Already reviewed a few solutions. Quite easy to do.
As a learner, I just want to say thanks to you folks for considering this. I've found exercism a fun way to learn and I also bring my solutions to the #beginners channel for even more education. It's been great.
But yeah, the queue does take a while but it's all volunteer work so I gladly work on other problems while I wait.
It's weird I submitted one solution on the mentor track but my place in line keeps moving back because it's the 5th or 6th exercise so they keep putting the earlier ones before me. c'est la vie!
Well, personally I haven't got beyond mentoring the first three.... [yet]
Hey. When I call
(stest/instrumentable-syms), a bunch of definitions are listed that I would expect. However, when I call
(stest/instrument) on the next line, nothing is instrumented. Perhaps I'm misunderstanding, but shouldn't they echo each other?
you need to run code (typically by loading a namespace that has top-level
s/defs) to put specs in the registry
Hmmm, I think I'm falling afoul of some shadow reload magic that I don't understand.
Yea, it's magic related. Reloading the page makes everything behave as expected.
hey guys. i’m trying to cobble together a datastructure that is as close to a map as possible (in terms of behaviour and performance characteristics), with one additional property: i can keep track of last access time for each item.
some ideas that came to mind were tuplifying the values, or somehow adding a metadata tag to each record
Then you will need to override some low-level access Java methods (if you are using Clojure/Java) to modify how the lookup behaves.
There are examples of other data structures built on top of Clojure maps that do this, if you would like to see how others have done similar things. data.priority-map for one, although it modifies more about the behavior than you want to.
i guess i’m not too concerned about sort order, now that i think about it. if that’s the best way to go about it, then it should be fine
I point at that example not because of the sort order, but because it shows one way to change the behavior of a data structure that otherwise behaves like a map.
Hi guys, I'm new to spacemacs and lisp editing and I'm having trouble creating complicated expressions. I feel like I'm managing the parentheses and indenting wrong. How do experienced people manage these?
is there any other operation besides slurp / barf that is important for editing lisp?
I find "next token" important,
n in vim. and matching paren,
% in vim. and "end of form" I use
f) in vim or start of form
F( in vim. There is certainly a version in your system of choice.
You want to slurp and barf I bet https://practicalli.github.io/spacemacs/structured-editing/lisp-state-slurp-barf.html
(not a spacemacs user but when people are annoyed by parens in lisp editing it's usually that they want slurp/barf)
would it be unwise to put something like a memcached connection inside an atom, given that it’s supposed to be multithreaded? i guess i’m a little fuzzy on how atoms work under the hood, i assume they can only be accessed by one thread at a time
atoms have no thread protection - they don't use locks to protect access during updates
it's worse - swap! guarantees behavior that will cause errors if trying to do updates to something mutable
either it detects the mutable object equality via reference and doesn't protect against race conditions at all
the line in the docs “changes are always free of race conditions” threw me off i suppose, sounded like thread protection to me
this will cause errors if the object inside the atom is mutable and your swap! function mutates it
gotcha. ok, sounds like i’m alright for a connection then, since i’m not really mutating it after it’s opened
i’m not 100% sure, i imagine nothing would happen, but that’s a good thing to keep in mind. thanks
It should be fine if you have mutable objects inside of the atom, e.g. as values of keys inside an immutable map, if you are just 'carrying them along unmodified' by the swap! fn as associated values in the map. True?
If that is OK, it is because the mutable values are not really being mutated, but used as unchanged values inside the swap!
right - you could even have the mutable object naked in the atom, so to speak, as long as all you do is replace it and let it leave scope
but that takes discipline and introduces the possibility of nasty bugs if the next dev touching related code misunderstands
(if you are willing to rely on dev reasoning and discipline you can just go back to old fashioned mutex locks haha...)
sure. I only ask because, if I understand correctly, sometimes people create applications with a 'big config map', where some of the values associated with keys are mutable objects. Not sure if I understand that correctly.
oh yeah - but if you look at the docs / README for the lib most commonly used for this (stuartsierra/component) they explicitly don't suggest using an atom, and instead want you to use a runtime argument in prod, and a var in dev
which eliminates questions of retries entirely (and doesn't hurt the semantics, since that map should only be updated from the top level immediately after a code reload - it's part of dev UI)
@UAKE446AJ I didn't even think to ask, but is the memcached connection soemthing that you need to protect against concurrent reads? (that's rare but I'm realizing it is an issue with some kinds of objects...)
cool - the underlying java layer probably takes care of read consistency for you when writes are going on anyway
hi folks, does anyone have experience trying to construct sorted-map instances from already sorted input? i'm trying to avoid the O(n log n) cost of doing an
(into (sorted-map) ...)
no matter how you construct it, using clojure's sorted map it will still need to do the extra work to build the underlying b-tree which as I understand it is where that cost is coming from
but I think that cost is unavoidable once you guarantee sorting and allow deriving new maps by adding or removing keys
The underlying red-black tree should be constructable in linear time, with a function written specifically for that purpose, which assumed/knew that the input sequence was already sorted. It would not be the existing constructor code, I don't think.
oh, it could even use something like n/m that wouldn't work
spliterator right? (with each split being directly turned into a branch)
how do I test an interactive terminal program that reads from stdin, prints something, reads something again? reason I'm asking: https://github.com/borkdude/jet/pull/33#issuecomment-522327719