Am Thu, 12 Mar 2020 14:44:03 +0800 schrieb Adam adam.mlmb@gmail.com:
On Wed, 11 Mar 2020 at 19:39, Jörg F. Wittenberger < Joerg.Wittenberger@softeyes.net> wrote: [...]
In practice I'm much easier confused understanding code with dynamic scope applies than code where lexical scope rules.
As for me I find the parameter objects highly intuitive.
YMMV.
I must admit that I did not quite understand all of your remarks:
The teleport example I included in my third post in this thread, reflects what I use parameter objects for. Again:
(define (a)
; Teleport from hr (b)) (define (b) (c)) (define (c) ; Teleport to hr #!void)
This for instance. Which "hr" you mean?
including a hundred arguments would be too verbose
Recall, when assigning "hundreds of arguments" to parameters, that parameters are expensive. (Can you, e.g., group them into records?)
arguments (e.g. in the example above, the |b| procedure does not need to define as arguments the values teleported from |a| to |c|).
The |doit!| example you provided does not illustrate this particular utility,
Sorry for that. I actually meant "doit!" to show that a 0-ari procedure whould have access to parameters bound by `parameterize`. However I badly failed to put an intermediate procedure in between.
Nevertheless: the "doit!" should do the expected thing. The "dare!" was meant to look incredibly simillar and still _appear_ to ignore the parameterize. (However: If you where to follow the dynamic-wind chain, you'd see that the bindings are unwound for the "dare!"-call and rewound afterwards.)
comprehend what your |magic| procedure does so can't comment on it.
Here a slight rewrite:
(define (call-with-current-dynamic-extent proc) ;; patterned after call/cc (proc (call-with-current-continuation (lambda (return) (call-with-values (lambda () (call-with-current-continuation (lambda (c) (return (lambda (thunk) (call-with-current-continuation (lambda (k) (c k thunk)))))))) (lambda (k thunk) (call-with-values thunk k)))))))
(define (dynamic f) ;; convert `f` into a version which restores the dynamic envt first (call-with-current-dynamic-extent (lambda (dynamic-extent) (lambda args (dynamic-extent (lambda () (apply f args)))))))
(define magic dynamic)
additional consideration (unclear of details in this moment). call/c is not so frequently used though and its use does mean that
Except, maybe, in exception handling etc.
Best
Jörg