[alexandria-devel] Possible WITH-COLLECTOR/COLLECTORS macros

Tobias C. Rittweiler tcr at freebits.de
Mon Mar 8 08:53:24 UTC 2010


Nikodemus Siivola <nikodemus at random-state.net> writes:

> On 7 March 2010 18:25, John Fremlin <john at fremlin.org> wrote:
>> Here is how ClozureCL does the same thing. I'm not at all suggesting
>> that it's better than with-collector, just that it is another example of
>> this useful wheel being invented.
>>
>> My opinion is that something along these lines would be grand.
>>
>>
>> ;;;   Copyright (C) 2009 Clozure Associates
>> ;;;   Copyright (C) 1994-2001 Digitool, Inc
>> ;;;   Clozure CL is licensed under the terms of the Lisp Lesser GNU Public
>> ;;;   License
>>
>> ;;;
>> ;;;    The ultimate collection macro...
>> ;;;
>>
>> (defmacro collect (collections &body body)
>
> Heh, that's the same CMUCL heritage COLLECT that SBCL has as well. (At
> least the docstring is identical, and CMUCL has had COLLECT in it's
> tree since 1990 at least.)
>
> I'm not strongly opposed to COLLECT, but neither am I a great fan of it.

I have a WITH-BUCKETS pending for inclusion into SBCL because it also
provides a :SYNCHRONIZED parameter which would rule it out from
inclusion into alexandria. It's not yet lock-free which is the reason I
haven't proposed it on the SBCL lists yet. I use
WITH-BUCKETS+synchronized for writing test cases involving multiple
threads.

Syntax is:

  (with-buckets collect-into ((foo :name "foo bucket" :synchronized t))
    (dotimes (i N)
      (make-thread #'(lambda () 
                       (sleep (random 1.0))
                       (collect-into foo i))))
    foo)

  -T.





More information about the alexandria-devel mailing list