Balazs Scheidler <[EMAIL PROTECTED]> writes:

> >   (lambda (port connection)
> >     (start-io (listen port connection)
> >               (open-direct-tcp connection)))
>
> I don't fully understand the above description. (maybe because I don't
> know LISP enough) what does "lambda" mean?

Sorry. Sometimes I assume that everybody has at least a little
experience with LISP, which is obviously wrong. lambda is used to
create/define/represent a function. The syntax is

  (lambda (formal-arguments) body)

and the result is a function. When the function is applied to
arguments, the body is evaluated/executed, with the formal arguments
replaced by the actual arguments. A simple example:

  (lambda (x) (* x x))

is the function which squares its arguments. Function application is
written as a (f a), not f(a) as in C. We can apply the square function
to an argument, say 7, like

  ( (lambda (x) (* x x)) 7)

where replacing the formal argument x with the actual argument 7 gives
(* 7 7). The name "lambda" comes from the "lambda calculus", invented
by Church in the study of computable functions, or something like
that.

So the example above means a function that takes two arguments,
CONNETION and PORT. Translated to C, it would be something like

object foo (object connection, object port)
{ return start_io(listen(port, connection),
                  open_direct_tcp(connection)); }

except that the name of the function, "foo", is not present in the
lambda-version. 

A really good book is Abelson and Sussman's "Structure and
Interpretation of Computer Programs" (also known as SICP). ISBN
0-262-01153-0 and ISBN 0-07-000484-6. This is not a book about LISP,
but about programming in general. As a side-effect, it is also a good
book about Scheme (a LISP dialect).

> What does GABA stand for ? 

Well, that's a good question. Clearly, "CLASS" had to be replaced, as
it gave the wrong associations. GABA is one signal substance in the
brain. It is also the handle of one of the persons who helped me to
sort out the SK combinator thing. One of his earlier handles was "Yf =
f(Yf)", which is a property of the Y-combinator that can be used to
define recursive functions in the lambda-calculus. So it just seemed
like a good name ;)

> >   A(S2(A(S2(A(K1, S)), A(S2(A(K1, S2(A(K1, foo_start)))), A(S2(A(K1, 
>S2(foo_listen))), K)))), A(S2(A(K1, K)), foo_open));

> This sounds chinese to me. What are those combinators? Or better I'll
> download your cvs repository, and check your code.

Yes, the combinator expression is quite unreadable. The SK translation
is described in chapter 16 of "The Implementation of Functional
Progamming Languages" by Simon L. Peyton Jones, ISBN 0-13-453333-X,
ISBN 0-13-3325-9 (paperback). I'm reading it right now. It also
describes some basic optimizations.

The definitions of S and K are

  S f g x == ((f x) (g x))

I.e. if f and g are two functions, then (S f g) is a new function.
When it is applied to an argument x, both f and g will be applied to
x, and then the result of (f x) (which should be a function) is
applied to the result of (g x).

  K x y == x

I.e. if x is any object, then (K x) is a function which, when called
with any argument y, discards the argument and returns x.

> I also think that this is very cool, since I had to code some of those
> "continuation" structures for tcpforwarding, and I can tell it's a pain.
> 
> I am mirroring your cvs repo right now. I expect my tcpforwarding code to
> be fully reorganized. I may not even recognize it...

Unfortunately, I haven't got there yet.

Regards,
/Niels

Reply via email to