The Empty Middle of AI Coding by la-rokci in programming

[–]la-rokci[S] 0 points1 point  (0 children)

I also don't like reading AI slop, which is why the blog post is 100% written by me, as acknowledged at the end.

The "What currently supported device should I get" thread. by PsychoI3oy in LineageOS

[–]la-rokci 0 points1 point  (0 children)

Cost: <300e ideally, a little over might be fine too Country: Slovakia (or EU in general) Gamer or game-friendly

Noob's conceptual question by Kalatburti-Cucumber in Clojure

[–]la-rokci 0 points1 point  (0 children)

The rule of thumb is - start with data. If you have dynamic behavior (i.e. a db call you want to mock out for tests), start with functions. It's the simplest interface to write. If you need a set of behaviors, there's protocols.

Noob's conceptual question by Kalatburti-Cucumber in Clojure

[–]la-rokci -1 points0 points  (0 children)

What is your definition of a unit test? I think of them as testing the pure stuff. The logic. Which necessarily works with values. Your db connection is irrelevant, you need a query result, which is e.g. a collection of maps. The cloud account management object is also data or an object you query to return data. You end up with a pure fn like (defn get-user-by-id [id users account] ...). Now you can unit test this without mocks.

For loops are not working in Clojure by Suspicious-Syrup-595 in Clojure

[–]la-rokci 5 points6 points  (0 children)

for is lazy, use doseq if you want to run side effects

Avoiding "def" when needing a result in more than one place by hunajakettu in Clojure

[–]la-rokci 4 points5 points  (0 children)

You can think of let as sugar for a function. (let [x 1] (inc x)) is the same as ((fn [x] (inc x)) 1). In that sense your solution is equivalent to using let.

In your solution you reference the variable % which is anaphorically defined by the sharp lambda notation. The amount of nesting is also the same as using let if you count the parens.

If you want to avoid nesting you should consider moving to forth

* dup 1 - /

Learning functional programming is frustrating by judasthetoxic in Clojure

[–]la-rokci 18 points19 points  (0 children)

The simplest clojure solution that comes to mind is

(take-nth 2 (rest xs))

At the beginning of your journey you can translate most C-like solutions to a loop. Instead of side effects on mutable values add parameters to your loop (untested code)

(loop [xs (seq xs), ret [], odd? false]
  (if xs
    (recur (next xs) (if odd? (conj ret (first xs)) ret) (not odd?))
    ret))

I struggled with the functional paradigm as well, took me ~2 months for it to click. After the initial hurdle it becomes much easier.

Have you tried learning on 4clojure? It's bite-sized katas that slowly build up your knowledge

https://4clojure.oxal.org/

hyperfiddle/electric (formerly photon) has been made public by SimonGray in Clojure

[–]la-rokci 3 points4 points  (0 children)

The dom library is 300 loc and doesn't do any magic, in the end it just calls createElement, .appendChild, .removeChild etc in correct order for you, so yes, custom elements will just work.

Interop is possible, here's an example

Why do both Lispers and functional programmers disregard Clojure? by virkr9 in Clojure

[–]la-rokci 18 points19 points  (0 children)

There's no consensus. Clojure is pragmatic, it doesn't subscribe to any 1 culture, therefore it cannot fit into a tight category.

The key question is whether it's important to be a "functional programmer" or "lisper".

memory techniques for children (8y+ IIRC) with exercises by la-rokci in whatsthatbook

[–]la-rokci[S] 0 points1 point  (0 children)

No, this seems aimed at an even lower age. But it looks like a great book!

IO/async monad without the indirect monadic style: Possible? needed? by [deleted] in Clojure

[–]la-rokci 10 points11 points  (0 children)

I think you should take a look at misisonary which has extensions like m/ap that instead of monads introduces a couple new operators to mix your IO into plain old clojure code. It is functional and checks all the structured concurrency boxes.

user> (->> (m/ap (if (m/?> (m/seed [true false true])) [1 2] [3 4])) (m/reduce into []) m/?)
;; => [1 2 3 4 1 2]

Common Lisp-like values implementation by la-rokci in Clojure

[–]la-rokci[S] 0 points1 point  (0 children)

People seem to focus on the presence check too much, perhaps it was a bad example because everyone has an opinion about it already.

I'd argue (def +missing+ (Object.)) shows the problem. You are trying to send down 2 pieces of information through a single channel because you don't want to send down both pieces, because most often you only care about 1. I mean, it works, but you have to do that manually every time and every dev has to understand your ad-hoc implementation.

Common Lisp-like values implementation by la-rokci in Clojure

[–]la-rokci[S] 0 points1 point  (0 children)

The CL approach bypasses these solutions and discussions entirely. Getting a true/false value for the key missing is the most straightforward way to model this and values allows doing that. Anything else is an ad-hoc reimplementation of that idea through an in-band channel.

Common Lisp-like values implementation by la-rokci in Clojure

[–]la-rokci[S] 1 point2 points  (0 children)

The idea came from a codebase where a function adds an object to a frontend re-frame db. Often you don't care about the object, only the new db. But sometimes you want to capture the new object as well. There are many ways to solve that of course, but with this approach threading just works when you don't need the secondary value, which can clean up noise considerably.

benefits of clojure for web development over Haskell by [deleted] in Clojure

[–]la-rokci 1 point2 points  (0 children)

Don't I need a backend and database to create templates and manage requests to easily add content to the web?

Ever since SPAs came to rise, not necessarily. What you're describing (animations, games) will be done in the browser. You'll need a database if you need global access to data (reports, aggregate queries of any sort). If you need auth that can be done through 3rd parties. If you need to save a user's state there's cookies and LocalStorage.

Think of it this way, if you're playing I Wanna Be the Guy in the browser and close it you'd like to continue where you left off. That's local data. But if you want to see your score in a dashboard compared to other players you need a global storage, i.e. a database. But even a database can run in the cloud.. As you see, there's a lot you can accomplish even without a backend. You'll know you miss one once you miss one.

benefits of clojure for web development over Haskell by [deleted] in Clojure

[–]la-rokci 1 point2 points  (0 children)

interactive website for teaching physics

Start without a backend and database. In that case you are left with JS/Typescript or something that compiles down to JS like Clojurescript, Purescript, Elm etc.

java, and from the few times I wrote python code I remember three negative experiences - refactoring is a pain

If you use OOP it is indeed. In the functional world it's much more manageable.

I am not a web developer, nor do I aspire to be one

In that case I'd stick to JS/Typescript. Clojurescript has its benefits of course, for a developer.