我尝试使用基于Programming With Nothing文章的JavaScript中的lambdas来创建FizzBuzz。我已经得到它working with variables但现在我想要替换变量的所有用法(大写字符串),我尝试使用m4,我为每个变量创建了定义,如:
define(`ZERO', `p => x => x')
define(`ONE', `p => x => p(x)')
define(`TWO', `p => x => p(p(x))')
define(`THREE', `p => x => p(p(p(x)))')
define(`FIVE', `p => x => p(p(p(p(p(x)))))')
define(`FIFTEEN', `p => x => p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(x)))))))))))))))')
define(`HUNDRED', `p => x => p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(p(x))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')
...
module.exports = MAP(RANGE(ONE)(HUNDRED))( n => IF(IS_ZERO(MOD(n)(FIFTEEN)))(
FIZZBUZZ
)(IF(IS_ZERO(MOD(n)(THREE)))(
FIZZ
)(IF(IS_ZERO(MOD(n)(FIVE)))(
BUZZ
)(
TO_DIGITS(n)
))));
并运行m4但它没有工作它没有用recursivly代替只显示箭头功能,我已经把它作为输出(文章程序要大得多):
module.exports = k => f => f => (x => f(p => x(x)(p)))(x => f(p => x(x)(p)))(x => y => f => f(x)(y)(x => y => x))(l => x => l => x => x => y => f => f(x)(y)(x => y => f => f(x)(y)(l))(f(x)))( n => b => b(
l => x => x => y => f => f(x)(y)(x => y => f => f(x)(y)(l))(n => p => x => p(n(p)(x)))
)(b => b(
l => x => x => y => f => f(x)(y)(x => y => f => f(x)(y)(l))(n => p => x => p(n(p)(x)))
)(b => b(
l => x => x => y => f => f(x)(y)(x => y => f => f(x)(y)(l))(m => n => n(m => n => n(n => p => x => p(n(p)(x)))(m))(p => x => x)(p => x => p(p(p(p(p(x)))))))
)(
f => (x => f(p => x(x)(p)))(x => f(p => x(x)(p)))
))));
HUNDRED
没有被替换,输出中没有p(
100次。
有没有办法使用m4或任何其他工具为整个程序设置一个表达式?