[gambit-list] Parameter objects performance Q

Jörg F. Wittenberger Joerg.Wittenberger at softeyes.net
Tue Mar 10 18:41:12 EDT 2020


Hi Adam,

On Sun, 8 Mar 2020 23:26:41 +0800
Adam <adam.mlmb at gmail.com> wrote:

> Hi Marc,
> 
> Cool, wonderful!
> 
> 
> Yeah for any situation like
> 
> (define (a)
>   ; Teleport from hr
>   (b))
> (define (b) (c))
> (define (c)
>   ; Teleport to hr
>   #!void)
> 
> , just totally great.

Before you fall too deeply in love with parameters, beware that heavily
parameterized code can easily become hard to read:

$ gsi

(define p-a (make-parameter 46))
(define p-b (make-parameter 23))
(define p-op (make-parameter -))

(define (doit!)
  (let ((op (p-op)) (a (p-a)) (b (p-b)))
    (display `("calculating ( " ,op " ) applied to" ,a "and" ,b))
    (newline)
    (op a b)))

(parameterize
 ((p-op *) (p-a 21) (p-b 2))
 (doit!))

;; =>
;; (calculating (  #<procedure #11 *>  ) applied to 21 and 2)
;; 42

;; Great!

(load "magic.scm")  ;; attached file magic.scm

(define dare! (magic doit!))

(parameterize
 ((p-op *) (p-a 21) (p-b 2))
 (dare!))
;; =>
;; (calculating (  #<procedure #4 ->  ) applied to 46 and 23)
;; 23

;; YMMV, but I find this not exactly intuitive.

Regards

/Jörg


-------------- next part --------------
A non-text attachment was scrubbed...
Name: magic.scm
Type: text/x-scheme
Size: 708 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20200310/216f05d7/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: magic-test.scm
Type: text/x-scheme
Size: 1623 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20200310/216f05d7/attachment-0001.bin>


More information about the Gambit-list mailing list