您问题的答案是 是的:
(define (foo ...)
(call-with-current-continuation
(lambda (return)
...... ; here anywhere inside any sub-expression
...... ; you can call (return 42)
...... ; to return 42 from `foo` right away
)))
这设置了 出口 延续 这样您就可以从函数的身体内部返回结果值。通常的方案方法是将您的返回表作为最后一个表格,因此其值将返回:
(let forLoop ()
(when (valid-choice graph assignment c)
(hash-set! assignment u c)
(set! result (backtrack n graph assignment))
(cond
((not (eq? result #f))
result)) ; the value of `cond` form is ignored
(hash-remove! assignment u))
; the value of `when` form is ignored
(set! c (+ c 1))
(if (>= n c) ; `if` must be the last form
(forLoop) ; so that `forLoop` is tail-recursive
;; else:
return-value) ; <<------ the last form's value
) ; is returned from `let` form
;; (let forLoop ...) must be the last form in your function
;; so its value is returned from the function
)
您在这里也有问题:
(cond (assignment-complete n assignment) (assignment) )
此代码确实如此 不是 打个电话 (assignment-complete n assignment)
. 。相反,它检查是否变量 assignment-complete
具有非零值,如果没有,则检查 assignment
变量,但是无论如何,其返回的值无论如何都被忽略。也许那里还有更多的括号,/或 else
条款。