chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] make-parameter, parameterize & SRFI-39


From: F. Wittenberger
Subject: [Chicken-users] make-parameter, parameterize & SRFI-39
Date: Thu, 07 Aug 2008 17:08:05 +0200

Hi all,

here a small test case, which shows how parameter objects work in
chicken:

---- %< ----
#!/usr/bin/csi -i

(require-extension srfi-18)

(define p (make-parameter #f))

(define ts (thread-start! (lambda () (thread-sleep! 3) (print "now
" (p)))))

(thread-sleep! 1)

(p 42)

(thread-join! ts)
---- %< ----

This will print "now #f".  To my understanding (and not only mine) of
SRFI-39, it should print "now 42".

Rationale:

a) The latter is needed for one of "standard" uses of parameter objects,
global setting (which might need dynamic overwrites).

b) SRFI-39 defines "parameterize", which is supposed to be the only
form, which modifies the dynamic environment wrt. parameters:

"The dynamic environment is composed of two parts: the local dynamic
environment and the global dynamic environment. The global dynamic
environment is used to lookup parameter objects that can't be found in
the local dynamic environment. When parameter objects are created, their
initial binding is put in the global dynamic environment (by mutation).
The local dynamic environment is only extended by the parameterize
form."

Here a diff, which fixes chicken according to my reading.

Index: library.scm
===================================================================
--- library.scm (Revision 11558)
+++ library.scm (Arbeitskopie)
@@ -2047,12 +2047,15 @@
        (##sys#setslot ##sys#default-parameter-vector i val)
        (lambda arg
          (let ([n (##sys#size ##sys#current-parameter-vector)])
-           (cond [(pair? arg)
+           (cond [(and (pair? arg) (pair? (cdr arg)))
                   (when (fx>= i n)
                     (set! ##sys#current-parameter-vector
                       (##sys#grow-vector ##sys#current-parameter-vector
(fx+ i 1) ##sys#snafu) ) )
                   (##sys#setslot ##sys#current-parameter-vector i
(guard (##sys#slot arg 0)))
                   (##core#undefined) ]
+                 [(pair? arg)
+                  (##sys#setslot ##sys#default-parameter-vector i
(guard (##sys#slot arg 0)))
+                  (##core#undefined) ]
                  [(fx>= i n)
                   (##sys#slot ##sys#default-parameter-vector i) ]
                  [else
Index: chicken-more-macros.scm
===================================================================
--- chicken-more-macros.scm     (Revision 11558)
+++ chicken-more-macros.scm     (Arbeitskopie)
@@ -213,7 +213,7 @@
            [aliases2 (##sys#map (lambda (z) (gensym)) params)] )
        `(let ,(##sys#append (map ##sys#list aliases params) (map
##sys#list aliases2 vals))
          (let ((,swap (lambda ()
-                        ,@(map (lambda (a a2) `(let ((t (,a))) (,a ,a2)
(##core#set! ,a2 t)))
+                        ,@(map (lambda (a a2) `(let ((t (,a))) (,a ,a2
'local) (##core#set! ,a2 t)))
                                aliases aliases2) ) ) )
            (##sys#dynamic-wind 
                ,swap

Open questions / problems:

a) So far I have only checked only one more Scheme implementation.
Maybe we are wrong about the intended function of parameter objects.

b) Even if the above is not only a modification, but a fix to the
chicken system, existing programs might already depend on the chicken
way.

c) How should the issue be dealt with?

Best regards

/Jörg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]