Greetings,
I have a few questions about call/cc
I work on mzscheme v.360
When I try to execute
( (call/cc (lambda (exit)
(apply (call/cc (lambda (k)(exit k))) '(1 2 3))
)
)
2 )
I get this error
apply: expects type <procedure> as 1st argument, given: 2; other
arguments were: (1 2 3)
It seems normal to me. If I clearly understand the behavior of call/
cc, the execution is as follow
to try to execute E = ( (call/cc ... ) 2 )
1- try to execute the (call/cc ... )
2- this means: try to execute (apply (call/cc (lambda (k)(exit k)))
'(1 2 3))
where exit is the continuation -> (lambda (v) (v 2))
2.1- try to execute (call/cc (lambda (k)(exit k))))
2.2- this means: try to execute (lambda (k)(exit k))
where k is the continuation (lambda (v) (apply v '(1 2 3))
2.3- try to execute (exit k) but exit is a continuation
3- stop all calculus and E returns the result of
((lambda (v) (v 2)) (lambda (v) (apply v '(1 2 3)))
4- this generate an error.
If my understanding is good, then I don't understand why the
following code generate an error:
> ( (call/cc (lambda (exit)
(apply (call/cc (lambda (k)(exit k))) '(1 2 3))
)
)
+ )
procedure application: expected procedure, given: 6; arguments
were: #<primitive:+>
It looks like the call to the continuation exit does not stop all
current calculus.
Can someone explain me where I did wrong ?
Thank you
Ben