What language functions cannot be defined in terms of lambda?

It seems that lambda can be used for almost anyone (even if it seems more complicated), but has its limitations.

What are some uses not covered by lambda?

+3
source share
1 answer

Lambda (i.e. function) in itself is not very interesting. Here's the function in JavaScript:

function id(x) {
    return x;
}
Run code

What does this JavaScript program do? Nothing.

However, functions have the dangerous property of being invokable.

When called, the function can potentially do something (conditions apply):

authorize_nuclear_attack(launch_codes); // oops

Hence, trivially, lambda can do something.

, C - , main.

Aadit - .

  • , , ?
  • if?
  • for?
  • ?
  • +?

?

. (, -) (, -).

, .

, ( ), - (, ).

:

  • .
  • .

:

  • :

    function id(x) { // declare variable x
        return x;    // valuate variable x
    }
    
  • ( viz-a-viz recursion) -:

    id(something);   // let x := something in the body of the function id
    
  • - :

    function boolean_true(then_branch, else_branch) {
        return then_branch;
    }
    
    function boolean_false(then_branch, else_branch) {
        return else_branch;
    }
    
    function if_statement(boolean_condition, then_branch, else_branch) {
        return boolean_condition(then_branch, else_branch);
    }
    
  • " " :

    function dragon(dragon) {
        return dragon(dragon); // infinite loop
    }
    
    dragon(dragon);
    

    , , :

    Uroboros dragon

    , , . .

    ( a.k.a.).

  • :

    function substitution(f, g) { // S combinator from SKI combinator calculus
        return function (x) {
            return f(x, g(x));
        };
    }
    
    // substitution(f, g) is equivalent to (statement g; statement f)
    // where the semicolon is the sequencing operator like in C
    
  • :

    function zero(f, x) {         // 0
        return x;
    }
    
    function add1(n) {            // n + 1
        return function (f, x) {
            return f(n(f, x));
        };
    }
    
    function add(m, n) {          // m + n
        return function (f, x) {
            return m(f, n(f, x));
        };
    }
    

, (.. ) (, -) (, ), , C Java.

- .

, - - (.. , , , , -).

, ( ), .

- , , ( ). " P P ?"

In other words, it is impossible to write a function Hsuch that H(P) = trueif it Pstops at all inputs, H(P) = falseotherwise. If you manage to write a function H, then it will always be incorrect for the following program:
function P(x) {
    return H(P) ? P(x) : x;
}

If he Hthinks he Palways stops, then he Pgoes into an endless cycle.

If he Hbelieves that he Pdoes not always stop, he always stops.

What are some uses not covered by lambda?

, -, - . , , , , -.

( , ). -, . .

, C Java, . , Haskell OCaml, . - , . , .

+5

Source: https://habr.com/ru/post/1656353/


All Articles