Fork me on GitHub
#off-topic
<
2022-11-30
>
pez06:11:45

What gets Youtube clicks seems to be faces showing expressions. There's something special with the Clojure related faces. 😃

😂 5
Gabriel Kovacs06:11:15

Can it be joy? 😄

😂 3
pez07:11:54

Look how happy Clojure makes you!

Ben Sless18:11:55

When you look at a piece of code and can already know how it escapes to heap 😅

👀 1
Ben Sless18:11:07

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 😮

🚀 1
Noah Bogart19:11:21

can you provide an example?

Ben Sless19:11:39

@UEENNMX0T

(defn wrap [^CharSequence cs] (reify CharSequence (charAt [_ i] (do-stuff (.charAt cs i)))))

👍 1
Ben Sless19:11:07

For example, read a string represented in another language as ascii

Martynas Maciulevičius19:11:18

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

Ben Sless19:11:21

In functional programming this is called Closure, we're still waiting the Design Patterns world to catch up 🙃

Martynas Maciulevičius19:11:30

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.

Ben Sless19:11:24

in my case do-stuff was doing things with primitives inline, I just elided for brevity

Ben Sless19:11:28

you remind me a parable

Ben Sless19:11:10

> 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.

😂 4
Ben Sless20:11:25

And Haskellers will be happy to tell you polymorphism isn't exclusive to OOP

Annaia Danvers20:11:24

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)

ohno 1
Ben Sless20:11:10

is it open source, by any chance?

Martynas Maciulevičius20:11:29

*first we should ask whether it's for Clojure

Ben Sless20:11:51

I'm tolerant of the existence of other languages 😄

😂 2
Annaia Danvers20:11:13

gaze, and be horrified

phronmophobic04:12:02

I’m reminded of that parable every time I check in to see what the react project is up to.

😂 2
Martynas Maciulevičius06:12:37

What horrifies you in react if I may ask? The amount of things? 😄

phronmophobic06:12:05

I was referring back to the parable of closures and objects, but since you asked, hooks horrify me.

phronmophobic06:12:39

React originally had class based components and then did a bunch of work to support and prefer function based components.

1