Questions tagged [functions]
For questions about the design or implementation of functions. This could include the syntax of defining and calling functions or implementing function calls at a lower level.
39 questions
7
votes
1
answer
474
views
What problems do applicative functors solve, as an abstraction relative to monads and arrows?
TL;DR
This site is of course particularly interested in the language designer's and implementor's perspective so, following What is an arrow and what powers would it give as a first class concept in a ...
27
votes
3
answers
11k
views
Colored vs uncolored functions
I've heard people say "colored" functions (e.g. async functions, or functions marked with throws) are bad because they ...
3
votes
1
answer
341
views
Concept Overloading in C++
The meaning of function overloading is that two or more functions can have the same name but different parameters. In C++20, concept has been introduced. I found ...
-2
votes
3
answers
281
views
How about support function return itself? [closed]
It seems that no language supports this feature:
Define a function that can return the function itself.
This function will continue to be called and continue to return itself.
For example:
...
9
votes
2
answers
3k
views
How do languages chain higher-order functions while still keeping performance?
How do different programming languages deal with the chaining of higher-order functions (ex. [1,2,3].foldl((a, b) => a+b, 0), ...
8
votes
7
answers
2k
views
Why tag function definition with def, fn, fun, func or function etc?
What makes it hard for compilers/interpreters that we need to tag the function definition with keyword fn/fun/func/function?
I can understand that types for numbers: int, int32, float32, float64... ...
3
votes
0
answers
101
views
Is it more readable to declare the return type of a function on the left side of it's name? [duplicate]
A lot of C-like programming languages (Java, C#, ...) use the following syntax for defining functions:
returnType functionName(parameters...) {
}
Is there a ...
13
votes
0
answers
338
views
Why were OS/360 PL/I procedure calls so expensive?
In Guy Steele’s famous paper Debunking the “expensive procedure call” myth or, procedure call implementations considered harmful or, LAMBDA: The Ultimate GOTO, he describes the poor performance of ...
13
votes
5
answers
1k
views
Prior art on pipelines of function calls
Say I have a loop that looks like this:
for i in range(1, 10) {
print(i)
}
Now I want to take the same sequence in reverse, and filter out even numbers. I might ...
14
votes
4
answers
4k
views
Could function parameters be placed inside names?
While in the shower thinking about my code, my mind went to C#'s type parameters, and I wondered what stops the type param from being placed in the middle of the function name like this:
...
4
votes
4
answers
758
views
Architecture for overriding "trait" implementations many times in different contexts?
I just asked this question about Rust: Is it possible to create a default trait implementation in Rust, and then override that trait implementation somewhere else? My problem is, in my custom lang, I ...
9
votes
6
answers
2k
views
Do variadic functions need to have a different calling convention to regular functions?
In C, calling a variadic functions are 'special' and not to be treated as regular functions or vice versa. Calling a variadic function through a regular function pointer, or vice-versa invokes ...
4
votes
2
answers
462
views
What are the disadvantages of making methods just functions with a 'this' first parameter?
In Lua, a function is no different from a method, except that a method has this as the first parameter, and calling a method on an object automatically passes the ...
17
votes
1
answer
1k
views
How can we define a denotational semantics for recursive functions?
Motivation
I want to define a denotational semantics (see here or here) for recursive functions in my language, by representing them as mathematical functions.
Background
Consider a simple language ...
7
votes
5
answers
3k
views
What are the pros/cons of having multiple ways to print?
In C++, there are two ways of printing something: printf() or cout <<.
However, in Python, there's only one way: ...