unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* to serialize/deserialize closures; and multithreading
@ 2004-03-25  6:19 Nicholas Paul Johnson
  2004-03-25  6:43 ` Paul Jarc
  2004-03-25 12:40 ` Greg Troxel
  0 siblings, 2 replies; 10+ messages in thread
From: Nicholas Paul Johnson @ 2004-03-25  6:19 UTC (permalink / raw)


Hello all,

I am writing a program in C which will make heavy use of the guile 
scheme interpreter, and want to use the SCM_ interface as opposed to the 
GH_ interface.  two questions:

1. If I have a scheme value that is a closure, is there any way that I can
serialize this closure (from C code) into a form that it can be
deserialized back into a SCM closure variable (again, by C code)?  I can
assume for this question that both ends of the serial line are running the
same version of gnu guile and my software, but cannot assume that both
ends are running on the same computer architecture.  Would it instead
only be possible for me to transfer closures as their scheme source.

2. Is it possible to have disjoint instances of the scheme interpreter 
running in the same process but in different threads?  I.E. If my C 
program was multithreaded, could more than one of the threads create a 
guile/scheme interpretter?  If so, would I have to use the initialization 
functions more than once.

Also, does anyone know of a good documentation of the SCM_ API?  I've not 
been able to find one.

-- 
Nicholas Paul Johnson
nickjohnsonSPAM^H^H^H^H@virginia.edu
http://manjac.ath.cx/nick
 _
( ) ascii ribbon campaign - against html mail 
 X                        - against microsoft attachments
/ \ http://www.google.com/search?q=ascii+ribbon
--




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: to serialize/deserialize closures; and multithreading
@ 2004-03-25 22:38 Faraz Shahbazker
  2004-03-26 13:05 ` rm
  0 siblings, 1 reply; 10+ messages in thread
From: Faraz Shahbazker @ 2004-03-25 22:38 UTC (permalink / raw)
  Cc: guile-user


[-- Attachment #1.1: Type: text/html, Size: 2421 bytes --]

[-- Attachment #1.2: Type: text/plain, Size: 1857 bytes --]

nick,

I am curious too : what is your purpose of migration?

        I am working on something similar, for using scheme on
Beowulf-clusters with PVM. Here the purpose of migration is to
remotely-evaluate a sexp. But possible uses of this technology
could be to simply suspend/restart programs(see chpox), or for
delivering active web-content.

> Should a mutation on the new computer of a captured variable
> affect the old computer? - greg

        Basically, if your program is purely/mostly functional,
it might be easy to migrate, while maintaining referential
transparency - just byte-copy(with tags) all   data-types.
The semantics of mutable objects (when mutation does occur)
is for you to decide. It might make greater sense for example
for exceptions to be migrated and  handled remotely, than
say mutexes or ports.


>  Also, you'd need to check that any symbols referenced by
> the code or variables were actually in existence in the
> new guile instance's symbol table.  And that global
> variables referenced by the code got copied (as well as
> the lexical variables).
> So will be recursively nasty.

        I agree with Lynn. Guile's own procedures for
detecting free-variables in expressions may be inadequate for
this.  There is a technique called lambda-lifting meant for
converting sexps into pure combinators(a.k.a thunks). See
Jonhsson's paper on lambda-lifting. It was meant to be used
for compiler optimizations for ML. It was also used in the
Larceny Scheme compiler. But since you are not yet conversant
with SCM_API, I don't know....

        printer/reader is an elegant(read slow ;) solution for
plain Scheme code, but it obviously won't work for custom smobs,
which I am assuming that you might want to create(since you are
using C). 

So tell me more about it!!

- faraz 



[-- Attachment #2: Type: text/plain, Size: 139 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: Re: to serialize/deserialize closures; and multithreading
@ 2004-03-26 20:02 Faraz Shahbazker
  2004-03-26 20:35 ` Andreas Rottmann
  0 siblings, 1 reply; 10+ messages in thread
From: Faraz Shahbazker @ 2004-03-26 20:02 UTC (permalink / raw)
  Cc: nickjohnson, guile-user


[-- Attachment #1.1: Type: text/html, Size: 2934 bytes --]

[-- Attachment #1.2: Type: text/plain, Size: 2184 bytes --]


        The problem with Kali and other distributed Scheme
implementations (and there are quite a few) is that most of
them are built around the imperative style of parallel
computation -- result: things get ugly quickly for complex
programs. You could end-up writing C-like programs in
Scheme.

        IMHO the ideal system would be built around pure
functional style (using MultiLisp type parallel annotations
like future/touch/pcall). This category is also known as
para-functional languages. It has been explored reasonably in
ML/Haskell, but little work of this nature has been done in
Scheme/Lisp so far.....


> Autsch, that does get rather expensive when closures/continuation
> are used (something that does happen occasionally in functional
> programming ;-)

        That I accept. It can be speeded up by building the
transformation into the compiler, something which is not possible
with guile - bigloo perhaps would be a better choice for such work.
But it is difficult to leave guile for 2 reasons :

1. it's got the "GNU" in it's name
2. SCM API is too good - absolutely love it. I don't think anyone
can provide a better extensibility for Scheme than what we have here.



As an aside : for functional purists like me, we should built
future/touch constructs into guile - they are a lot of fun.
Try out these prototypes =>
(Note : these are not actually correct - the simple semantics fail
in the presence of mutations/continuations. A proper implementation
would have to be done in C using Guile-internals)

        It basically works like delay/force except that any-thing
that is "future"d returns a place-holder immediately and starts
concurrent computation. When the value is required, you "touch"
the place-holder, causing a block until the computation completes.


(defmacro future (expr)
  `(let ((ans (cons "#<future>" (cons #f #f))))
     (set-car! (cdr ans)
               (begin-thread
                (set-cdr! (cdr ans) ((lambda () ,expr)))))
     ans))

(defmacro touch (future-val)
  `(begin
     (join-thread (car (cdr ,future-val)))
     (cdr (cdr ,future-val))))


regards,
- faraz 



[-- Attachment #2: Type: text/plain, Size: 139 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-03-26 20:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-25  6:19 to serialize/deserialize closures; and multithreading Nicholas Paul Johnson
2004-03-25  6:43 ` Paul Jarc
2004-03-25 12:40 ` Greg Troxel
2004-03-25 17:18   ` Lynn Winebarger
2004-03-25 18:11     ` Lynn Winebarger
2004-03-25 19:55     ` Paul Jarc
  -- strict thread matches above, loose matches on Subject: below --
2004-03-25 22:38 Faraz Shahbazker
2004-03-26 13:05 ` rm
2004-03-26 15:22   ` Nicholas Paul Johnson
2004-03-26 20:02 Faraz Shahbazker
2004-03-26 20:35 ` Andreas Rottmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).