Makefile图灵完成了吗? [英] Are makefiles Turing complete?

查看:109
本文介绍了Makefile图灵完成了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近在工作,我一直在做一些从Makefile到替代构建系统的翻译.我已经在某些地方使用功能映射,过滤器和foreach构造看到了一些毛茸茸的Make代码.这让我感到惊讶,因为我认为构建脚本应该尽可能地具有声明性.

Lately at work, I've been doing some translation from Makefiles to an alternative build system. I've seen some pretty hairy Make code in some places using functional map, filter, and foreach constructs. This surprised me since I think build scripts ought to be as declarative as possible.

无论如何,这让我开始思考:Makefile语言(比如说要使用最新的GNU make)是图灵完整的吗?

Anyway, this got me thinking: is the Makefile language (say the latest GNU make to be specific) Turing complete?

推荐答案

是的,请参见.一旦有了lambda,一切就从那里下坡了.

Yes, see this. Once you have lambda, it's all downhill from there.

以下是抄袭的斐波那契示例

这应该足以为更多通用性打下基础(我必须重新开始工作,否则我会玩得更多.)

This should be enough to build a foundation for more generality (I've got to get back to work, or I'd play more.)

dec = $(patsubst .%,%,$1)

not = $(if $1,,.)

lteq = $(if $1,$(if $(findstring $1,$2),.,),.)
gteq = $(if $2,$(if $(findstring $2,$1),.,),.)
eq = $(and $(call lteq,$1,$2),$(call gteq,$1,$2))
lt = $(and $(call lteq,$1,$2),$(call not,$(call gteq,$1,$2)))

add = $1$2
sub = $(if $(call not,$2),$1,$(call sub,$(call dec,$1),$(call dec,$2)))
mul = $(if $(call not,$2),$2,$(call add,$1,$(call mul,$1,$(call dec,$2))))
fibo = $(if $(call lt,$1,..),$1,$(call add,$(call fibo,$(call dec,$1)),$(call fibo,$(call sub,$1,..))))
fact = $(if $(call lt,$1,..),.,$(call mul,$1,$(call fact,$(call dec,$1))))

numeral = $(words $(subst .,. ,$1))

go = $(or $(info $(call numeral,$(call mul,$1,$1)) $(call numeral,$(call fibo,$1)) $(call numeral,$(call fact,$1)) ),$(call go,.$1))

_ := $(call go,)

这将打印出平方,斐波那契数和阶乘.数字大小似乎限制为16位.笨蛋

This prints out squares, fibonacci numbers and factorials. There appears to be a 16 bit limit on number sizes. Bummer.

这篇关于Makefile图灵完成了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆