Is conditional branching a requirement of Turing-completeness?

前端 未结 7 1770
不知归路
不知归路 2021-02-05 21:39

I\'ve been searching the web and I\'m finding somewhat contradictory answers. Some sources assert that a language/machine/what-have-you is Turing complete if and only if it has

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 22:27

    If you can compute the address for your goto or jmp, you can simulate arbritary conditionals. I occasionally used this to simulate "ON x GOTO a,b,c" in ZX Basic.

    If "true" has the numerical value 1 and "false" 0, then a construction like:

    if A then goto B else goto C
    

    is identical to:

    goto C+(B-C)*A
    

    So, yes, with a "computed goto" or the ability to self-modify, a goto or jmp can act as a conditional.

提交回复
热议问题