Live data from Hacker News

Show HN: KatLang – Language for Calculations

katlang.org

11–20 of 46 posts

Re: Show HN: KatLang – Language for Calculations

#11

Looks good. Curious about the syntax of function declaration - i.e.: A = x * y + x And then I invoke it by: A(2, 3) Implicitly using the order of which the parameters were used in the function declaration. Rather than having it explict either via: A = (x, y) => x * y + x Or via named parameters: A(x = 2, y = 3) Why this design?

I was obsessed with the perfect syntax. Declaring method parameters in method parameters list is redundant, because the parameters appear in the method body anyway. This approach is not the best in all situations, but for short expressions, like lambda expressions, it is perfect (in my opinion). Check my paper on comparing lambda expression implementation: https://www.bjmc.lu.lv/fileadmin/user_upload/lu_portal/proje.…

I don’t think you got the perfect syntax. Being both implicit and order-based is just begging for mistakes. Your Grace~ operator is esoteric, making it quite impossible for a casual reader to understand what’s going on, and being just another unusual thing for the reader to keep in mind about the language. This sort of thing is slightly mitigated by tooling support (an IDE-like thing that reminds you of the order), but it’s generally a bad idea to depend on such tooling for sane operation.

Meanwhile, `A(x, y) = x * y + x` is only slightly more verbose, but extremely clear as it matches standard practice in mathematics and is easily familiar to programmers as well. I think it’s fairly unambiguously a superior syntax for use. Short and non-repeating is not all there is to life.

Re: Show HN: KatLang – Language for Calculations

#12

Earlier quoted context omitted.

I expected `A(x, y) = x * y + x`, in line with standard mathematical function notation.

When you have A=x y+x from math perspective it looks like assigning a value to a variable. When You use A(x,y)=x y+x it looks like math function definition. You can look at it as if used variable assignment syntax and changed underlying semantics to the function definition syntax. I suppose, people are familiar with classic math syntax and it will be difficult to change their beliefs. But I also believe, that smartph…

OK, for typing on a mobile device I can see such a thing, but I think it’d be better to leave the language doing the clear, explicit thing and having the mobile app assist you in some way with converting an expression to a function declaration with automatic parameter ordering.

Re: Show HN: KatLang – Language for Calculations

#13

Earlier quoted context omitted.

I was obsessed with the perfect syntax. Declaring method parameters in method parameters list is redundant, because the parameters appear in the method body anyway. This approach is not the best in all situations, but for short expressions, like lambda expressions, it is perfect (in my opinion). Check my paper on comparing lambda expression implementation: https://www.bjmc.lu.lv/fileadmin/user_upload/lu_portal/proje.…

It creates the situation where these two functions appear to be identical but they are not: A = x * y + x A = y * x + x It is an interesting subject, and in general you would want to balance usability, people's expectations, and succinctness.

It is not the same.

   A1 = x * y + x    
   A2 = y * x + x    
   A1(1, 2), A2(1, 2)    
returns results 3, 4 If You want to change parameter order, You can use Grace~ operator like this:

   A1 = x~ * y + x   
it moves parameter x one position towards the end of the parameters list.

Sorry, I do not know how to post code snippets in HN properly.

Re: Show HN: KatLang – Language for Calculations

#14
post #5

I wonder why no (proper) https?

KatLang parser is executed as Blazor webassembly app on client side, therefore your entered KatLang code is not sent to the server. But I agree, it needs https, especially when KatLang supports operators like 'load' which can load KatLang code from other sources. Loading part is inspired from Prolog predicate consult.

> therefore your entered KatLang code is not sent to the server

But that's not something that even client-side code supplied by HTTP should be capable of ensuring, considering that somebody could have intercepted it somewhere on the route and replaced it with something that does send it somewhere.

Re: Show HN: KatLang – Language for Calculations

#15

Earlier quoted context omitted.

It creates the situation where these two functions appear to be identical but they are not: A = x * y + x A = y * x + x It is an interesting subject, and in general you would want to balance usability, people's expectations, and succinctness.

It is not the same. A1 = x * y + x A2 = y * x + x A1(1, 2), A2(1, 2) returns results 3, 4 If You want to change parameter order, You can use Grace~ operator like this: A1 = x~ * y + x it moves parameter x one position towards the end of the parameters list. Sorry, I do not know how to post code snippets in HN properly.

Indent with 3 spaces or more.

Re: Show HN: KatLang – Language for Calculations

#16

Earlier quoted context omitted.

I was obsessed with the perfect syntax. Declaring method parameters in method parameters list is redundant, because the parameters appear in the method body anyway. This approach is not the best in all situations, but for short expressions, like lambda expressions, it is perfect (in my opinion). Check my paper on comparing lambda expression implementation: https://www.bjmc.lu.lv/fileadmin/user_upload/lu_portal/proje.…

I don’t think you got the perfect syntax. Being both implicit and order-based is just begging for mistakes. Your Grace~ operator is esoteric, making it quite impossible for a casual reader to understand what’s going on, and being just another unusual thing for the reader to keep in mind about the language. This sort of thing is slightly mitigated by tooling support (an IDE-like thing that reminds you of the order), b…

Modern math syntax is relatively new, it started to form in 18th century. It is not too late to make some changes. Implicit parameters is only one feature in KatLang. Classic math functions can return only one value, that is why in KatLang there are no functions. In KatLang everything is an algorithm - concept which can return several outputs. Yes, some programming languages have syntactic sugar for that too, but still there are no accepted general syntax. Lambda is special case for an algorithm! Even natural languages have experienced a lot of changes. For example, Latvian language grammar changed in only 10 years. Maybe You are right about implicit parameters, but I believe, that implicit parameters are useful and I will try to convince the world about it. We will see how it will turn out ;).

Re: Show HN: KatLang – Language for Calculations

#17

The author here. I am ready to answer any questions about KatLang. The future plan is to create android app and I hope that it will become the future calculator. I have been postponing android app creation for years, but now KatLang is in good shape and I can continue with tool development.

I'd enjoy a page that explains why I should care. What makes it special?

Re: Show HN: KatLang – Language for Calculations

#18

Earlier quoted context omitted.

I don’t think you got the perfect syntax. Being both implicit and order-based is just begging for mistakes. Your Grace~ operator is esoteric, making it quite impossible for a casual reader to understand what’s going on, and being just another unusual thing for the reader to keep in mind about the language. This sort of thing is slightly mitigated by tooling support (an IDE-like thing that reminds you of the order), b…

Modern math syntax is relatively new, it started to form in 18th century. It is not too late to make some changes. Implicit parameters is only one feature in KatLang. Classic math functions can return only one value, that is why in KatLang there are no functions. In KatLang everything is an algorithm - concept which can return several outputs. Yes, some programming languages have syntactic sugar for that too, but sti…

Few programming languages actually support returning multiple values, and those that do are I think all quite old: the usual course these days is just to support record or tuple/list types and some kind of destructuring syntax, with the completely incidental effect of simulating returning multiple values, typically without any syntax sugar (unless you count destructuring, which is normally strictly sugar, but it’s often more a fundamental language feature and not really related to multiple return values).

KatLang’s algorithms look to me to just be functions that return tuples. Am I wrong?

Requiring that the reader read the entire expression before they can know the arguments they need to provide and the order they need to provide them in is not a good thing. Add the Grace~ operator and they have to parse even more, maintain a list of arguments in their head and even reorder them mentally! That’s massive cognitive overhead. If people start using this for anything of even moderate size, you will observe people writing the signature in comments—or perhaps, if I’ve read your docs properly, writing `A = #x, #y, x * y + y`. There’s a reason why serious programming languages all specify the signature separately from the body.

Re: Show HN: KatLang – Language for Calculations

#19

Looks good. Curious about the syntax of function declaration - i.e.: A = x * y + x And then I invoke it by: A(2, 3) Implicitly using the order of which the parameters were used in the function declaration. Rather than having it explict either via: A = (x, y) => x * y + x Or via named parameters: A(x = 2, y = 3) Why this design?

I was obsessed with the perfect syntax. Declaring method parameters in method parameters list is redundant, because the parameters appear in the method body anyway. This approach is not the best in all situations, but for short expressions, like lambda expressions, it is perfect (in my opinion). Check my paper on comparing lambda expression implementation: https://www.bjmc.lu.lv/fileadmin/user_upload/lu_portal/proje.…

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/:

    sum = fn (a, b) -> a + b end
    sum.(2, 3)

    sum = &(&1 + &2)
    sum.(2, 3)

Re: Show HN: KatLang – Language for Calculations

#20

Earlier quoted context omitted.

It is not the same. A1 = x * y + x A2 = y * x + x A1(1, 2), A2(1, 2) returns results 3, 4 If You want to change parameter order, You can use Grace~ operator like this: A1 = x~ * y + x it moves parameter x one position towards the end of the parameters list. Sorry, I do not know how to post code snippets in HN properly.

Indent with 3 spaces or more.

(Two, actually.)
Post reply on HN