This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-05
Channels
- # beginners (229)
- # cider (54)
- # cljs-dev (187)
- # cljsrn (1)
- # clojure (187)
- # clojure-dev (5)
- # clojure-italy (31)
- # clojure-losangeles (1)
- # clojure-russia (3)
- # clojure-spec (76)
- # clojure-uk (29)
- # clojurescript (94)
- # cursive (18)
- # datascript (8)
- # datomic (26)
- # docker (6)
- # emacs (19)
- # figwheel (6)
- # fulcro (41)
- # garden (1)
- # graphql (1)
- # hoplon (33)
- # jobs (1)
- # jobs-discuss (1)
- # lein-figwheel (14)
- # leiningen (7)
- # nrepl (10)
- # nyc (1)
- # off-topic (2)
- # onyx (2)
- # parinfer (25)
- # portkey (6)
- # powderkeg (1)
- # protorepl (1)
- # re-frame (14)
- # reagent (14)
- # shadow-cljs (31)
- # spacemacs (3)
- # test-check (33)
- # uncomplicate (1)
- # unrepl (40)
- # vim (5)
- # yada (16)
thanks for the help guys, the space issue was a Cursive configuration option related to pretty printing (useful for data structures)
hey all, I'm getting an error trying to load a local edn file
this is the file, creds.edn
{:consumer_key "asdadasdasd"
:consumer_secret "asdasdasdasd"
:access_token "asdasda-asdasdasdasd"
:access_token_secret "asdasd"}
and some code to load it:
(ns cool-beans.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs-lambda.util :as lambda]
[cljs-lambda.context :as ctx]
[cljs.nodejs :as nodejs]
[cljs-lambda.macros :refer-macros [deflambda]]
[cljs.core.async :refer [put! chan <!]]))
(def credsMap
(-> (nodejs/require "fs")
(.readFileSync "static/creds.edn" "UTF-8")
read-string))
using clojurescript 1.10.64
but I get the error: module initialization error: TypeError
@derpocious It would be interesting to know if that is a regression in 1.10.64 (a beta release) relative to 1.9.946 (the current version)
that's the exact syntax to load an edn file in the starter project made from lein cnew cljs-lambda
which uses cljs 1.8.51
I upgraded my project, but I'm not sure if the syntax changed or I'm just doing something wrong
Seems weird to me though that you would use the nodejs version of require for edn files
oh maybe I am just missing the require for it
[cljs.reader :refer [read-string]]
@derpocious FWIW, if I compile
(ns cool
(:require
[cljs.nodejs :as nodejs]
[cljs.reader :refer [read-string]]))
(def credsMap
(-> (nodejs/require "fs")
(.readFileSync "static/creds.edn" "UTF-8")
read-string))
(prn credsMap)
with 1.10.64 and run it in Node, it prints out
{:consumer_key "asdadasdasd", :consumer_secret "asdasdasdasd", :access_token "asdasda-asdasdasdasd", :access_token_secret "asdasd"}
Since you are using 1.10.64, you can use cljs.main
to test that it works by doing
clojure -Srepro -m cljs.main -re node cool.cljs
with deps.edn
containing
{:deps {org.clojure/clojurescript {:mvn/version "1.10.64"}}}
thanks @mfikes!
mine says 1.10.64
oh whoops
but I just used lein ancient upgrade :check-clojure
to upgrade
is there a way to specify a version?
can I just change it in project.clj, do lein deps
, and then everything should work?
don't I need to change the clojure version with it?
or 1.9.0 should be fine
thanks. but suppose I have this code and want to extract the map into a separate edn file
(def Twitter
(new twit
#js {:consumer_key "sfgs"
:consumer_secret "sdfgdsg"
:access_token "sdfg-zsdfgsdfg"
:access_token_secret "sfgsdfgsdfg"})))
an am getting error that it's expecting map, but when I try to use the defined map it give me an error
@derpocious The read-string
call is returning a persistent map. In your Twitter example, that is a JavaScript object. (Note the #js
.) You can convert your persistent map to a JavaScript object using clj->js
.
Backing up a little, I'm assuming you are doing
(def Twitter
(new twit credsMap))
and instead you likely need
(def Twitter
(new twit (clj->js credsMap)))
based on your example abovewow, excellent 🙂
is that all one thing, cljs->js
like is that one macro?
interesting, but why do I not have to require it?
It is cljs.core/clj->js
; since it is in core, there is no need to require it, like map
, filter
, etc.
ah I see
well thanks a lot for all the knowledge! I'm going to continue on until I hit another roadblock. 🙂
I have a function I use to solve n-puzzle using A*. Though this works for 3x3 puzzles fast enough, it takes hell of a long time to solve a random 4x4 puzzle (I have run the algorithm for a random 4x4 puzzle for two hours and still no result). So I want to profile the code. I want memory usage of each maps/sets/lists being used and I want to get timings for functions.
you can use jvisualvm
for this. it’s not a Clojure-sepcific tool, but it comes install by default with Java and is a good starting point imo
What tool could I use? If it’s non-intrusive (I don’t have to do any code change), better
The relevant code is here: https://github.com/nakiya/npuzzle/blob/master/src/clj/npuzzle/puzzle.clj
Hello guys. Do you have to suggest me any tutorial or book for beginner? I am coming from Python 😁
Since you already know programming, you should pick up Programming Clojure: https://pragprog.com/book/shcloj3/programming-clojure-third-edition
other beginner books which are good: Clojure for the Brave and True, and Living Clojure
also this series of blog posts: https://aphyr.com/tags/Clojure-from-the-ground-up
I am also coming from the Python world — I attempted to create a 15' tutorial here: https://orestis.gr/your-first-clojure-code/
OK, perhaps I can be forgiven for plugging my own book... Getting Clojure, currently in early release, is also aimed at beginners. If you want you can check out some sample chapters over at http://bit.ly/gettingclojure But obviously I'm biased.
Although I didn't read Russ' book yet, it looks very interesting and I'm looking forward to reading it. It also includes some latest stuff like Spec. I don't consider myself to be a Clojure beginner anymore but I believe every Clojure novice can get tremendous value from it.
Dear beginners, please give me feedback on this draft of a guide about the Clojure REPL, which I intend to submit as the REPL guide on http://clojure.org: https://5a9d2be7be40f13a7f060a2c--clojure-site-preview-vvvvalvalval.netlify.com/guides/programming_at_the_repl.html
@U83GGL8DA from what I read above, this might interest you.
This is huge — major props and thanks for taking the time to read all that. Is there any more persistent place for people to post feedback? E.g. reddit thread/clojureverse?
@U7PBP4UVA yes ClojureVerse https://clojureverse.org/t/writing-a-beginner-friendly-repl-guide-for-clojure-org-please-send-me-inspiration/1578
This is really helpful. More material like this targeted at beginners and giving a comprehensive overview of some facet of clojure programming would help people like me. During the past few days, I’ve been doing my first Clojure program, and it took me three or four days to realize that I could connect to a nrepl in a split window in the Cursive editor and use that to eval forms and load whole files, etc. Even then, I didn’t know about most of the things here. Some other stuff that I have trouble over is 1. understanding lein project file and commands, 2. Debugging (What would be a proper way to do it, etc). I feel that a lot of documentations online presuppose a lot from the developer. Or they are written for geniuses. This article is way more accessible and helpful for that reason. I hope there will be more material like this. Thanks for taking your time for writing this.
It may not be within your styleguide to mention libraries not supported by the Clojure core team. But if it is, I think it would be interesting to note in "Data Visualization at the REPL" that 1) inspector is a Swing GUI and 2) there exists a library, seesaw, which functionalizes/datafies Swing
I bring it up just 'cause Stuart Halloway spoke last year and suggested more people should be launching little GUI debugger helpers from the REPL. I think it's an interesting idea
Ah! I see that you do link to it at the end. I would still put in a one-sentence mention in the data visualization section
@U83GGL8DA I'm glad you find it helpful - being very inclusive of beginners was one of the objectives. Regarding debugging, what do you think of the dedicated section in the guide? See https://5aa147747b6ee8595c2301b3--clojure-site-preview-vvvvalvalval.netlify.com/guides/repl/enhancing_your_repl_workflow.html#debugging-tools-and-techniques
@U06GS6P1N: I was adding println
s all over the place before to figure out what was going on, but it left a bad taste in my mouth. After reading yours, I sort of don’t worry about it that much. Now I’m adding print statements anywhere where I need to have a look. It’s a different way of programming for me.
I’m using cljs a lot and the biggest problem I have now are these enormous stack traces which drive me nuts.
@U83GGL8DA you should also probably take a look at this https://medium.com/@roman01la/debugging-clojurescript-6e4d903e831 and this https://github.com/binaryage/dirac
Will do, thanks @U06GS6P1N
does anyone have a safe and lazy way of serving their js files from node_modules (ex: jquery)? do you use lein to move individual files to public directories? or do you set up a separate route and serve small parts of the node_modules directory? the latter seems to be the recommended method but it feels wrong to serve files from outside the public directory.
by dispatching events 🙂
alright thanks! that's what I was thinking of but did hope to get something more like ... direct
You can (for dev purposes) create a event subscription pair to modify the DB however you wish
(reg-event-db
:reset-db!
(fn [_ [_ new-db]] new-db))
(reg-sub :db (fn [db _] db))
(dispatch [:reset-db! (my-update-fn @(subscribe [:db])))
Is there a channel for beginners who are totally new to programming and learning Clojure as a first language? I’ve been to two introductory workshops with one-on-one coaching, but this channel’s content still seems very advanced to me. It’s pretty intimidating, there’s no way I’d feel comfortable posting my much more basic questions here.
People in this channel tend to be pretty patient and understanding. While there are some more intermediate questions in this chan, I'm sure everyone is happy to answer questions at any level. ask away when you're ready! 🙂
@amelia ask away, if anything it will make us better teachers
I appreciate that, but as a complete newbie I think I’d just feel too self-conscious in this space. I asked the question in part to highlight the issue - I’m speaking up, but you should consider that not everyone will.
there’s tons of complete newbies here — this is exactly what this channel is for. A channel specifically for people new to programming doesn’t exist in this slack (yet? :) )
a #programming-beginners channel could be a good idea but there’s the problem that there’s 3.7k people here and 0 in a non existent channel
I was gonna say it's not a good idea, but hell I don't see any downside to giving it a try 🙂
worst case scenario it is a smaller channel where some or most questions escalate to here, but it is at least a safe space to test the waters
https://www.maria.cloud looks like a great intro to programming using Clojure
Thank you! 😁 I’ll contribute as much as I can, probably not hard since I spent hours yesterday just asking myself “Why won’t this work” over and over about something extremely simple
You might be surprised that you’re likely a better programmer already than some professionals who have been doing this for 10-20 years!
No it’s true. I have interviewed some with over 20 years experience in a single programming language that cannot even code something simple like: Create a list of numbers.
It's a strange market. Programming itself is easy, e.g. write a function that given some input returns some output. Yet no one has really created a blueprint of how to successfully build a real application. Most of us come to Clojure after years of pain with other programming languages.
I’ve gone to introductory events for a number of languages, and I work in a tech startup with developers who’ve been kind enough to walk me through basic principles, but at a point now where I just need to focus on one and build up a working knowledge. Clojure is my favourite so far, and the inclusiveness of the community is a real plus (and the reason I felt comfortable asking about an alternative channel).
The only downside is the market for Clojure jobs (and functional programming languages) is still really small. The plus side is that you will have a skillset that few developers have.
I actually just want to be able to build things for myself - I’m a bit entrepreneurial, and being unable to code what I can imagine is holding me back. I like the simplicity of Clojure, being able to code what I can imagine actually feels near-future possible.
I have the perfect beginner project in mind, just need to get a bit more comfortable with basic stuff (like defn!) then I’ll get started.
I took a look at Maria yesterday but after two introductory workshops it covers a fair amount I’ve looked at there
here's the relevant piece of code in my project
(ns clogue.display.ascii-window
(:require [lantera.screen :as s]))
here's the error when i run
Exception in thread "main" java.io.FileNotFoundException: Could not locate lantera/screen__init.class or lantera/screen.clj on classpath., compiling:(clogue/display/ascii_window.clj:1:1)
at clojure.lang.Compiler.load(Compiler.java:7391)
at clojure.lang.RT.loadResourceScript(RT.java:372)
at clojure.lang.RT.loadResourceScript(RT.java:363)
at clojure.lang.RT.load(RT.java:453)
at clojure.lang.RT.load(RT.java:419)
...
but:
❰liamdyer❙~/mydev/clogue❱✔≻ jar tvf ~/.m2/repository/clojure-lanterna/clojure-lanterna/0.9.7/clojure-lanterna-0.9.7.jar
116 Thu Nov 24 12:17:02 CST 2016 META-INF/MANIFEST.MF
2796 Thu Nov 24 12:17:02 CST 2016 META-INF/maven/clojure-lanterna/clojure-lanterna/pom.xml
636 Thu Nov 24 12:17:02 CST 2016 META-INF/leiningen/clojure-lanterna/clojure-lanterna/project.clj
636 Thu Nov 24 12:17:02 CST 2016 project.clj
377 Thu Nov 24 12:17:02 CST 2016 META-INF/leiningen/clojure-lanterna/clojure-lanterna/README.markdown
0 Thu Nov 24 12:17:00 CST 2016 META-INF/
0 Thu Nov 24 12:17:00 CST 2016 META-INF/maven/
0 Thu Nov 24 12:17:00 CST 2016 META-INF/maven/clojure-lanterna/
0 Thu Nov 24 12:17:00 CST 2016 META-INF/maven/clojure-lanterna/clojure-lanterna/
108 Thu Nov 24 12:17:00 CST 2016 META-INF/maven/clojure-lanterna/clojure-lanterna/pom.properties
0 Thu Nov 24 12:14:40 CST 2016 lanterna/
997 Sat Dec 12 13:17:56 CST 2015 lanterna/common.clj
3275 Sat Dec 12 13:17:56 CST 2015 lanterna/constants.clj
9455 Thu Nov 24 12:14:40 CST 2016 lanterna/screen.clj
8729 Sat Dec 12 13:22:20 CST 2015 lanterna/terminal.clj
0 Sat Dec 12 13:17:56 CST 2015 README.markdown
i think you misspelled lanterna in your (ns clogue.display.ascii-window (:require [lantera.screen :as s]))
if i could dump some more code on y'all
(defn draw-state [entities]
(let [size (s/get-size @screen)
width (first size)
height (second size)]
(do
(debug "screen is " width " by " height)
(for [x (range width)]
(for [y (range height)]
(let [glyph (get-glyph x y entities)]
(do
(debug (str "drawing " glyph " at " x " " y))
(s/put-string @screen x y )))))))
(s/redraw @screen)
(s/get-key-blocking @screen))
❰liamdyer❙~/mydev/clogue❱✔≻ lein run
18-03-05 17:14:16 TC-HQ-MBP--6396-William-Dyer DEBUG [clogue.display.ascii-window:25] - screen is 80 by 24
it threw an NPE on
Caused by: java.lang.NullPointerException
at clojure.lang.Numbers.ops(Numbers.java:1013)
at clojure.lang.Numbers.isPos(Numbers.java:96)
at clojure.core$dorun.invokeStatic(core.clj:3036)
at clojure.core$doall.invokeStatic(core.clj:3039)
at clojure.core$doall.invoke(core.clj:3039)
at clogue.display.ascii_window$draw_state.invokeStatic(ascii_window.clj:24)
Small note, you don't need nested for
statements, (for [x (range width) y (range height)] ...)
should iterate through all possible x y combinations
here:
(defn dorun
"When lazy sequences are produced via functions that have side
effects, any effects other than those needed to produce the first
element in the seq do not occur until the seq is consumed. dorun can
be used to force any effects. Walks through the successive nexts of
the seq, does not retain the head and returns nil."
{:added "1.0"
:static true}
([coll]
(when-let [s (seq coll)]
(recur (next s))))
([n coll]
(when (and (seq coll) (pos? n))
(recur (dec n) (next coll)))))
for
is lazy list comprehension, it has nothing to do with the for
you might be used in C-like languages
The advantage of for
is the binding forms it allows you. e.g.
(for [x [0 1 2 3 4 5]
:let [y (* x 3)]
:when (even? y)]
y)
@scot-brown you can in doseq
too
oh hell yeah http://recordit.co/lwB0sOT0vh thanks everyone
I'm spec'ing. How do I spec an argument that can be any of the clojure.core functions? e.g. inc
Hi any suggestion for an event dispatcher in clojure?
@elena.caraba Can you clarify how ifn?
"is not correct"?
@seancorfield The error I get back is "java.lang.RuntimeException: Map literal must contain an even number of forms "
@elena.caraba OK, so that says your syntax isn't correct -- but isn't related to ifn?
Can you share youre code?
Please show your code -- I think you just have a syntax error in your spec.
@elena.caraba Specifically it's saying that you have a map that has a key w/o a value (or a value without a key, depending on how you look at it), something like {:name "russ" :age}
@russ767 I think you may be right. So does this mean that spec-ing is discovering errors in my source code?
you're not hitting spec yet. you're seeing an error from the reader. you've got a malformed map literal somewhere. and i think @seancorfield is right that it might be in your spec
Right, this is the kind of error you get as the code is being read in right at the start.
@elena.caraba right, that {:pre ...}
map needs one value. (Put all of those spec/valid?
calls in one larger vector.)
I think you want
{:pre [(spec/valid? m/array? m)
(spec/valid? int? i)
(spec/valid? int? j)
(spec/valid? ifn? fct)]}
It also seems the preconditions are referring to i
and j
, which aren’t args.
But, as an aside @elena.caraba what you are doing can also be done via instrumentation in spec. (You can write a spec that says that dosmth
’s args must comply with some specs, and then enable “instrument” the dosmth
fn at runtime—typically at dev time.)
Instrumenting with spec is covered here https://clojure.org/guides/spec#_instrumentation_and_testing
@mfikes pulling them all in one vector worked, though I don't understand why... i, j are supposed to be r,c
Oh, I misunderstood your comment @elena.caraba: All of the preconditions that you want to apply are put into a single vector
This allows for a syntax where you have all of the preconditions in that map under :pre
and all of the postconditins under another key :post
Ahh, TIL, it is called a “condition map” https://clojure.org/reference/special_forms#__code_fn_code_em_name_em_em_param_em_em_condition_map_em_em_expr_em
@mfikes Gotta love that url.
I'm getting a strange linter error... in my code I have (Math/floor (/ (- score 10) 2))
which is working when I run it... however my linter is complaining that it is unable to resolve symbol Math
... do I have to define Math
somewhere? I was a bit confused on how to call it... but it seemed to just work.
your linter is bad if it doesn't recognize interop in scope
ok. I'm cool with just ignoring it... I just wanted to make sure I wasn't supposed to explicitly import it into the namespace or something
also "unable to parse" is weird here - I mean it's a valid clojure symbol
java.lang.* is always in scope in jvm clj
now you might have an issue in a cljc file, and definitely in a cljs file - but it's always valid to use Math/* in clj
yes, it should be js/Math
oh, cool - but I'm less surprised with a cljs linter not recognizing Math/
ok sounds like it's just the linter is a bit confused then. I just wanted to make sure it wasn't "magically" working due to something local on my system that would break later. 🙂
I just discovered the (. Math floor x)
form works in clj, but not in cljs
(that's a lower level form of interop syntax, mostly only useful in macros)
also (.floor Math x)
works in cljs, but not clj
Yeah, I had found https://cljs.github.io/api/syntax/Math-namespace ... which made it sound like Math/
should just work... but it was a little confusing to me where this namespace is...
I wish I could find a formal doc on this, but https://github.com/clojure/clojurescript/blob/ff573d12d8f868c980585445ff39b957967b6dce/src/main/clojure/cljs/compiler.cljc#L1026
oh wow, that's quite the special case, haha
it's like, the only built in js class treated that way
right (.floor js/Math x) works
it's like an implicit pseudo-namespace, as a special case
It makes writing portable .cljc
code a little easier. And it is easier to context switch between Clojure and ClojureScript as a human.
I could see that. I'm working pretty much exclusively with ClojureScript since I'm working with react-native, but that makes sense in terms of context switching
Oh, @kara also, if you weren't aware, there is a #cljsrn channel for React Native-specific stuff if you encounter any