在Scheme中命名

时间:2017-05-22 07:55:08

标签: guile

我试图使用命名let在Scheme中编写一个循环。我希望能够根据各种标准尽早摆脱迭代,而不是总是在最后循环。实际上,我希望whilebreakcontinue。由于强烈的原因,我被限制使用guile 1.8,而guile 1.8没有实现R6RS while结构。我的问题是,使用命名let的递归是否必须是尾递归的,为什么不能在结束之前重启循环? [这需要一个代码示例吗?]当我尝试使用IO操作在几个点上提前退出时,我总是读过EOF并得到不可预测的数据损坏。

1 个答案:

答案 0 :(得分:2)

    AppCompatRadioButton appCompatRadioButton = (AppCompatRadioButton) findViewById(R.id.radio);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int myColor = Color.parseColor("#4caf50");
        //appCompatRadioButton.setSupportButtonTintList(ColorStateList.valueOf(myColor)); // Your code applying tint to button
        appCompatRadioButton.getCompoundDrawables()[3].setColorFilter(myColor, PorterDuff.Mode.SRC_ATOP); // Applying tint to drawable at bottom. '3' to get drawable at bottom
    }

继续只是使用大多数相同的参数再次调用,除了迭代的部分将改变为下一个东西。

休息是一个基本情况。

那么什么是(let name ((iter iter-expr) (arg1 expr1) (arg2 expr2)) (cond (continue-predicate (name (next iter) arg1 arg2))) (break-predicate break-expression-value) (else (name (next iter) next-arg1-expression next-ar2-expression)))) ?它是一个带有中断谓词和默认大小写的while

Scheme并没有真正的let构造。如果你阅读报告,你会发现它只是一个语法糖(宏)变成类似于while的东西。

如果你希望能够退出它而不需要完成所有先前的计算,那么你需要它是尾递归的。你也可以使用let提供退出延续,这基本上是让你在幕后为你做的。通常call/cc对于初学者来说相当远,并且掌握它需要一些时间,因此使得程序尾递归比执行这样的操作更容易理解:

call/cc