I think I'm more confused than ever.  The following fails:

(define (foo a)
  (lambda () a ))

(define bar
  (foo 42))

(serialize bar)

because "a" is a free variable.  Fair enough.  If we expand
the syntatic sugar for the definition of foo, the following
also fails:

(define foo (lambda (a) (lambda () a ) ) )
(define bar (foo 42))
(serialize bar)

No problem -- it's equivalent to the first.  But now if
we inline the definition of foo, it succeeds:

(define bar ((lambda (a) (lambda () a ) ) 42) )
(serialize bar)

I suppose this is because ikarus somehow is able to
optimize the final expression, "noticing" that the
expression simplifies to (lambda () 42), and no
free variables exist.  And I furthermore suppose that such
an optimization is not possible in the former cases.

Is there a general technique for eliminating free
variables in these sorts of expressions?

Thanks for your patience.  The subtleties of all this
are currently beyond me, but I hope to learn...

                      -- David



On Feb 5, 7:17 am, David Wingate <[email protected]> wrote:
> Thanks for the help!
>
> Interestingly enough, the example that you gave serializes
> without any problems (you can remove the "let" block, and
> it still serializes).
>
> The only example that I've been able to construct by
> hand is this:
>
> (serialize command-line-arguments)
>
> which fails.  It makes sense to me that you can't serialize
> things like open file handles, network sockets, and the like.
> Command-line parameters seem different, but I suppose I can
> see how at some level some OS voodoo might be going on.
>
> So I'm still not sure that I totally understand what's going
> on.  Sigh.
>
> (Or better: I'm totally sure that I still don't understand.  :) )
>
>                        -- David
>
> On Feb 4, 8:08 pm, Andreas Rottmann <[email protected]> wrote:
>
> > David Wingate <[email protected]> writes:
> > > Hello, all.  I've recently ported my scheme application to Ikarus
> > > (love it!) and have a question.
>
> > > I'm interested in serializing a complex structure which consists of
> > > all sorts of functions, lists, strings and numbers.  I've defined
> > > serialize and deserialize using the same code found in scheme/tests/
> > > fasl.ss.
>
> > > When I attempt to serialize my structure, it gives the following
> > > error:
>
> > >> (serialize foodata)
> > > Unhandled exception
> > >  Condition components:
> > >    1. &assertion
> > >    2. &who: fasl-write
> > >    3. &message: "Cannot write a non-thunk procedure; the one given has
> > > free vars"
> > >    4. &irritants: (2)
>
> > > I imagine this is NOT an error in Ikarus, but rather an error in my
> > > thinking.
>
> > > Could someone help me understand what generates this sort of error?
> > > For example, the FASL system is quite happy to serialize the
> > > following:
>
> > >> (serialize (lambda(x) x))
>
> > > which also appears to have "free vars."  So I'm not sure what that
> > > means, or how to best fix it.
>
> > No, this has no free vars, as 'x' is bound in the expression '(lambda
> > (x) x)' (as there is a formal parameter, which it refers to). This
> > example is hence entirely independent of its environment; the following
> > is not:
>
> > (let ((foo 42))
> >  (serialize (lambda (x) (+ x foo))))
>
> > In the expression '(lambda (x) (+ x foo))', 'x' occurs bound, and 'foo'
> > occurs free. See alsohttp://en.wikipedia.org/wiki/Bound_variable.
>
> > > P.S.  What does FASL stand for, anyway?  :)
>
> > I think it's "FASt Load" or something alike.
>
> > Kind regards, Rotty
> > --
> > Andreas Rottmann         | ro...@icq      | 118634...@icq | 
> > [email protected]http://rotty.uttx.net  | GnuPG 
> > Key:http://rotty.uttx.net/gpg.asc
> > Fingerprint              | C38A 39C5 16D7 B69F 33A3  6993 22C8 27F7 35A9 
> > 92E7
> > v2sw7MYChw5pr5OFma7u7Lw2m5g/l7Di6e6t5BSb7en6g3/5HZa2Xs6MSr1/2p7 
> > hackerkey.com
>
> > Always be wary of the Software Engineer who carries a screwdriver.
> >   -- Robert Paul
>
>

Reply via email to