I finally came across the need for higher-order functions. Specifically a 
function returning a new function that closes a variable (that happens to also 
be a function but that's inconsequential).

Turns out passing functions as arguments works fine but returned functions 
don't close their lexical scope properly.

Test case:

(define make-higher-order (fn (predicate)
  (fn (arg)
    (if (not (predicate arg)) (print "FAILED higher-order function test")))))

((make-higher-order
  (fn (arg1)
    (= "hello higher-order" arg1)))
  "hello higher-order")

I traced this down to what appears to be code that's trying to do object 
pooling with context objects. This wasn't playing too nicely with closures 
since it modified the home context shared state.

My fix was simply to get rid of the `new-<context>` function and promote 
`new-base-<context>` to that role (i.e. always create a new context for now. I 
understand the need for this optimization but it seems like it could be 
implemented in a more orthogonal way - a proper object pool, a GC that 
separates ephemeral from longer lived objects, etc.

shawn
_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to