This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-21
Channels
- # announcements (4)
- # aws (29)
- # aws-lambda (1)
- # babashka (21)
- # beginners (143)
- # calva (47)
- # cider (31)
- # clj-kondo (24)
- # cljsrn (4)
- # clojure (70)
- # clojure-australia (3)
- # clojure-czech (1)
- # clojure-europe (97)
- # clojure-greece (4)
- # clojure-nl (3)
- # clojure-uk (45)
- # clojurescript (70)
- # code-reviews (1)
- # conjure (7)
- # cursive (10)
- # datomic (13)
- # duct (5)
- # emacs (1)
- # fulcro (38)
- # graalvm (1)
- # graphql (9)
- # honeysql (13)
- # integrant (33)
- # jobs (14)
- # jobs-rus (1)
- # malli (7)
- # off-topic (72)
- # pathom (1)
- # re-frame (11)
- # reitit (9)
- # remote-jobs (2)
- # sci (11)
- # shadow-cljs (9)
- # sql (5)
- # tools-deps (5)
- # xtdb (6)
I don't recall ever hearing of the reverse threading macro. how does it behave differently than threading macros built into Clojure?
(defmacro <-
[form]
(loop [form form, out '[]]
(if (seq? form)
(let [f (first form)
args (first (rest form))]
(recur args (conj out f)))
(list* '-> (reverse (conj out form))))))
(macroexpand-1 '(<- (inc (inc 1)))) ;;=> (-> 1 inc inc)
;PSo, here is the code that doesn't need a Clojure threading macro, please give me the same but using a Clojure threading macro? I guess that is one way to reverse it š
@andy.fingerhut That was my interpretation of reverse threading macro
asked by bsless
Now if you can just make it so that you invoke it like this: ((inc (inc 1)) <-)
š
I think this is what @ben.sless asks https://twitter.com/cgrand/status/1281527501387440128?s=20
I keep staring at this and canāt quite wrap my head around it. How does threading the forms in reverse order not result in the forms getting executed in reverse order?
With this macro you thread other macros (if let when etc) for which evaluation order is not the applicative order. Try to expand a simple example with pen & paper.
Iāve worked out the example a bit more so it works in the repl when you paste it
(def fn-which-may-return-falsey identity)
(def fn-which-may-return-nil identity)
(def a 2)
(def y 4)
(<<-
(if (odd? a) 1)
(let [a (quot a 2)])
(when-let [x (fn-which-may-return-falsey a)])
(when-some [b (fn-which-may-return-nil x)])
#_(when (seq x)) ;;; type incompatible
(do (println x))
(if (odd? (+ x y)) 2)
3)
(macroexpand '(<<-
(if (odd? a) 1)
(let [a (quot a 2)])
(when-let [x (fn-which-may-return-falsey a)])
(when-some [b (fn-which-may-return-nil x)])
; (when (seq x))
(do (println x))
(if (odd? (+ x y)) 2)
3))
Hi! I'm experimenting with Christophe's macro to see if it's usable with our project and dev setup. clj-kondo raises warnings in many situations. I started playing with its config and I wonder... Have you found a robust way to make clj-kondo happy with idiomatic usage of the macro?
The following might help just a bit:
@U0514DPR7 writing a hook is your best bet with a macro like this
clj-kondo can run clojure macros now too, you just have to place them in your .clj-kondo folder and hook them up in the config
But I both don't fully understand what will happen for clj-kondo by doing this
ā¢ is it sane to as it to treat <<-
aka else->>
as ->>
?
ā¢ as for the example if
I'm not even sure if the warning raised by clk-kondo should be a real warning even in Christophe's and Mark's examples.
Thanks a lot Michiel; not sure if I'll be able to run with this but at least I know that we know that a solution lies ahead if we really want it! š
Just copy the macro to :
.clj-kondo/cond_better.clj
and then configure as {:hooks {:macroexpand {cond-better/else cond-better/else}}}
ok, the scroll position of your link in my screen showed me things about rewrite-clj nodes, but the actual macroexpand doc you linked too (and your help above) make it much more friendly to try, thanks again, I'll report back
yeah I don't know what's up with linking to relative uris (or how do you call these), it often fails for me too
Oh a few days ago I stepped upon this new Chrome deep-linking-highlighting feature, let's see how slack renders it and how following the link shows the page https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md#:~:text=Macroexpand,clojure.set/union%20https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md#:~:text=Macroexpand,clojure.set/union%20...)
in chrome:
Wow, this looks like it's magical! Kondo still reports some cases of missing else branches, but it looks like it only happens in the one-liners and those don't make sense. The example with more lines is more realistic and Kondo seems to have picked up the threading of the else branch of the if. š
Michiel, this is very impressive... Clojure seems to give us so often tooling that works well at every layer!
Some general thoughts about beginner friendliness, adoption and learnability of Clojure. Disclaimer: Iām teaching web programming/development for designers part-time, so Iām strongly biased. IMHO web programming (frontend) is likely one of the best introductions to programming for several reasons: * Very fast feedback loops: You code, save and you see the results immediatly. * GUI/user centric: printing stuff on your terminal/REPL ist not very exciting for most beginners. * Familiar: you build something you already understand as a user and conceptually, very few concepts have to be learned. * Practical / reach: you can publish a website easily, you create something that you can show and has value. * Creative: the web is an open system with tons of capabilities, from drawing to calculating to communicating etc. However, most introductions to Clojure seem to start with JVM Clojure and almost none of them are truly introductory. Java and the JVM are scary! Someone who is familiar with these and has substantial experience will consider Clojure, because it solves problems they know from experience. Others are likely comming from learning Scheme/Racket via SICP etc. (Scheme has a strong tradition as a educational language and fantastic books/resources) and they are looking for a Lisp that has a strong pragmatic focus. They will happily take those hurdles. But what about real beginners. They might have written āHello World!ā with Python and know what a loop is or created a rudimentary HTML/CSS website. Or maybe they donāt even know where to start. I think there might be an opportunity to build learning resouces for real beginners based on the web and ClojureScript. Likely a subset of ClojureScript, with a set libaries focussed on learning, or even a simpler learning DSL that is built on top of ClojureScript. Examples of thinkable libraries/features: * easy and fast setup. There needs to be some time limit, like 5 minutes. * a simple, constrained GUI library * a networking library based on AJAX or websockets * maybe canvas/webgl to create some simple games All of these features have to be stripped down to the essence, have very strong ājust worksā conventions and very little to no configurability. Sorry for the long rant. But I really wonder what you guys think of these ideas, especially since I donāt know all the beginner resources for Clojure. Even pointers like X does already do that or have a look at Y are welcome.
My view (which I have previously expressed in the Clojure Slack) is that I donāt see Clojure as a suitable language to teach to beginners. Similarly, I donāt see Java/Kotlin/C++ as suitable languages either. when learning to program as a beginner, you need to limit the surface area of things that you need to learn and the above languages donāt do that sufficiently for my liking.
When I learned Clojure, I already knew Java and I had already learned Emacs and Slime (it was a while ago). I personally would have struggled if hadnāt.
(Iām still interested in hearing about tools/resources that you can learn in five minutes and hearing about experiences of beginners leaning Clojure because I could be completely wrong, of course.)
Those are very good points. I agree especially with the surface area part. A beginner should be programming against very simple interfaces at the start. I think a Lisp is inherently suitable, because of its meta programming capabilities and dynamism. You can build a library of macros around a beginner experience. I disagree with having to learn Emacs though. I think VSCode and others enable a better beginner experience.
If they are real beginners, then would such a course include learning HTML, CSS, AJAX, too? Or assume you learned those already somewhere else?
No! I thought more of having very constrained abstractions that use those things under the hood, and maybe you can dig down gradually to expose them over time.
I believe it was lighttable or something like that which seemingly had the ābatteries super includedā approach to things with built in templates and such.
ClojureBridge was designed to teach Clojure to total beginners (although many attendees were already programmers in other languages) and one of the struggles we faced was trying to figure out learning exercises that were fun and provided the sort of feedback students like best. I think ClojureBridge has tried several curricula with at least one focused on graphics (Quil on the JVM, I think).
Ah, there are five choices of app now, including one web app...
@hobosarefriends Yeah, LightTable was really good in the early days but once it became incompatible with macOS after one of the O/S releases, it wasn't a good experience for teaching. I think ClojureBridge used NightCode for a while which is a really simple Clojure all-in-one editor. [Confirmed: see https://github.com/ClojureBridge/curriculum/blob/gh-pages/outline/setup.md ]
Iām really thinking in terms of āIntroduction to Programmingā and not āIntroduction to Clojureā
There are many people who would benefit from learning how to program, not necessarily to become programmers full-time. Iām being a bit āin your faceā here: There are things you cant put in front of 70% of beginners at the frist hour or so. * data structure concepts * lots of declarations * not seing a GUI * lots of setup Essentially they have to see some satisfying results in a couple of minutes.
I think this part of clojure has been improving dramatically. For minimizing setup, I think https://github.com/babashka/babashka could be a really good fit. You could even have a download that included all the dependencies you were interested in. When it comes to GUIs, I'm pretty biased since that's the project I've been working, https://github.com/phronmophobic/membrane. The hello world for membrane is:
(require '[membrane.skia :as backend]
'[membrane.ui :as ui])
;; Show a window that displays a "Hello World" label
(backend/run #(ui/label "Hello World"))
Making programming more accessible is a topic I'm interested in, so if you do end up going with a non-web approach, then I would be happy to help.depending on your time horizon, since clojure is expression based and repl friendly, it could become a great language to build beginner friendly programming environments
I just remember now, I started programming in QBasic (I think). We were able to put in a floppy, write a couple of lines and then see pixels on the screen.
Iām thinking of that kind of experience, but then gradually (and very friendly) building up knowldge and familiarity with programming in general and Clojure specifically.
https://www.maria.cloud/ might be worth looking at too
I've always thought the beginner persona is highly conflated (absolute beginner to programming? new to webdev? new, coming from a different lang?)
For absolute beginners, webdev seems so complex, dragging so much historical baggage, fads etc that it can be just confusing to newcomers
Ruby's irb
console seems pretty self-contained and unassuming. Not sure if it allows one to code visual games like QBasic does though :)
Thatās a very good point actually. There are very different types of approaches and beginners. Since Iām teaching designers to code, it is useful and easy for them to think in terms of layouts. Others think well in terms of abstractions/math, and then there are learners who think in terms of machinery. For the latter it is useful to start with something like C, assembly or even by constructing machines manually.
yeah I was thinking a bit about that - some people may be more 'visual-thinking' than others although I wouldn't underestimate how hard can learning the basics be: variable assignment, divide-and-conquer with functions, etc. those routinely blow children's / teens' minds so if they don't get to understand those, the rest of the learning could collapse by its own weight
GWBasic's PLAY statement got me hooked to programming in primary school ;) (https://hwiegman.home.xs4all.nl/gw-man/PLAY.html)
Seems pretty ellaborate :) I recall playing a bit with https://en.wikibooks.org/wiki/QBasic/Sound#SOUND (much to the annoyance of my classmates)
Me too!!! QBasic's Sound
and Play
(at age 10) is when I knew I wanted to make software as a grown up.
Yep. no tool, method, language or book is going to do the learning for you. Thatās something each person need to figure out themselves.. eventually. āHow do I learn this thing the best?ā. āHow do I find the relevant resources to guide my learning?ā āWhere do I need help?ā.