[Top][All Lists]

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

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

From: John Cowan
Subject: Re: [Chicken-users] make-parameter, parameterize & SRFI-39
Date: Thu, 7 Aug 2008 12:50:00 -0400
User-agent: Mutt/1.5.13 (2006-08-11)

Jörg F. Wittenberger scripsit:

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

If you look at the third and fourth paragraphs of the Rationale section of
SRFI-39, you'll see that the interaction between parameters and threads
is kept undefined.  SRFI-39 is a retrospective SRFI that attempts to
standardize the intersection of existing implementations.

In particular, there are three ways to set up the parameters of a
child thread:  "fresh parameters", "cloned parameters", and "shared
parameters".  A fresh-parameters Scheme will give the child all-new
parameters initialized to their initial values.  Cloned-parameter
systems will give the child all-new parameters also, but initialized
to the current values in the parent thread.  Finally, shared-parameter
systems give both parent and child access to the same parameter objects.
Chicken is a cloned-parameter system.

The following program should be portable to all Schemes that implement
both SRFI-18 and SRFI-39, and prints different things depending on the
type of parameter sharing:

(require-extension (srfi 18))
(require-extension (srfi 39))
(define hat (make-parameter 'new))
(define (black-hat) (hat 'black))
(define (white-hat) (hat 'white))
(define (print-hat guy)
        (display guy) (display " guy, ")
        (display (hat)) (display " hat")
(define (bad-guy) (print-hat 'bad) (black-hat) (print-hat 'bad))
(print-hat 'good)
(print-hat 'good)
(thread-join! (thread-start! (make-thread bad-guy)))
(print-hat 'good)

It should start by printing "good guy, new hat" on all systems.  Then it
sets the good guy's hat (the good guy is the primordial thread) to white,
and prints "good guy, white hat", also on all systems.  These are basic
sanity checks for the SRFI-39 implementation.

Then it creates the bad guy thread and prints his hat color.  On a
fresh-parameters system, the bad guy's hat will be new; otherwise it
will be white.  Then we explicitly set the bad guy's hat to black and
print that, and rejoin the two threads.

Finally, we print the good guy's hat color.  On a cloned-parameters system
it will still be white, but on a shared-parameters system it will have
changed to black.

> 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.

There are arguments for all three parameter designs.  Ideally perhaps
there would be an additional argument to thread-start! that would specify
what kind of parameter sharing to do.

John Cowan    address@hidden
        Sound change operates regularly to produce irregularities;
        analogy operates irregularly to produce regularities.
                --E.H. Sturtevant, ca. 1945, probably at Yale

reply via email to

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