Practical non-Turing-complete languages?

前端 未结 8 2022
一生所求
一生所求 2020-12-04 07:19

Nearly all programming languages used are Turing Complete, and while this affords the language to represent any computable algorithm, it also comes with its own set of probl

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 07:21

    The problem is not with the Turing machine, it's with "algorithm". The reason why you can't predict if an algorithm will halt or not is because of this:

    function confusion()
    {
        if( halts( confusion ) )
        {
            while True:
                no-op
        }
        else
            return;
    }
    

    Any language that can't do recursion or loops wouldn't really be "general-purpose".

    Regular expressions and finite-state-machines are the same thing! Lexing and string matching are the same thing! The reason FSMs halt is because they never loop; they just pass on the input char-by-char and exit.

    EDIT:

    For many algorithms, it's obvious whether or not they would halt.

    for instance:

    function nonhalting()
    {
        while 1:
            no-op
    }
    

    This function clearly never halts.

    And, this function obviously halts:

    function simple_halting_function()
    {
        return 1;
    }
    

    So the bottom line: you CAN guarantee that your algorithm halts, just design it so that it does.

    If you are not sure whether the algorithm would halt all the time; then you probably cannot implement it in any language that guarantees "halting".

提交回复
热议问题