P
P
protalk2016-06-17 15:27:20
Programming languages
protalk, 2016-06-17 15:27:20

Keyword "call itself" in programming languages?

I haven't seen a keyword in any programming language that means "call itself". You must always specify your own name explicitly. It is clear that the use of such a word is limited (only self-recursive functions). But still, I think it would be nice.
Maybe someone knows languages ​​​​with such a feature?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alex_ak1, 2016-06-17
@alex_ak1

Here, in my opinion, there is a different kind of restriction - how can you call something without a name? That is, in a regular recursion, I take my name and a recursion is formed, and you propose to make a special construction that will do the same. It turns out just a complication of syntax without much benefit.

A
Alexander Skusnov, 2016-06-17
@AlexSku

Wirth showed that recursion can be reduced to an iterative scheme, so recursion can be dispensed with.

T
theg4sh, 2016-09-21
@theg4sh

"call itself" what exactly do you imagine? Code reduction? And what to do with arguments?
I only know that such things can definitely be used in Bash

function testit() {
    echo "$1"
    [ -n "$1" ] && return;
    echo $__FUNCNAME__ "ok"
}

testit

JavaScript
function testit() {
    if (arguments.length>1 && arguments[1]<2) {
        console.log(arguments[0], arguments[1]);
        arguments.callee("offtop", arguments[1]+1);
    } else {
        console.log("no arguments left");
    }
}

testit("test", 1);

As you can see, the function name swells a bit when used this way, so it's up to you to use it or not.
I assume that many other scripting languages ​​have a similar tool.
Surely Java and C# have this capability. Google to the rescue.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question