Hi,

Ian Piumarta <[EMAIL PROTECTED]> writes:

> First, if you don't mind having a special calling convention for
> closures, create a tuple containing a function pointer (lambda) and
> the data it is supposed to operate on.  Invoke all your closures
> using a function that calls the closure's function pointer, passing
> the closure's data as an argument.  The data can be anything,
> including an array of 'free variables' or even a list of such arrays
> linked through their first element (this is actually pretty close to
> the way Pepsi implements blocks).

You know, this sounds close to what I want.  I think my needs would be
fulfilled by a simple (for you, but apparently not for me) change to
function/object/BlockClosure.st.  I believe this can be done using the
existing StaticBlockClosure calling convention.

I'm thinking that another child of StaticBlockClosure (maybe called
StatefulBlockClosure) that has a 'state' member would be appropriate.
I hope that it could use the same 'value' methods that
StaticBlockClosure does.  I tried doing that, but I get segfaults that
I don't really know how to debug... I'm probably missing something
obvious (attached is my attempt).

I would manually set up a StatefulBlockClosure from Jolt code,
building its variableArray by hand.  Eventually, it may make sense to
have some Jolt syntax extensions to create a closure in this way.

For my current problem, passing Jolt callback functions to Pepsi, my
suggestion is just to implement dynamic extent using this minimal
change.  I believe that the more advanced changes (your other "three
options") aren't needed for what I'm trying to accomplish right now.

Thanks,

-- 
Michael FIG <[EMAIL PROTECTED]> //\
   http://michael.fig.org/    \//

Index: objects/BlockClosure.st
===================================================================
--- objects/BlockClosure.st     (revision 245)
+++ objects/BlockClosure.st     (working copy)
@@ -1,4 +1,4 @@
-" BlockClosure.st -- defferred execution of code
+" BlockClosure.st -- deferred execution of code
 
   Copyright (c) 2006, 2007 Ian Piumarta
   All rights reserved.
@@ -106,6 +106,12 @@
 ]
 
 
+StatefulBlockClosure function_: _implementationAddress arity_: _argumentCount 
state: variableArray
+[
+    self  := super function_: _implementationAddress arity_: _argumentCount.
+    state := variableArray.
+]
+
 BlockClosure function_: _implementationAddress arity_: _argumentCount
             outer: outerBlock state: variableArray nlr_: _dynamicEnvironment
 [
Index: objects/Objects.st
===================================================================
--- objects/Objects.st  (revision 245)
+++ objects/Objects.st  (working copy)
@@ -45,6 +45,7 @@
   SlotDictionary : Object ( _size _tally _keys _values default )
   StaticBlockClosure : Object ( _function _arity )
     BlockClosure : StaticBlockClosure ( outer state _nlr )
+    StatefulBlockClosure : StaticBlockClosure ( state )
   SinkStream : Object ()
   ReadStream : Object ( collection position readLimit )
     WriteStream : ReadStream ( writeLimit )
_______________________________________________
fonc mailing list
fonc@vpri.org
http://vpri.org/mailman/listinfo/fonc

Reply via email to