News for hackers. Stuff that matters.
Re:Elixir-style pipelines in Ruby by joeman1000 on Saturday December 10, 2022 @05:16PM (#33937487)
I've had a look at threading/piping operators in a few languages (list below). I'd say that Racket has the best one I've used. I love that you can specify a '_' for the hole which the result from the previous operation will fill. Julia's threading macro is surprisingly brittle, only letting you chain single-argument functions unless you want to use anonymous functions with one bound variable and the rest free.

+ Haskell :: https://www.schoolofhaskell.com/user/Gabriel439/Pipes%20tuto...

+ Racket :: https://docs.racket-lang.org/threading/index.html

+ Clojure :: https://clojure.org/guides/threading_macros

+ Julia :: https://syl1.gitbook.io/julia-language-a-concise-tutorial/us...

+ R :: https://r4ds.had.co.nz/pipes.html

Re:Elixir-style pipelines in Ruby by sundarurfriend on Sunday December 11, 2022 @12:55AM (#33940492)
> Julia's threading macro is surprisingly brittle, only letting you chain single-argument functions

Julia's threading/piping is surprisingly limited, but the phrasing here (combined with the link) could make things confusing to a Julia beginner. So to make things clear:

* The linked page is talking about an external Julia package which provides a macro. And that macro lets you use the `_` syntax similar to what you describe Racket as having.

* Julia's default inbuilt piping syntax is the one with the single-argument limitation, and that's an operator, not a macro.

There's been a lot of discussion about bringing the `_` syntax or something like it to the base language, but there seem to be implementation difficulties. [1]

> +R :: https://r4ds.had.co.nz/pipes.html

This page is talking about magrittr piping (which is probably still the most popular), but base R also got inbuilt piping syntax with version 4.1. It automatically passes the piped-in value as the first argument to the subsequent function. [2] [3]

[1] https://github.com/JuliaLang/julia/pull/24990

[2] https://www.r-bloggers.com/2021/05/the-new-r-pipe/

[3] https://michaelbarrowman.co.uk/post/the-new-base-pipe/

Re:Elixir-style pipelines in Ruby by fulafel on Sunday December 11, 2022 @08:46AM (#33943114)
> I'd say that Racket has the best one I've used. I love that you can specify a '_' for the hole which the result from the previous operation will fill.

Clojure also has a placeholder variant, the as-> form. Quoting the example the Clojure doc page (https://clojure.org/guides/threading_macros):

  (as-> [:foo :bar] v
     (map name v)
     (first v)
     (.substring v 1))
  
  ;; => "oo"
Re:Elixir-style pipelines in Ruby by nine_k on Saturday December 10, 2022 @05:54PM (#33937914)
+ F# :: https://fsharp.github.io/fsharp-core-docs/reference/fsharp-c... — only works with unary functions.

+ Hack :: https://docs.hhvm.com/hack/expressions-and-operators/pipe — works with any functions, uses $$ for the pipelined value.

OCaml also has a similar thing (@@) but I can't find a good reference page.

Re:Elixir-style pipelines in Ruby by fells on Saturday December 10, 2022 @06:46PM (#33938299)
OCaml :: https://v2.ocaml.org/api/Stdlib.html#1_Compositionoperators, it has `|>` for (unary) pipelines and `@@`.