[CM] bit OT, Might be of interest

Iain Duncan iainduncanlists at gmail.com
Sat Jun 6 12:03:18 PDT 2020


Thanks Bill, that gives me a bunch more to chew on.

As part of my documentation for Scheme For Max, I plan on writing a page
"S7 for people coming from Clojure". When I do so I will be sure to check
here to make sure I present things accurately. :-)

iain

On Sat, Jun 6, 2020 at 7:34 AM <bil at ccrma.stanford.edu> wrote:

> My understanding of the transactional memory stuff was that it was a way
> to simplify multithreaded programs.  When I had within-s7 threads, I
> found
> they were slow because of contention for the heap and whatnot, and
> using multiple s7 interpreters instead was faster and simpler (from
> s7's point of view, of course).  My thought was that thread-global
> variables could be handled through a traditional data base -- I think
> the libgdbm example in s7.html touches on this.
>
> The immutable! function sets its argument immutable, so I think
> almost anything in s7 can be marked as immutable (you can also
> use a setter function).  It's not automatic, but you could
> obviously make it a local convention:
>
> (define (make-immutable-vector len)
>    (immutable! (make-vector len)))
>
> A lot of the metadata info in clojure is also supported in s7, but
> under a different set of names:  setter, documentation, signature,
> arity,
> and funclet for function definition location, argument list and source.
> Each function or c-object also has a local let that can
> contain arbitrary info under arbitrary names.  I haven't
> implemented that for sequences, but you could implement it
> in scheme by using the sequence's setter function's closure
> (a kludge, but it should work).
>
> ;;; a function with user-defined metadata:
> (define func
>    (let ((my-special-info "hi"))
>      (lambda (x)
>        (+ x 1))))
>
> ((funclet func) :my-special-info) -> "hi"
>
> ;;; use define-constant to define an immutable function
>
> ;;; a vector with user-defined metadata
> (define vct
>     (let ((v (make-vector 23)))
>       (set! (setter 'v)
>             (let ((my-info "ho"))
>               (lambda (s v)
>                 v)))
>       (immutable! v)))
>
> (immutable? vct) -> #t
> (vector-set! vct 0 32) -> error: can't vector-set! ... (it is immutable)
> ((funclet (setter vct)) :my-info) -> "ho"
>
> I need to look at clojure more closely -- I probably
> misunderstand the argot.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/mailman/private/cmdist/attachments/20200606/81f5f469/attachment.html>


More information about the Cmdist mailing list