3 ms·
There's at least one type of lambda missing from your paper, the OCaml function. After using the keyword `function`, you can directly go into a match: let
by Zababa 5y ago
There's at least one type of lambda missing from your paper, the OCaml function. After using the keyword `function`, you can directly go into a match:
let toto = function
| 0 -> 'a'
| _ -> 'b'
About the contents of the paper, I'm not sure that I agree with you. There is a clear distinction between lambdas with shorthands and lambdas with named parameters, and I think it exists for a good reason. You seem to base your reasoning on the following:
> The number of symbols is a fundamental aspect of code readability (Tashtoush et al., 2013). In general, the shorter and more compact the code, the higher the code readability factor. Therefore, the perfect lambda syntax makes lambda expressions more readable and improves code editability factor (Blow, 2014) allowing programmers to be more productive in their work.
I'm not convinced that it's true. From the abstract of Tashtoush et al., 2013:
> The survey responses were analyzed using SPSS statistical tool. Most of proposed code features showed to have significantly positive impact on enhancing readability including: meaningful names, consistency, and comments. On the other hand, fewer features such as arithmetic formulas, nested loops, and recursive functions showed to have a negative impact.
That doesn't seem to agree with what you said. Also:
> In general, the shorter and more compact the code, the higher the code readability factor.
I'm not sure where that comes from, but I'm also not convinced that it's true. Try limiting yourself to only one or two characters for name and you will quickly discover that it's probably not generally true.
As an aside, is this a common thing in academia to call something "perfect"? I personally find it weird and even a bit unprofessional but maybe I'm not used to how people talk in papers.
Edit: after thinking about it a bit more, I found why I don't like the type of lambda you proposed. In programming, a lot of people (me included) have the belief that you should be able to sometimes only know the interface of something, not the implementation behind it. Naming your parameters properly is a way to separate that interface and that implementation. Both "sides" agree on what is exchanged, and part of that "contract" is in the name of the parameters.
However, as with all things, there are trade-offs. Sometimes you don't need a strong separation between the two. Lambda expressions are often used in that case: you don't name the function, as you're the one directly using it. However, just because you don't name the function doesn't mean you also don't want to name the parameters, at least all the time. The name of the parameters are often an important part of an interface: the interface of the higher order function you are using. I often use reduce or fold, in a wide variety of language, and I always have trouble remembering if the accumulator is the first or the second parameter of the function I'm passing to reduce. But when I read code that use "acc" and "el", it's very easy to see which is which.
All of that to say that your perfect lambda syntax seems to be a small improvement over the existing positional lambda, and doesn't replace lambdas with named parameters, that have a place. Elixir has both anonymous functions with named parameters and anonymous functions with positional parameters. Both have their use. Example taken from https://elixirschool.com/en/lessons/basics/functions/ https://elixirschool.com/en/lessons/basics/functions/:
sum = fn (a, b) -> a + b end
sum.(2, 3)
sum = &(&1 + &2)
sum.(2, 3)
- rabarbers 5y agoYour OCaml function example looks like feature I call conditional parameters in KatLang (inspired from Erlang). In mathematics exists many different concepts which are called perfect. For example, perfect numbers. God called Lucifer a perfect. I provided a definition for symbols perfectness and tokens perfectness. You can call it unprofessional, but I did my best. I do not call my work perfect to make it more significant. I use term perfect as an attribute of the code expressions. Imagine identity function: function(x) {return x; } In KatLang You can define it as: x The question is: can you remove one more symbol without changing the meaning of the expression? If no, then, the identity function definition 'x' is symbols perfect according to my definition. Of course, I rely on the usage context and it allows me to hide some part of critical information and focus only on the short lambda expression. Thanks for the elixir examples.
- Zababa 5y ago> Your OCaml function example looks like feature I call conditional parameters in KatLang (inspired from Erlang). It does! Elixir (coming from Erlang) and Haskell have the same thing, both through pattern matching of a function to different definitions. OCaml (and most other languages using pattern matching) pattern match inside a single definition. > In mathematics exists many different concepts which are called perfect. For example, perfect numbers. I personally only know about perfect numbers. I'm not sure if it's a great name for them, or if it's just a "fun" name like sexy prime https://en.wikipedia.org/wiki/Sexy_prime https://en.wikipedia.org/wiki/Sexy_prime that doesn't mean much. For your example about the identity function, I think it's great, but I'm personally more in favour of positional lambdas like &1 in Elixir. > The question is: can you remove one more symbol without changing the meaning of the expression? If no, then, the identity function definition 'x' is symbols perfect according to my definition. Maybe "minimal" would be a better name then? Or "shortest"? Many people could argue on what makes the perfect lambda, but it's hard to argue that yours isn't the most minimal or shortest.
- rabarbers 5y agoProbably picking the term "perfect" was not the best think I could do. Seems, that others actively fight against it. I still believe that the perfect syntax has both attributes: 1) it is the shortest 2) it is expressive - you can express any expression in it. Picking that name made my life much more difficult.