1
我們想從C#中使用IronScheme調用閉包方案,但是我們不斷得到一個異常,並說「不是一對」。使用ironscheme調用閉包
我們想調用下面的計劃代碼:
(define (create-robot name)
(let* (
(position (cons 0 0))
(move-forward(lambda (x)
(set! position (cons (car position) (+ x (cdr position))))
position))
)
(list name (cons 'position position) (cons 'move-forward move-forward))));return attribute 'name' and procedure 'move-north'
(define (get-from-robot r name)
(cdr (assq name (cdr r))))
使用C#下面的代碼:
Callable c1 = schemeInterpretor.getCallable("create-robot");
Cons john = (Cons)c1.Call("john");
Callable getFromRobot = schemeInterpretor.getCallable("get-from-robot");
getFromRobot.Call(john , "'position");
我們得到以下異常:
{"not a pair"} {&assertion
&who: "cdr"
&message: "not a pair"
&irritants: (#f)
}
是什麼導致問題?我們如何解決它?