Readit News logoReadit News
rabarbers commented on Show HN: KatLang – Language for Calculations   katlang.org/... · Posted by u/rabarbers
geocar · 4 years ago
No. They are not keywords. The program:

    x:42;
    f:{[a]x+a}
is the same as:

    x=42;
    f=function(a){return x+a}

rabarbers · 4 years ago
Thanks for explaining! But how about this example:

  x:42
  {x+1}[5]
It results in

  6
It seems like you can define variables with the name 'x', but when you do not have explicit parameters, then the identifier 'x' is used to refer to the first implicit parameter, y - for second and z - for the third parameter. In context of implicit parameters x, y and z acts like predefined keywords.

rabarbers commented on Show HN: KatLang – Language for Calculations   katlang.org/... · Posted by u/rabarbers
geocar · 4 years ago
They're just variables like any other; {[x;y;z] x+yz} is almost exactly the same as {x+yz}
rabarbers · 4 years ago
I tested and seems, that x is the first implicit parameter, y - second, z - third. It is as stated in their online documentation. When you try following example:

  {y+x*z}[1;2;3]
It gives result:

5

And in Q you cannot define implicit parameters with names, for example,: a, b, c. But You can define parameters explicitly:

  {[a;b;c]a+b*c}[1;2;3]
I still think that their implicit parameters are keywords. Similarly as keyword 'it' in Kotlin programming language is used to refer to the single parameter of the lambda expression.

In KatLang there are no predefined implicit parameter names. The user is the one who defines implicit parameters by declaring the implicit parameter names.

rabarbers commented on Show HN: KatLang – Language for Calculations   katlang.org/... · Posted by u/rabarbers
geocar · 4 years ago
I think they meant:

    A1 = x * y + x
    A2 = y * x + y

rabarbers · 4 years ago
A1 in Javascript pseudocode would be:

  function A1(x, y) {return x*y + x; }
But A2 would be:

  function A2(y, x) {return y*x + y; }
If you do not like the default order of implicit parameters, you can always use Grace~ operator to move x or y. Prefix form moves the parameter one position towards the beginning of the parameters list, postfix form moves one position towards the end of the parameters list:

  A1 = y~ * x + y
or

  A1 = y * ~x + y
or [Edit]

  A1 = y * x + y~
In the last example take into consideration, that without Grace~ operator y is the first parameter, so, you need to move it one position towards the end of the parameters list - therefore use postfix form of Grace~ operator.

rabarbers commented on Show HN: KatLang – Language for Calculations   katlang.org/... · Posted by u/rabarbers
geocar · 4 years ago
They're just variables like any other; {[x;y;z] x+yz} is almost exactly the same as {x+yz}
rabarbers · 4 years ago
Can you explain the difference little bit more, Maybe using Javascript pseudocode as comparable example? I want to understand how Q is different from KatLang. The problem with me is that I do not know where I can try Q code, therefore I rely only on the documentation fragments I can find.
rabarbers commented on Show HN: I built an online programming language   codigo.so... · Posted by u/sandes
sandes · 4 years ago
It's a multi-language pseudocode interpreter so you can write and run code in English, Spanish, Portuguese and French in your browser.
rabarbers · 4 years ago
Link to documentation is broken: https://codigo.so/docs/ (also link to community is broken, but I care more about Documentation link).
rabarbers commented on Show HN: KatLang – Language for Calculations   katlang.org/... · Posted by u/rabarbers
rabarbers · 4 years ago
Yes, the first unknown identifier becomes the first parameter, next unknown identifier becomes next parameter and so on...
rabarbers · 4 years ago
More specifically: the first unknown identifier becomes the first parameter for the closest algorithm defined with {} brackets. Properties (also called named algorithms) are defined as {} context. And KatLang program also is defined as {} context. I call it Second order algorithm - algorithms can contain another algorithms. First order algorithm is something defined between commas or semicolons. But inside brackets () or {} you can define second order algorithm.
rabarbers commented on Show HN: KatLang – Language for Calculations   katlang.org/... · Posted by u/rabarbers
geocar · 4 years ago
> But regarding languages: k/q the issues with them is that they use x, y and z as keywords for the parameters. x is always the first parameter, y - second, z - third. In KatLang parameter names are not predefined keywords, you can pick almost any parameter names you like.

They aren't in q either: x can be redefined to whatever you like.

How does KatLang determine which argument is first? Is it merely the first free variable?

rabarbers · 4 years ago
According to Q documentation, Q supports only 3 implicit parameters x, y, z: https://web.archive.org/web/20190213035913/http://code.kx.co...
rabarbers commented on Show HN: KatLang – Language for Calculations   katlang.org/... · Posted by u/rabarbers
geocar · 4 years ago
> But regarding languages: k/q the issues with them is that they use x, y and z as keywords for the parameters. x is always the first parameter, y - second, z - third. In KatLang parameter names are not predefined keywords, you can pick almost any parameter names you like.

They aren't in q either: x can be redefined to whatever you like.

How does KatLang determine which argument is first? Is it merely the first free variable?

rabarbers · 4 years ago
Yes, the first unknown identifier becomes the first parameter, next unknown identifier becomes next parameter and so on...
rabarbers commented on Show HN: KatLang – Language for Calculations   katlang.org/... · Posted by u/rabarbers
Zababa · 4 years 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 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 · 4 years ago
Probably 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.

u/rabarbers

KarmaCake day12May 3, 2011View Original