News for hackers. Stuff that matters.
Re:Ante: A low-level functional language by tazjin on Friday June 17, 2022 @04:57AM (#31775709)
> Is there a reason why you would make fn(1) and fn 1 equivalent?

If your standard function call convention is just `f x`, but you also support precedence operators, then `f (x)` automatically becomes possible.

It reminds me of an old Lisp joke, though:

    f x   -- too mathematical!
    (f x) -- too many parenthesis!
    f(x)  -- just right!
Re:Ante: A low-level functional language by gpderetta on Friday June 17, 2022 @05:07AM (#31775774)
> f x -- too mathematical!

:) yet we are very happy to use the same syntax in shell scripts or the shell itself.

Re:Ante: A low-level functional language by georgyo on Friday June 17, 2022 @08:06AM (#31776919)
I've heard this argument before, but this isn't true.

In shell, f x y z, x y z are all augments to f. Doesn't matter if f takes one argument, all are passed to the function.

With many functional languages this gets very confusing. IE what ie what does `f f x` do? In shell I know for sure.

In the example f f x, it might be easy to parse. But in f x y z, any of x y z might be functions.

Re:Ante: A low-level functional language by momentoftop on Saturday June 18, 2022 @01:31AM (#31787461)
It's pretty easy to reason about that particular example if you have a type system. In a simply typed language, "f f x" is just a type error, so it doesn't do anything. In the polymorphic lambda calculus, the typing will force f to either be the identity, meaning that "f f x = x", or it will be a constant function, so you just replace "f f" with the constant.
Re:Ante: A low-level functional language by nemaar on Friday June 17, 2022 @08:22AM (#31777040)
Most functional languages parse a b c d e f as a(b, c, d, e, f), it does not matter what b, c, d, e, f are. Do you know any language where this is different?
Re:Ante: A low-level functional language by tomp on Friday June 17, 2022 @11:00AM (#31779203)
No functional languages do that.

OCaml parses a b c as ((a b) c). In case the compiler can determine that a is a function taking 2 arguments, it will optimise the code, so that it’s effectively a(b, c). But in general, that’s not possible, especially in the case where the compiler determines that a is a function with a single argument (in which case, it’s return value must be another function, which is in turn called with c) or when a is a first-class function (e.g. passed as an argument)

Re:Ante: A low-level functional language by sfvisser on Saturday June 18, 2022 @04:59AM (#31788319)
My toy FP language did. :) It’s perfectly possible to just parse a list of arguments and figure out currying in a later compiler stage. In my experience it even somewhat helps with producing nicer arity-specific error messages, which user might appreciate.
Re:Ante: A low-level functional language by dwenzek on Friday June 17, 2022 @09:52AM (#31778161)
OCaml and Haskell parse `a b c d e f` as `((((a b) c) d) e) f`.
Re:Ante: A low-level functional language by jerf on Friday June 17, 2022 @10:08AM (#31778408)
And while different than Algol-descended languages, I don't think that's particularly confusing. (Not that you were saying so, just continuing the conversation.) You can put together a confusing expression with it, but I can put together confusing things with the Algol syntax with not too much effort too. I've got the source code with my name on the blame to prove it.
Re:Ante: A low-level functional language by georgyo on Friday June 17, 2022 @08:33AM (#31777144)
I thought more languages did this but at least nix and ocaml do not actually behave like I thought.

In Ruby however it is a bit more ugly

  def f x
    x + 1
  end

  puts f f 1
> 3
Re:Ante: A low-level functional language by the_af on Friday June 17, 2022 @09:53AM (#31778175)
I don't understand your objection, what output would you like to see instead?
Re:Ante: A low-level functional language by lgessler on Friday June 17, 2022 @10:20AM (#31778603)
GP's point is that while yes, we know since `f` has arity 1 there's no ambiguity, in general you might not have the arity of any given function fresh in your head, and therefore can't tell (in Ruby) just from looking at `f f 1` whether it means a single invocation of an arity 2 function, or two invocations of an arity 1 function
Re:Ante: A low-level functional language by the_af on Friday June 17, 2022 @12:41PM (#31780827)
Ah! Right. It helps to have all functions be of arity 1 to disambiguate, yes.
Re:Ante: A low-level functional language by zeckalpha on Friday June 17, 2022 @08:33AM (#31777153)
Many counter examples to this, xargs for one.
Re:Ante: A low-level functional language by georgyo on Friday June 17, 2022 @08:37AM (#31777188)
xargs is not a counter example. It is not a shell builtin, it is a program that takes a bunch of string arguments like every other program a shell would call.

xargs -0 -n1 bash -c 'mv $1 ${1//.js/.ts}' --

Everything to the right of xargs is a string argument passed to xargs.

Re:Ante: A low-level functional language by zeckalpha on Friday June 17, 2022 @04:40PM (#31784040)
So an identifier representing a function? Isn’t that the same for most languages?
Re:Ante: A low-level functional language by layer8 on Friday June 17, 2022 @07:45AM (#31776754)
I guess the difference is that nesting calls (commands) is much less common in the shell, and (closely related) commands don’t really have a return value.
Re:Ante: A low-level functional language by DougBTX on Friday June 17, 2022 @08:06AM (#31776917)
On the shell, it is all the other way around, so to use command substitution it is like this:

    f $(g x)
To pass the output of g x to f.
Re:Ante: A low-level functional language by gpderetta on Friday June 17, 2022 @08:42AM (#31777246)
is it? In practice I find that my shell one liners are orders of magnitude more complex than what I would dare to write in any other 'proper' language:

   grep "hello ($(cat patterns.txt| tr '\n' '|'|grep ')$^)"  <(ssh other.host "cat ~/file.txt") |tee >(grep 'a' >As.txt) >(grep 'b' > Bs.txt)
[yes, gratuitous use of cat, sue me]
Re:Ante: A low-level functional language by lyxsus on Friday June 17, 2022 @07:52AM (#31776812)
We’re not, but your point is still valid.
Re:Ante: A low-level functional language by mellavora on Friday June 17, 2022 @05:14AM (#31775821)
As an old lisp fan, I never got this. (f x) and f(x) have the same number of parenthesis.

and the nice thing about (f x) is that the parenthesis group f with x; so you have the whole call inside the (). Consistent and simple to understand.

vs i.e. print(f"a string"), where it isn't even clear that the "f" is a function call.

Re:Ante: A low-level functional language by junon on Friday June 17, 2022 @05:17AM (#31775839)
That's the joke. The number of terms doesn't change, and the last two have the same number of parens. The statements relate quantities of those things as though they're a problem, when in reality the "just right one" only changes the order slightly.

Hence the joke. It's one of those jokes that earns a loud sigh from me, rather than a chuckle.

Re:Ante: A low-level functional language by layer8 on Friday June 17, 2022 @07:56AM (#31776838)
> the nice thing about (f x) is that the parenthesis group f with x

The drawback is that they are put on the same level, whereas in most people’s minds the function is a fundamentally different thing from the argument(s). The “f(x)” syntax reflects that asymmetry.

Re:Ante: A low-level functional language by agumonkey on Friday June 17, 2022 @09:17AM (#31777674)
What creates that distinction ? in the lisp / fp world you quickly stop considering functions as separate entities.
Re:Ante: A low-level functional language by layer8 on Friday June 17, 2022 @10:19AM (#31778601)
The function represents the operation or computation you want to perform. The arguments represent inputs or parameters for that operation or computation.

Of course, theoretically you could also view the function as a parameter of the computation and/or the arguments as specifying an operation (in particular if those are also functions), but for most concrete function invocation that's not generally the mental model. E.g. in "sin(x)" one usually has in mind to compute the sine, and x is the input for that computation. One doesn't think "I want to do x, and `sin` is the input of that operation I want to do". One also doesn't think "I want to do computation, and `sin` and `x` are inputs for that computation". It's why you may have mentally a sine graph ranging over different x values, but you don't imagine an x graph ranging over different functions you could apply to x.

Re:Ante: A low-level functional language by agumonkey on Friday June 17, 2022 @10:49AM (#31779026)
But even in high school topics start to talk about functional equations (calculus, e/ln). I'm not sure the <function> vs <value> doesn't come from the mainstream imperative paradigms and only that.
Re:Ante: A low-level functional language by tikhonj on Friday June 17, 2022 @12:01PM (#31780189)
The distinction isn't between functions and values in general, it's between the function being called and the arguments passed to the function being called. The difference isn't in the things themselves, it's in the role that they play in the specific expression we're reading.
Re:Ante: A low-level functional language by agumonkey on Friday June 17, 2022 @02:21PM (#31782231)
This argument is rather strange. Maybe for people who never interacted with different -fix notations ? Human language binds concepts with arguments in all kinds of direction .. I'd be surprised this is enough to annoy people.
Re:Ante: A low-level functional language by layer8 on Friday June 17, 2022 @03:29PM (#31783123)
Natural language isn’t precise and a lot is inferred from context. Exact order does often not really matter. In formal languages, however, you want to be as unambiguous and exact as possible, so it makes sense to use syntax and symbols to emphasize when elements differ in kind.

Incidentally, that’s also why we use syntax highlighting. One could, of course, use syntax highlighting instead of symbols to indicate the difference between function and arguments (between operation and operands), but that would interfere with the use of syntax highlighting for token categories (e.g. for literals of different types).

Re:Ante: A low-level functional language by agumonkey on Friday June 17, 2022 @04:00PM (#31783497)
We also alternate between various positions in programming languages, so it's not a matter of formal precision.
Re:Ante: A low-level functional language by layer8 on Friday June 17, 2022 @04:49PM (#31784171)
Not sure what you mean by “alternate between various positions”.
Re:Ante: A low-level functional language by agumonkey on Friday June 17, 2022 @09:14PM (#31786461)
Prefix for function, infix in expressions, and postfix if you use forth
Re:Ante: A low-level functional language by YetAnotherNick on Friday June 17, 2022 @05:18AM (#31775849)
> (f x) and f(x) have the same number of parenthesis.

That's the joke

Re:Ante: A low-level functional language by quickthrower2 on Friday June 17, 2022 @06:22AM (#31776207)
I have heard that if you count { and ( as parens, a Java program for example has just as many parens as. lisp one.

A lisp paren can do both jobs: expression and scopes.

Re:Ante: A low-level functional language by layer8 on Friday June 17, 2022 @07:51AM (#31776798)
> A lisp paren can do both jobs: expression and scopes.

Using different symbols for different purposes makes sense, it helps humans to parse correctly faster.

Re:Ante: A low-level functional language by kazinator on Friday June 17, 2022 @10:14AM (#31778497)
That's right, which is why the parenthesis is combined with a leading symbol like (let ...).

Mainly, you don't look at the parenthesis when reading; you look at that let and your eyes rely on indentation for structure.

Re:Ante: A low-level functional language by hyperhopper on Friday June 17, 2022 @12:56PM (#31781027)
Okay, but now you have to look at more things.

Also, the ending paren doesn't have anything to help you see what it is on its own.

Re:Ante: A low-level functional language by kazinator on Friday June 17, 2022 @01:50PM (#31781777)
You're not supposed to look for ending parentheses in Lisp; getting the right number of them is more or less your editor's job, and they are maximally stacked together like this: )))), as much as the given nesting and indentation permit. Given some (let ..., the closing parenthesis could be the third one in some ))))) sequence; you rarely care which one. If it's not matched in that specific ))))) sequence where you expect, then that's a problem.

)))) is like a ground symbol in a schematic:

    (+5V
      (+10V
        (-10V
          (INPUT3 ...))))
                     -----  local "ground" for all the above

    (different circuit)
Re:Ante: A low-level functional language by layer8 on Friday June 17, 2022 @05:00PM (#31784320)
That doesn’t seem very user-friendly. ;) Or at least that’s always my perception when programming Lisp.

As a side note, I believe that different people fundamentally have different programming languages that objectively suit them best, due to differences in their respective psychology and way of thinking and perceiving. It’s interesting to discuss trade-offs, but in the end there is no single truth about which language is better overall — it depends on the task and on the person. There’s no “one size fits all”. What’s valuable is to understand why a certain syntax or language might work better for certain people.

Re:Ante: A low-level functional language by lispm on Friday June 17, 2022 @01:05PM (#31781155)
Just ignore the parentheses. Setting them to the background color may enforce that.
Re:Ante: A low-level functional language by quickthrower2 on Friday June 17, 2022 @06:28PM (#31785245)
It does, but there are still many different purposes. In JS:

( can mean: function call, part of an expression to be evaluated first, regex capture group

{ can mean: scope [of ... loop, if, lambda, function etc.], object definition, string interpolation code i.e. ${..}, class definition

There are probably other things I am not thinking of.

The one that trips me in JS is code like x.map(v => {...v, v2}) breaks because the compiler sees the { as the beginning of a scope, not the object definition I intended.

The working solution is x.map(v => ({...v, v2}))

But x.map(v => v+1) is allowed.

I don't think the compiler could figure out what you meant because an object definition might be a lambda function body. For example { myvar } can be both an object definition, and a function that returns myvar.

Re:Ante: A low-level functional language by gorjusborg on Friday June 17, 2022 @09:49AM (#31778111)
Sure, why care about splitting algorithms into functions and naming them appropriately when you can just write it all in a 3k line function.
Re:Ante: A low-level functional language by lptk on Saturday June 18, 2022 @10:36PM (#31795627)
That's obviously nonsense.

Java, one pair of parens:

    int x = 1;
    int y = x + 1;
    System.out.println(y);

Clojure, six pairs of brackets:

    (let [x 1 y (+ x 1)] ((. (. System out) println) y))
Re:Ante: A low-level functional language by agumonkey on Friday June 17, 2022 @08:37AM (#31777186)
I wish we had stats about sexps (we shall call it the kinthey scale). As a kid what you said was the first thing my brain caught on. It compresses the number of things I had to remember it's ~always (idea arguments...). We can now discuss interesting problems.
Re:Ante: A low-level functional language by throwaway17_17 on Friday June 17, 2022 @11:58AM (#31780143)
I had the same feeling when I first started using a lisp (which was Scheme to work through SICP and the Ableman&Sussman MIT course). I was utterly entranced by the simplicity and uniformity. It was absolutely a factor in the way syntax works in my personal language (which I use for almost everything in my day to day). I really do agree that learning a lisp can truly expand the way in which a dev views and thinks about code.
Re:Ante: A low-level functional language by agumonkey on Friday June 17, 2022 @02:07PM (#31782035)
Brown university PLT labs also vouched for this approache. Their textbook starts with a descriptions of sexps as syntax saying that's the only parsing theory covered here.
Re:Ante: A low-level functional language by hota_mazi on Friday June 17, 2022 @12:37PM (#31780762)
It's a stupid joke.

The negative reactions that a lot of people have toward Lisp's parentheses are not because of the call function syntax but because parentheses are used everywhere else in Lisp's syntax.

Re:Ante: A low-level functional language by arethuza on Friday June 17, 2022 @06:11AM (#31776148)
Pity it doesn't include a line for:

   x f
Re:Ante: A low-level functional language by cwillu on Friday June 17, 2022 @06:26AM (#31776225)
That line necessarily comes after all the arguments about it.
Re:Ante: A low-level functional language by silon42 on Friday June 17, 2022 @06:53AM (#31776398)
x.f and x.f()