5 ms·
Show HN: KatLang – Language for Calculations
- rabarbers 5y agoThe 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.
- Jeff_Brown 5y agoI'd enjoy a page that explains why I should care. What makes it special?
- rabarbers 5y agoI think, that there is needed Android app - calculator using KatLang syntax. That (or maybe iOS version) would make You care about it. I am planning to use KatLang syntax for physics tests in schools. Physics formulas can be defined using KatLang syntax. That is experimental idea, but I believe, that it can make a difference.
- throwaway4good 5y agoLooks 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?
- rabarbers 5y agoI 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/projekti/bjmc/Contents/6_1_02_Vanags.pdf https://www.bjmc.lu.lv/fileadmin/user_upload/lu_portal/proje...
- throwaway4good 5y agoIt 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.
- rabarbers 5y agoIt 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.
- throwaway4good 5y agoIndent with 3 spaces or more.
- chrismorgan 5y ago(Two, actually.)
- geocar 5y agoI think they meant: A1 = x * y + x A2 = y * x + y
- rabarbers 5y agoA1 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.
- chrismorgan 5y agoI expected `A(x, y) = x * y + x`, in line with standard mathematical function notation.
- rabarbers 5y agoWhen you have A=xy+x from math perspective it looks like assigning a value to a variable. When You use A(x,y)=xy+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 smartphone usage can change people habits. When function body defines the function signature, it is much easier to move around the function definition on small screen devices, define function, edit, and so on... I advice to watch promotional video for KatLang predecessor - https://www.youtube.com/watch?v=ya8beSCx1IA https://www.youtube.com/watch?v=ya8beSCx1IA It is still available on Windows Phone marketplace as IlCalculus app. Next goal is to develop Android app and I believe then it will be much easier to convince you, that implicit parameter declaration is the future feature of the clalculator.
- chrismorgan 5y agoOK, 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.
- geocar 5y agoWithout trying to speak to why "katlang" does what it does, there are other languages that do this and I can speak to how useful it is when you already prefer functions of low arity: It repeatedly demonstrates a substantial improvement in bug/defect reduction and code. APL does this; a function like {ω×α+ω} and assigns omega to the right-argument, and alpha to the left-argument. They also have ωω for the right-side function and αα for the left-hand function for writing higher-order functions. Dyadic expressions tend to modify their right-hand argument, and not the left, so for the times that the arguments are "backwards" this can usually be fixed with the commute operator (⍨) which looks similar to katlang's "grace" operator (~) so I assume at least some influence. k/q does something more similar: a function like {x*y+x} assigns the first argument to x, the second to y, the third to z. The author seems inspired by this behaviour (even mentioning it in a linked paper). In q, when the function is in the q context, x is the left-argument and y is the right-argument when called dyadically. Sadly, q and k don't have commute.
- rabarbers 5y agoI will do some research on APL and your mentioned 'commute operator', cannot comment on it now. 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.
- geocar 5y 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 5y agoYes, the first unknown identifier becomes the first parameter, next unknown identifier becomes next parameter and so on...
- kreetx 5y agoI wonder why no (proper) https?
- rabarbers 5y agoPage does not require any authentication and I wanted to make it simple. But too many people are asking about https, so I will configure https.
- kreetx 5y agoAck on the simplicity part and not needing to talk to the server after the first load. But the main concern is that stuff could simply be injected on that first load. Depending on how you host, the easiest solution might be to use the caddy web server which has letsencrypt built in.
- rabarbers 5y agoKatLang 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.
- jhgb 5y ago> 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.