Fork me on GitHub

When I try importing a class definined in the same project I get "class not found" errors


I am fairly certain all my compiling happens at runtime when I load in the clj files


so I am a bit confused


is the class created by a namespace?


if so, you must require the ns, or otherwise cause it to be loaded, before using a class it defines


no, its a namespace loading in the class


the namespace is throwing the error


where does the class come from?


the same project


in a differnt package


what I mean is, how is the class generated? from clojure? from java? who compiles it? when?


so the workflow is that you compiled the java, then started the repl, and it couldn't find the class?


I compiled the java, the repl can find the class


the java code that calls the api cannot find the class


maybe an issue with the classpath in the process running java and using


Makes sense


but Im not sure how to resolve it


@emccue a start would be to see if the target-path lein / lein-javac are compiling to is on the classpath of the java process


unless the java process is using your jar


I just ran maven compile a few times and it started working randomly


I don't know what was causing the problem but I guess it's solved


if a clojure class is generated twice (via reload for example) the two classes have the same name but aren't the same class


similar issue with methods/protocols


this can cause similar but not identical bug behaviors


Im not sure that was this issue but that is definitely useful information


okay the issue came back but at least now I think I know why


Its something with my namespaces being AOT compiled, which I dont want anymore


but after I turn that on my clj files are no longer on the classpath


you need to add you clojure src as a resource in the pom I think


(you may not need the clojure maven plugin at all without aot)


@hiredman That fixes every problem, thank you


This started as a AOT compile project and im pretty glad that the requirements were bendable to the point where I could make it all dynamic


it’s not merged yet but you can check out this branch locally and try it yourself 🙂


I use it all the time, it works great


phew it was a good practice, learned a few good things


I'm probably still not grokking clojure symbols clojure.reflect, how would I go from the symbol returned for the parameter-types to the actual class, i.e.:

(let [type (first
                 (filter #(= (str (:name %)) "matches")
                         (:members (reflect/type-reflect String))))))]
  (prn :type type :class (class type)))
:type java.lang.String :class clojure.lang.Symbol
where I want class java.lang.String?


ah (resolve symbol) seems to do it...ok I retract my question and advance to the rear


Does anyone here recall a demo of Pedestal showing a sales funnel, with dots migrating between pulsating circles that showed customers in various stages of their shopping experience? It was shown at a ClojureConj a few years ago…..


if you have questions about that demo, I can probably point you to someone useful


is there a shorthand of doing something like this?

(defn generate-players
  [user computer]
  {:user user
   :computer computer})


basically generating a keyword based on argument name


I dont think there is a built in, I think I have seen this done with a macro though


👍 thanks


records are pretty close:

(defrecord Player [user computer])
(into {} (Player. "foo" "bar"))
{:user "foo", :computer "bar"}


What is the state-of-the-art library to extract mime types from files?


Not something that maps file extensions to mime types, but something that really looks into the file searching for headers/blocks?


Does any one use either of them?


I use pantomime, it's cool


@qqq There's a #vim-fireplace channel -- maybe that should have its focus expanded to other vim stuff?


@seancorfield moving over; thanks!


I am having a bizarre experience where the falling returns false at my repl: (= "Date" (first ["Date" "Apple" "Orange"])) I suspect it is because the vector is read in from a CSV so perhaps there is some kind of encoding that makes the letters of the word actually different than they appear? Is there a way to convert the imported text into a "standard" encoding?


it would appear that if you copy/paste my code snippet exactly, you will also get false at any repl, but if you type it out yourself, then you will get the expected true


@ajs to debug you could look at (seq (.getBytes s)) and compare for each string


@ajs I see this in my repl:


i get bytes of (-17 -69 -65 68 97 116 101) what does that mean?


oh weird


so there is an underscore there, that is not appearing anywhere in my repl? why would yours show that?


sorry, not sure that worked, slack gave me some complaint about storage space


my repl shows a space


I bet it's a non-printing unicode


strange, so you copy/paste my code snippet but it appears differently after pasting?


how can I "clean" these strings?


@noisesmith was trying to figure out what that’s called, one of those gave me no end of trouble a little while ago


@ajs one approach is to use a regex to strip that garbage out


and why do everyone's repls display it differently?


I’m in cider, could be an emacs vs. terminal repl thing


i'm in cider also, in emacs


(String. (byte-array [-17 -69 -65]) "UTF-8") => ""


im in cursive for reference


what would the regex look like to just extract the letters?


looks like something along the lines of (re-find #"[a-zA-Z]+" (first ["Date" "Apple" "Orange"]))


(.replaceAll "Date" "\\p{C}" "?" ) => "?Date"


so you could use "" instead of "?", maybe there's something more elegant


(Character/codePointAt "" 0)
=> 65279
(Character/getName 65279)


hey folks, what kafka client do you use with clojure ?


@lxsameer my first recommendation is to always use the Java libs, unless they don't do what you want. There's just not enough eyes on Clojure wrapper libs.


Java libs are often produced by the vendor themselves, that helps a lot when trying to find tutorials, and troubleshooting, and even when talking to the vendor themselves.


3rd party wrappers will often be blamed by the vendor when there's some bug that appears. When you use the vendor's libs, they can't blame that layer anymore 😄


@tbaldridge Yeah good points. I'll go with the java client then. Thanks


tricky bastards: vmware won't let you run vmware console from within a vm


^ emoji game on point, @kenrestivo @zylox!


I'm trying to reset a private atom for testing. I'm using alter-meta! and it seems to work just fine at the repl but it blows up when compiling


I suspect that the compiler sees the private atom and freaks out, but it should work at runtime


what's the best way to tell the compiler to back off?


so you are trying to update the metadata on a private atom, which works in a repl, but this doesn't work when running your tests?


yes, exactly


FYI the compiler used in the repl is the same one that is used when running tests, and clojure doesn't have an interpreted mode


Best thoughts on/resources for making Clojure’s flavor of simple also beginner-friendly (not easy, mind you 😄)? I fell in love with the language and its primitives/view on development because I had the great luck to land on a team of awesome senior devs using it effectively. I want to have a goto set of resources to help people experience that banana without also having to bring the monkey (pushing through tooling setup), the tree (pre-existing team), and the jungle (sorry I stretched this metaphor too far). Will ask this differently phrased in #beginners as well.


what do you mean by 'Clojure's flavor of simple'? 'simple' in the context of Clojure is merely one of the lesser-used meanings of the word: 'Composed of a single element; not compound.' (i.e. 'simplex')


Yes, that one. It’s maybe obvious that one of the side effects of making things simplex is that you also make them separate, but I’ve been thinking about the consequences of that kind of simplification a lot recently. For someone starting out one consequence is that it makes for many entry points at each level of simplification, e.g. I read the Rationale at and at the end it takes me at the end to Features ( I think it’s possible because of this branching factor for people to spend inordinate time down minor branches of the path, and have observed this when introducing people to the language/libs/tools: I’m looking for something that teaches how to learn Clojure, i.e. gives a strong heuristic for searching the frontier.


More concisely: resources/unifying values to help people see the forest (a bunch of possible DAGs of learning to go follow) for the tree (the reasons the language’s DNA caused it to branch out into these separate paths here) at each juncture.


Something like a digest of Clojure’s instantiations of SICP’s 3 language mechanisms: - primitive expressions, which represent the simplest entities the language is concerned with, - means of combination, by which compound elements are built from simpler ones, and - means of abstraction, by which compound elements can be named and manipulated as units.


I don't think it's the 'simple' that makes it hard to learn, it's the garbage-in-garbage out, and also the host leaking through. But lots of people want to paint by numbers and plenty of other languages do a good job at that. The thing that 'simple' itself is responsible for is delaying gratification.


Simplicity doesn't necessitate something having many 'entry points'. The reason Clojure has all those features is that Clojure isn't merely an academic exercise: it's a practical language designed to be used to solve real-world problems, robustly and effectively, and those features are what Rich Hickey considers important in achieving that goal. They are a separate concern to its underlying philosophy of simplicity (in syntax or in semantics). Dynamic development doesn't follow from simplicity; nor does concurrent programming; or being a hosted language. They're orthogonal decisions.


Scheme might be a better choice for learning, since even though it doesn't do any better at 'simple', there's just less stuff, and it's introduced gradually in a well-considered order by people who thought a lot about teaching. ML might be a better choice because interacting with a complex compiler is probably going to help a lot for the earliest and most trivial kinds of mistakes.


In addition, the SICP mechanisms are just about the core language (e.g. def, let, fn) are they not? Are you asking about Clojure's core, or about Clojure's features beyond that?


Or about how the website is structured (Rationale leading through to Features etc.)?


Clojure has a tiny amount of operators built into the compiler (, but that's barely scratching the surface of Clojure as a whole


I think the way approaches explaining Clojure is quite good


@U61HA86AG thanks for your notes and questions! I think “features” is indeed what I mean by entry points: each simplex feature is an entry point for a learner (e.g. vars vs refs vs agents vs atoms) at each point of considered language simplification (although note that in this case is an ideal guide/motivation!). It’s in this sense that I mean there are many entry points at different language junctures due to simplification (which yet again is a good thing: it lays bare the false dilemma between Python’s one obvious Pythonic way and Ruby’s AllTheThingsAndSyntaxes design choices at important points in language design). Understand that I am entirely in agreement with: > The reason Clojure has all those features is that Clojure isn’t merely an academic exercise: it’s a practical language designed to be used to solve real-world problems, robustly and effectively, and those features are what Rich Hickey considers important in achieving that goal. but I am also a teacher by trade and disposition: I want to show and motivate and enable people as efficiently as possible, and with as high a conversion rate as possible, to see what’s so beautiful and useful about this sort of simplification cum pragmatism. So I’m just trying to find high leverage tools and paths and principles so that people can join in the fn. Re: SICP’s mechanisms, yes absolutely, it’s about def, let, and fn (actually values, lists, and def/`let`/`fn`/application to be precise pointwise) but (recursively) much more too: it’s about the basic things you introduce at any level of abstraction, the ways you can put them together to express/do useful things, and how you can then name/manipulate/generalize/export that usefulness to other realms.


I had forgotten about aphyr’s project: thanks so much for the reminder! Will post back here with the completed list/introductory structure I get out of this exercise.


I dabble in teaching myself, and I completely get where you're coming from! Please know I'm merely trying to get to the core of your question, so that I can better answer it 🙂


Awesome, I sensed as much, but neither text conversations nor S-expressions is very often sufficient to imply shared goals, so figured I would try to make them explicit 😄 really grateful for your questions and thoughts here.


One thing I feel is that the full scope of Clojure isn't really relevant to a learner. The only bits of Clojure they need to learn are those they're going to use; they can learn about the rest on an as-needed basis. It doesn't matter that Clojure has refs, agents, and atoms until you're in a position where you need to know about all of them. I have a vague sense of the differences between them, but since I've only ever needed to use atoms and vars so far, I don't actually need to


you can get very far only knowing about the language fundamentals, and perhaps a small but mighty subset of the standard library - the rest you can learn as you go


it's important not to delve overly deep into Clojure when there's no need for it


Whereas trying to isolate a minimal subset of, say, Ruby might be more difficult, since everything is built into the language, so you need to know about them, with Clojure, being a lisp, you can get by just fine without knowing most (or even all) of clojure.core, since you can write it all yourself once you've grasped how to write macros


the only time you need to know about clojure.core functions is when reading other people's code really, but that's rather far into the learning process


That’s a great point. Core of my question: what language features, ancillary tools/materials, ideas, and experiences have you found unusually effective in teaching newcomers to Clojure to () for themselves, and complementarily: is there anywhere you have observed people disproportionately getting stuck and dropping out? Any of three audiences: people coming from Javascript/web development; people coming from programming servers, especially in OO/OO+scripting languages; and beginners to programming. I’m not yet ready to believe that JS or Python is better to begin in 🙂


I actually think JS/Python are worse to begin in, due to their inherent complexity/largeness


especially JS has so many weird rules and quirks you need to be aware of


Python's no stranger to gotchas either though


funny you should mention those two, since they were my first two languages 😛


Likewise, but I think more people successfully begin there, at least by observation, thus driving me to this question.


🙂 that’s funny!


Well, one thing i've observed is that beginners don't necessarily need simplicity. What they need is small, easy, chunks to get their head around (which sure, it's helpful if the language itself adheres to those chunks, but it's far from a necessity). That's where their teachers come in - how you're being taught a language is vastly more important than the language itself


JavaScript is a very large language, but as long as you can start with console.log("hello world") and then move on to functions, it's not really an issue


teaching is a UX problem - doesn't matter that Wikipedia is vast, since its interface lets you explore it bit by bit, starting with the specific article you need at that given moment


a teacher is the interface between the student and what they're learning, and so the same sorts of approaches apply


@gtrak important point about the host leaking through. Re garbage-in-garbage-out, do you mean malformed/mistaken expressions -> yucky errors? If so thanks for the reminder that I have highly tuned stacktrace filters by now: really easy to forget as a blocker to interactive learning.


the biggest reason Python and JavaScript see so much success among beginners is that they're popular, so there's a lot of people teaching it and wanting to learn it (rather than any inherent learnability)


Yes, and good teachers also deftly redirect requests to get themselves out of the picture and to get students to the right resources/habits of resource finding at the right time. This is both to scale teaching as well as to self-obsolesce as a teacher! Want to keep growing my bag of tricks 🙂 301 Knowledge Moved Permanently


right! 🙂


Great points about small firewalled chunks and interactivity.


Some insightful things to read: Don Norman's The Design of Everyday Things (designing a user interface to be intuitive, approachable and delightful is isomorphic to teaching a given subject to be intuitive, approachable, and delightful: they're both about learning)


Eric Normand's is also quite good (in particular, the part about using physical metaphors to drive intuition)


An excellent example of using real-world metaphors is in Eric Normand's course on Category Theory:


(you should ask him about teaching Clojure, he has lots of experience doing it!)


Nice, thanks, I think I was at the conj talk above; thanks @U050P0ACR!


very good point about self-obsolescence by the way. it's vital to teach learners how to become more adept and more self-sufficient learners; to become their own teachers. give a man a fish and whatnot 🙂


though there's somewhat of an art to balancing student agency and teacher aid: too much of one and the students don't learn enough about the subject to be self-sufficient, too much of the other and the students never learn to be self-sufficient


i recently had a teacher who left too much to the students, and needless to say my knowledge of and confidence in the subject suffered greatly


re: 'what language features, ancillary tools/materials, ideas, and experiences have you found unusually effective in teaching newcomers to Clojure to () for themselves, and complementarily' i think the repl is really important for this. it's one thing to talk at someone, but when that person is trying things for themselves and seeing the specific results of their own exploration, it really helps them to piece it all together. especially with things like and, since they turn Clojure code into something more tangible


and that's also a major reason behind JavaScript and Python's success with beginners I feel. JavaScript has the browser, and Python has a REPL (albeit less interactive than Clojure's, though IDLE makes it somewhat better)


another thing Python has, which is quite cool to use interactively, is Tkinter


but the compiler freaks out while compiling, and it definitely works in the repl


let me hunt up an example


it would probably be helpful to provide an example of what you mean by "freaking out"


(defonce ^{:private true} testatom (atom "hey"))


^that's in one namespace. then in another namespace:


(do (alter-meta! #'ns1/testatom assoc :private false) (reset! "yo"))


That works fine in the repl, but when compiling I get this:


oh, so you aren't altering meta on the atom, you are altering meta on the var holding the atom


Exception in thread "main" java.lang.IllegalStateException: var: ns1/testatom is not public, compiling:(proj/test.clj:134:15)


oh, yeah, good point


is the do at the top level of the ns? I know there are special case rules for top-level do

zylox21:03:32 can get around private with @#'


try just calling (reset! @#' "yo")


@datran that is, (do ...) at the repl, or at the top level of an ns, doesn't act exactly like (do ...) inside a defn


hmm, let me play with that for a sec


additionally, its not crazy to have a fn in that ns that sets the value for you


alright, that seems to be working!


though that depends on what you are trying to present


so what in the world is @#' - does that read as deref the var-quote?


its dark magic and you should use it sparingly


and why does that ignore private?


private is....more of a suggestion than you might think it is


because deref of a var ignores the metadata on the var


but it returns the value of the var?


right, deref of a var gets its contents - a var is just another mutable container


okay, it all makes sense now.


thanks very much @noisesmith @zylox! 😄


use this power wisely


good for white-box unit tests, generally best avoided though


arguably needing to do something like that exposes a design flaw in the original code - a mutable singleton that determines the correctness of your code is usually a bad idea - many prefer to pass such a thing as an argument rather than hard-code the global availability


that makes testing much easier


senorflor: try the cheat sheet


a java guy i introduced clojure to thought it was a godsend


thanks @gtrak, I forgot about that!


for 'I want to program bottom-up, but learn top-down!' :-)


Re: the top down part, I’m doing some sort of CBT self-talk therapy on a thread at;cid=C03S1KBA2; let me know if you have any insight there too 🙂


here's a construct that comes up all the time, and I'm wondering if there's some kind of shorthand for it: (if (pred x) (f x) x)