28 comments

[ 4.3 ms ] story [ 88.2 ms ] thread
Partisans in favor of spaces over tabs, here’s another argument for your arsenal.
I see something different in there.

F(condition1,

Condition2)

Is worse than

F(

  Condition1,

  Condition2
)

The problem isn't tabs or spaces, it's trying to align to the length of the function name instead of adding a new line

(comment deleted)
(comment deleted)
Fantastic. Not on-board with the ^^^^ syntax - could be improved. But it reminds me of how sequential-character syntax is limiting, like if you were going to make an integrated circuit in strict 2 dimensions, without being able to bridge over traces sometimes in a minimally 3-dimensional way. This is like bringing programming into, literally, a new dimension.
Can't this just be solved by using a do/while loop?
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
How do you reference a variable for plumbing if it doesn't have a name?
tidyverse 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.
IRB 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

> 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(_ + _)
We already have:

- partial application notation with numbered arguments

- pattern matching

- anaphoric if and related notations

- point-free form (no names at all)

I 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.
It 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
The number of people that don't have their guard up on April 1 is always astounding.
I can only imagine what the elegance and clarity when we start writing code in 3D.
I know this is a joke, but it really might be worth an experimental implementation, just to see where this leads. (Decent editor support would be critical.)