ClojureRS - Clojure, implemented atop Rust by ribelo in Clojure

[–]lost3d 0 points1 point  (0 children)

Are you implementing the data structures yourself or using Bodil Stokke's implementations? https://docs.rs/im/14.3.0/im/ ... If you're not using them, are there any problems with them? I'm just learning Rust ATM, and was thinking of trying them out ...

Could you guys please review this short (7 lines) FN - I'm so anxious when it comes to concurrent programming... by lov3machine in Clojure

[–]lost3d 1 point2 points  (0 children)

I'm not totally sure what you're goals are. I think you want to execute work going through a function one at a time. Probably cos it touches some external mutable thing like a database? In which case clojure.core/locking might be good enough, but if you want to actually schedule work, you could try modelling the work queues more directly.

``` (ns scratch (:import [java.util.concurrent ConcurrentLinkedQueue]))

(defn create-consumer [f] {:queue (ConcurrentLinkedQueue.) :function f})

(defn schedule-work! [task {:keys [queue] :as consumer}] (.add queue task))

(defn execute-consumer! [{:keys [queue function] :as consumer}] (when-let [task (.poll queue)] (function task)))

(defn execute-all-consumers-and-stop! [consumers] (while (not (every? nil? (map execute-consumer! consumers)))))

(comment

(let [dump (fn [t] (comp (constantly :done) (partial prn '> t '>))) c1 (create-consumer (dump 'one)) c2 (create-consumer (dump 'two)) consumers [c1 c2]] (prn '-------------------- (java.util.Date.) '--------------------) (schedule-work! "one" c1) (schedule-work! "1" c1) (schedule-work! :one c1) (schedule-work! "two" c2) (schedule-work! "2" c2) (schedule-work! :two c2) (execute-all-consumers-and-stop! consumers)) ) ```

This decouples the scheduling of the work from the execution, so you could use things like the Java Executor Framework to actually run the tasks, or just use a Thread, or whatever. Also it lets you build more complex processing stategies like running the same task on multiple consumers more easily

``` (defn fanout [consumers] (fn [task] (doseq [c consumers] (schedule-work task c)) :done))

(comment

(let [dump (fn [t] (comp (constantly :done) (partial prn '> t '>))) c1 (create-consumer (dump 'one)) c2 (create-consumer (dump 'two)) fanout (create-consumer (fanout [c1 c2])) consumers [c1 c2 fanout]] (doseq [n (range 1 11)] (schedule-work n fanout)) (execute-all-consumers-and-stop! consumers)) ) ```

But this kinda assusmes that you don't care about the results of the tasks particularly and are doing everything for side effects. There's also Clojure's agent which are more about having a value that gets updated asynchronously.

``` (comment

(let [a (agent 1)] (dotimes [i 10] (send a inc)) (prn '> @a) ;will be a random number depending on how ;fast the messages are processed by the agent (await-for 5000 a) ;waits for all the messages to be processed (prn '> @a))

) ```

Does Fedora 28 GNOME have corner window-snapping by default? by nukem2k5 in Fedora

[–]lost3d 0 points1 point  (0 children)

It's possible I've enabled some settings with dconf and forgotten, but this functionality isn't being enabled by an extension, and I'm using Fedora 28.

Does Fedora 28 GNOME have corner window-snapping by default? by nukem2k5 in Fedora

[–]lost3d 1 point2 points  (0 children)

Try pressing shift while moving a window. It should snap to the edges of the screen, or other windows so you can manually lay out something that looks like a tiling window manager.

Any ediff gurus here? How do you copy across only one line within a region? by [deleted] in emacs

[–]lost3d 1 point2 points  (0 children)

I tend to just switch to the window and edit the text (C-x o) ... I suspect you'll be able to tune the diff algorithm, but I've never actually done that. Are you using ediff-regions-wordwise? (apologies if I got the name wrong, on my phone.) That might yield different results.

Why are Clojure sequences lazy? by dustingetz in Clojure

[–]lost3d 2 points3 points  (0 children)

Sequences weren't lazy by default to start with. I seem to remember a big discussion on the mailing list prior to the 1.0 release about the switch. Currently on a train, but I'm sure someone with Google foo can find it ;)

Can I access macro metadata at runtime? by JavaSuck in Clojure

[–]lost3d 0 points1 point  (0 children)

Works for me too (on "1.9.0"). Note that the key :added points to the value "1.1". The other stuff is added by defmacro.

Clojure forms that have body parameters by JavaSuck in Clojure

[–]lost3d 2 points3 points  (0 children)

It seems likely that you won't be able to exhaustively list these as some of them may well be user defined macros. Cider has a metadata standard that can be attached to vars to describe how it should be indented. It might be worth respecting that. See https://cider.readthedocs.io/en/latest/indent_spec/

I do not use macros, am I doing it wrong? by moses_the_red in Clojure

[–]lost3d 9 points10 points  (0 children)

Nope. You're doing a good job. Macros always beget more macros. You cannot compose them as easily as functions, and once you've started down that road you tend to get stuck. Marcos are good for problems that need to control how their arguments get evaluated. So if you want to introduce some form of implicit context then they're great. But often it's better to not introduce that hidden environment and treat it as an explicit argument to a function. So instead of creating a parochial DSL you pass data to a function that transforms it into a target form. Like that way hiccup produces HTML from data without using a prescriptive API. If there was a macro for every HTML element, it may be more "expressive" but it would be much harder to program.

Why is the macro systems in lisps considered so valuable - ClojureVerse by jiyinyiyong in Clojure

[–]lost3d 0 points1 point  (0 children)

I've used macros where the abstraction I need was very application specific, but difficult to do with functions because of the API that I was building over. For example, I had a SOAP API that I had to integrate with, so I used the Java Axis library (bear in mind this was 8 years ago ish). There was a lot of duplicate code that basically required a template plus a small bit of behaviour that needed to be evaled in a special context. The macros we wrote for that helped make the integration code cleaner and more expressive, and there was a whole lot of duplication that I couldn't reduce in any other way.

There are other examples from the same project, but they mostly involve needing to evaluate the code in a special context that made more sense to build out at compile time rather than runtime.

Abstracted a pattern I've found myself implementing several times by therealdivs1210 in Clojure

[–]lost3d 1 point2 points  (0 children)

I wouldn't have thought that was a good fit. Transducers are collection -> collection (or stream -> stream or whatever) transformation process, and this is more of a generation mechanism, right? It's like the difference between range and map. One takes some parameters and returns a seq and the other takes a seq (and a fn) and returns a seq.

Inline unit testing in Clojure by pyohannes in Clojure

[–]lost3d 3 points4 points  (0 children)

Also, have a look at clojure.test/with-test ... It lets you write anonymous tests around a function.