4 ms·
This is hilarious, and clearly a joke, but it does make one think. I've always thought that it would be nice to have variables which you don't name, which only
by oivaksef 6y ago
This is hilarious, and clearly a joke, but it does make one think. I've always thought that it would be nice to have variables which you don't name, which only live over a couple of lines, where it's clear the variable is just for some plumbing and doesn't need a name. I wonder if there is actually something in these two concepts combined
- 8note 6y agoHow do you reference a variable for plumbing if it doesn't have a name?
- inivekin 6y agoWouldn't any concatenate language fit the bill? https://concatenative.org/ https://concatenative.org/
- thepratt 6y agoWould Elixir's pipe - https://elixir-lang.org/getting-started/enumerables-and-streams.html#the-pipe-operator https://elixir-lang.org/getting-started/enumerables-and-stre... - or Haskell's function composition - https://wiki.haskell.org/Function_composition https://wiki.haskell.org/Function_composition - fit the criteria?
- oivaksef 6y agoThose would. The Elixir style feels nice. I wonder if something like that could make it into Ruby 4
- acidbaseextract 6y agoMentioned in another sub-comment, but Clojure's threading macros do this. They do it by making positional assumptions about the implicit argument: https://clojure.org/guides/threading_macros https://clojure.org/guides/threading_macros
- nonameiguess 6y agotidyverse packages in R do this. Normally, you might have something like this: df = someFunctionThatReturnsADataFrame() newDf = someFunctionThatTakesAndReturnsADataFrame(df) doSomethingTo(df) Since R lets you define your own operators, they took '%>%' and defined it as "pipe the return value from one function as the first argument to another function," so you can do this: someFunctionThatReturnsADataFrame() %>% someFunctionThatTakesAndReturnsADataFrame() %>% doSomethingTo() No need to name either the temporaries or the function arguments.
- oivaksef 6y agoIRB the interactive ruby shell has _ which references the return value of the last command. So 10 + 10 puts _ # prints 20 but that isn't available in ruby itself
- dragonwriter 6y ago> I've always thought that it would be nice to have variables which you don't name, which only live over a couple of lines, where it's clear the variable is just for some plumbing and doesn't need a name There are several things that involve unnamed, shortlived plumbing vars; as well as various languages pipeline notations, therr is also this in scala lambdas: xs.map(x => x + 1) can be written as: xs.map(_ + 1) and even: (xs, ys).zipped.map((x,y)=>x+y) as: (xs, ys).zipped.map(_ + _)
- kazinator 6y agoWe already have: - partial application notation with numbered arguments - pattern matching - anaphoric if and related notations - point-free form (no names at all)
- gremlinsinc 6y agoI think a better format would be: instead of: p(2 * 3 * 7) #=> 42 ^^^^^var Having: p(var1:[2*3] * var2: 7) => 42 p(var1) => 6 p(var2) => 7 The other requires ugly whitespacing.
- nwatson 6y agoIt kind of works in Python 3.9 and perhaps earlier, unfortunately need extra parentheses ... >>> print((v1 := 2 * 3) * (v2 := 7)) 42 >>> print(v1) 6 >>> print(v2) 7 edit: formatting
- acidbaseextract 6y agoClojure's "threading" macros are exactly this: https://clojure.org/guides/threading_macros https://clojure.org/guides/threading_macros Elixir's pipe is the same thing, though Clojure has a few extra forms to facilitate other variable passing patterns.