This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-30
Channels
- # adventofcode (3)
- # announcements (4)
- # babashka (42)
- # beginners (56)
- # biff (23)
- # cider (8)
- # clj-yaml (2)
- # cljdoc (16)
- # clojure (83)
- # clojure-europe (52)
- # clojure-nl (3)
- # clojure-norway (4)
- # clojure-sweden (2)
- # clojure-uk (2)
- # clojurebridge (1)
- # clojurescript (2)
- # cloverage (1)
- # cursive (11)
- # data-oriented-programming (1)
- # deps-new (2)
- # dev-tooling (2)
- # emacs (3)
- # etaoin (4)
- # events (5)
- # fulcro (5)
- # gratitude (3)
- # java (3)
- # jobs (1)
- # jobs-discuss (1)
- # joyride (33)
- # malli (16)
- # music (1)
- # nbb (1)
- # nrepl (4)
- # nyc (1)
- # off-topic (25)
- # pathom (8)
- # re-frame (1)
- # reitit (7)
- # remote-jobs (2)
- # shadow-cljs (6)
- # tools-deps (9)
What gets Youtube clicks seems to be faces showing expressions. There's something special with the Clojure related faces. 😃
Did you know you can reify a char sequence around a string if you want to provide a by-char translation over it? Just implement charAt and you saved yourself the allocation of an entire string 😮
can you provide an example?
(defn wrap [^CharSequence cs] (reify CharSequence (charAt [_ i] (do-stuff (.charAt cs i)))))
In Java this is called "Adapter design pattern" 😄 The only difference is that you used Clojure syntax for it :rolling_on_the_floor_laughing: https://www.tutorialspoint.com/design_pattern/adapter_pattern.htm
In functional programming this is called Closure, we're still waiting the Design Patterns world to catch up 🙃
You still rely on JVM's polymorphism, so even if it's Closure that produces the object, you still use OOP's polymorphism.
But yes, in this case it allocates a single Object to avoid a string allocation which is well worth it. Unless the do-stuff
is actually pricy or nondeterministic, then it's better to be eager.
in my case do-stuff
was doing things with primitives inline, I just elided for brevity
> The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said “Master, I have heard that objects are a very good thing – is this true?” Qc Na looked pityingly at his student and replied, “Foolish pupil – objects are merely a poor man’s closures.” > Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire “Lambda: The Ultimate…” series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress. > On his next walk with Qc Na, Anton attempted to impress his master by saying “Master, I have diligently studied the matter, and now understand that objects are truly a poor man’s closures.” Qc Na responded by hitting Anton with his stick, saying “When will you learn? Closures are a poor man’s object.” At that moment, Anton became enlightened.
i have in fact built an entire object system, with inheritence and even contract-based type checking of a sort, with lambda closures (and a LOT of macros)
*first we should ask whether it's for Clojure
gaze, and be horrified
I’m reminded of that parable every time I check in to see what the react project is up to.
What horrifies you in react if I may ask? The amount of things? 😄
I was referring back to the parable of closures and objects, but since you asked, hooks horrify me.
React originally had class based components and then did a bunch of work to support and prefer function based components.