This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-17
Channels
- # beginners (70)
- # boot (4)
- # cider (16)
- # clara (6)
- # cljdoc (21)
- # cljs-dev (2)
- # cljsrn (1)
- # clojure (73)
- # clojure-finland (2)
- # clojure-nl (6)
- # clojure-russia (35)
- # clojure-sg (1)
- # clojure-spec (14)
- # clojure-uk (146)
- # clojurebridge (2)
- # clojurescript (128)
- # cryogen (2)
- # cursive (20)
- # datomic (27)
- # emacs (6)
- # events (8)
- # figwheel-main (57)
- # fulcro (46)
- # hoplon (3)
- # hyperfiddle (2)
- # immutant (3)
- # jobs (6)
- # jobs-discuss (15)
- # juxt (2)
- # off-topic (33)
- # parinfer (2)
- # portkey (4)
- # protorepl (1)
- # re-frame (4)
- # reagent (78)
- # ring-swagger (45)
- # schema (6)
- # shadow-cljs (167)
- # spacemacs (2)
- # specter (13)
- # tools-deps (6)
The http://figwheel.org tutorial/docs are the best I’ve read for getting started with webdev in clojure--thank you @bhauman!
i'm trying to unit test a function that calls (comp resolve symbol)
on a string that may or may not resolve to a symbol in the enclosing namespace
i'm not sure how to provide a bound symbol that the function can resolve
i tried just passing in bound symbols as arguments to the function, but that doesn't work
any thoughts?
oh, looks like resolve
optionally accepts a namespace
@michael740 there's ns-resolve
for when you want to pass a namespace to resolve from
though personally, instead of using resolve
or ns-resolve
, i would have the function take a map from symbols to values as an explicit argument
you can also get a random symbol from your namespace by doing something like (rand-nth (seq (ns-map *ns*)))
or (rand-nth (seq (ns-interns *ns*)))
originally i wanted to use resolve
because i was trying to write code that would treat json data as code, and execute it
like, what if json could be a dsl?
could a macro transform "{\"operator\" [\"operand1\" \"operand2\"]}" into (operator operand1 operand2)
?
so far, i'm just doing it with functions. first i transform the map into a list, then i resolve the strings
yeah, macros are only for transforming Clojure code into different Clojure code, so functions are the way to do it
instead of resolve
ing the strings in the function, you can have the function take a map from string to operator
replicating the resolve
behaviour (if you want that), is then just passing in the (ns-map *ns*)
map
if you only want to be able to resolve things from the current namespace, then you can use (ns-interns *ns*)
instead
@olekss.janis The REPL sometimes distorts what is going on, in this case by insisting on displaying (the P in REPL) the value produced by E. You entered a DO, which returns the value returned by the last form, namely the value returned by (p2)
. So the REPL itself is triggering the evaluation of the lazy sequence. For fun, try
(do (println "l1") (p1) (println "l2") (p2) 42)
Even if (p2)
is the last form, it will not necessarily execute.
(let [j (do (println "l1")
(p1) (println "l2")
(p2))]
42)
I haven’t read all of the backlog, but this doesn’t seem right.
do
actually “does” when needed, following the spirit of its name.
ClojureScript optimizes by eliding some non-side-effecting non-last expressions in a do
(and perhaps Clojure does as well).
Lazy sequences are quite the gotcha for folks not accustomed to them, and sometimes even us. This is one of those deals where one is always double-checking oneself. The best rule of thumb is to use doseq
for side-effects, and to think twice if one finds oneself coding doseq
nested under any lazy generator.
How do I edit the leiningen app template to update the clojure version to 1.9.0 in the project.clj file?
lein upgrade
edit your ~/.lein/profiles.clj
this is the default profile lein initially builds to
also its worth noting leiningen is still using clojure 1.8
is https://github.com/ztellman/byte-streams a replacement for https://github.com/ztellman/gloss ?
@veix.q5 no, they do different things. byte-streams handles type conversion. gloss handles binary format deserialization.
@michael.gaare hmmm, since gloss is archived, I was wondering if some other lib has deprecated it?!
@bj Here is a little on dynamic vars: https://clojure.org/reference/vars In Lisp we call tem special variables, and some refer to the asterisks as earmuffs.
Dynamic vars are insanely useful when needed (often by library code) where a suite of functions will expect to be operating in some context or other and we do not want to be forever passing around this extra “context” variable. Former Mac QuickDraw programmers will un-fondly remember juggling the global grafPort.
One thing that may help avoid confusion with earmuffs (at lest for ClojureScript devs) is that this Clojure warning will appear in the next ClojureScript release:
cljs.user=> (def *foo* 3)
WARNING: *foo* not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic *foo* or change the name at line 1 <cljs repl>
so I've been loving this (doc f)
capability in the REPL. Can I get something like that for java things? like a quick example from a tutorial used (Integer. str)
which is pretty self explanatory but am I going to be coming across more java stuff like that and if so how do I look up the docs?
well i assume that was java. maybe it's a clojure thing too but (doc Integer.)
didn't return anything
yeah that’s correct, (<Object name>.)
is syntax for constructing a new Java object in Clojure
unfortunately I don’t believe Clojure gives a defined way of obtaining docs of Java code
Java does not really have a language-level way of associating docstrings with a class or method
what you can do is: 1. Open a browser and Google the class name (kinda sucks) 2. Use an editor that can go-to the definition site, like Cursive (maybe Emacs does this too?)
ok, cool. i'll explore my spacemacs stuff and ask on that channel if i can't find anything. i think it will have something because it does autocomplete the java stuff so it's recognizing it somehow.
now whether i can do anything with that big ole doc page remains to be seen. hahaha. i'm sure it builds up with experience though
if I do find some cool capability with a java method or something can i assume i will be able to use that within my clojure functions?
yep, that’s one of the beautiful things about Clojure - we have access to all of Java as well 🙂
it’s not always great to use Java APIs though… they are usually built in a way that is very mutable and object-oriented
@chase-lambert Try this in a REPL: (require '[clojure.java.javadoc :as jd])
followed by (jd/javadoc Integer)
When I do that, it opens a browser to the Java doc page for class Integer
quick namespace question. if you called clojure.java.javadoc :as jd why do i still need to write (jd/javadoc ...)
instead of just (jd ...)
does every namespace specific call need the /
ala (foo/bar ...)
so it knows i'm calling a namespace? not sure if i'm using these words correctly.
@chase-lambert In a REPL, it is probably more common to want to avoid typing namespaces, and also to avoid typing "namespace aliases", which is what the "jd" is called in my example. You could instead do (use 'clojure.java.javadoc)
followed by (javadoc Integer)
.
The namespace clojure.java.javadoc might have many functions, constants, etc. in it other than javadoc
.
yes, which you can get explicitly if you change my example to (require 'clojure.java.javadoc)
followed by (clojure.java.javadoc/javadoc Integer)
.
In code saved in a file, it is very common to create and use short namespace aliases, like the "jd" in my first example. At the REPL, it is common to use either those, or use
to avoid them completely, as long as the names of things in the namespace you are use-ing do not collide with your names. It is fairly uncommon to use the use
variant in code saved in a file, because then it can be difficult when reading the code to determine which namespace different names originally came from.