3 ms·
A little while ago I sketched some ideas for a programming language [1], one of which was that I would like a language who did not distinguish between these two
by sixo 1y ago
A little while ago I sketched some ideas for a programming language [1], one of which was that I would like a language who did not distinguish between these two cases. Obviously you can always write a function with a single N-param argument, but it's rather verbose, but would be nice to also be able to write the param list normally and then refer directly to its parameter type elsewhere. Although this would require that the "set of possible parameter lists" were the same as "the set of possible object type", which isn't the case in any language I know of.
[1] https://samkrit.ch/2025/03/09/programming-1.html#anonymous-type-definitions https://samkrit.ch/2025/03/09/programming-1.html#anonymous-t...
- feoren 1y agoIsn't C#'s named arguments basically what you want? You can choose to use the names or not at the time of calling the function. You can name some arguments but not others. Don't many programming languages have this feature?
- intrepidhero 1y agoI had a similar thought while designing my dream programming language but I also wanted automatic currying and I couldn't figure out an ergonomic way to have both. Now I'm gonna go read your blog series.
- ashtuchkin 1y agopython does this pretty elegantly: def my_func(a: int, b: int): print(a+b) # both of these can be used my_func(1, 2) my_func(a=1, b=2)
- sixo 1y agoThis isn't what I'm talking about. I would want def my_func(a: int, b: int): ... def my_func2(args: my_func.__args_type__): ... with `my_func.__args_type__` standing for an object like `{a: int, b: int}`.
- ziofill 1y agoAlso `my_func(**{a:1, b:2})`
- ImageXav 1y agoEven better, python has named tuples [0]. So if you have a tuple that you are sure will always have the same inputs you can declare it: ``` Point = namedtuple('Point', 'x y') pt1 = Point(1.0, 5.0) ``` And then call the X or Y coordinates either by index: pt1[0], pt1[1], or coordinate name: pt1.x, pt1.y. This can be a really handy way to help people understand your code as what you are calling becomes a lot more explicit. [0] https://stackoverflow.com/questions/2970608/what-are-named-tuples-in-python https://stackoverflow.com/questions/2970608/what-are-named-t...