[rescue] fans fans fans...

Jonathan C. Patschke jp at celestrion.net
Fri Jun 21 13:54:37 CDT 2002


On Fri, 21 Jun 2002, Dave McGuire wrote:

>   So you STILL haven't pointed me in the right direction for getting a
> quick intro to this too-many-parens-for-normal-people language.  What
> environment should I download?

I'm more of a Schemer than a Lisper (and I use Scheme about 1% as often
as I use C), but I think Scheme is a far-cleaner language than Lisp is,
anyway.  On the flipside, Common Lisp is far more complete than R5RS
Scheme and defines a standard GUI toolkit and message-passing system
(among other things).

I like DrScheme for poking around in.  I have yet to find an environment
for embedded Scheme, so I'm working on my own (Wily) that allows one to
embed Scheme-like code (possibly user-defined) into a C program.

> What platform should I build it on?

DrScheme runs well on Unix, MacOS, and Windows.  It even runs well on
IRIX.  Rice requires it to run flawlessly on MacOS, Solaris, and Windows,
as that's what they use (there's only one SGI left in the CS department).

> Are there any *PRACTICAL* introductory texts, either printed on
> online, that I should read?  Bearing in mind that I've always been a
> procedural programmer..

Josh will kill me for saying this, but Scheme and LISP are not generally
practical languages, especially not from the viewpoint of procedural
programmer.  I had only used procedural languages (and a tiny bit of OO in
C++ and Java) prior to learning Scheme, and I still don't tend to think
of problems in a way that lends to solving them in Scheme.  This has
probably clouded my thinking, as I tend to think in C or assembly, and
Lisp/Scheme were designed to think like people supposedly think.

For example: iteration, as you typically think of it, does not happen in
Scheme, for Scheme does not have what you would call a proper loop.

  Problem:
    Given a list of numbers, find their sum.
  C Solution[1]:
    Find the length of the list, iterate over the list, adding each value
    to an accumulator.  Can be done with a single loop and one
    initialization statement.
  Scheme Solution[1]:
    Create a wrapper function that accept a list of numbers and passes it
    and a 0 to a helper function.   Create a helper function (usually
    unnamed) that accepts a list of numbers and an accumulator.  The
    helper function should first check if the list is empty.  If so, it
    should return the accumulator.  Otherwise, it should add the first
    number in the list to the accumulator, and call itself using the new
    accumulator and the remainder of the list as arguments.

Both solutions -do- the same thing, but the languages have different ways
of expressing them.  There's a lot more to learning Scheme than just
syntax and API.  There is an assload of idiom there that still trips me
up.

Now, once you get past that, Scheme does a lot of things more easily than
C does:
  * Bignums (required as parts of R5RS)
  * Arbitrarily-large data structures (with automatic garbage collection)
  * On-the-fly function composition (functions are lists)
  * Functional encapsulation (unnamed functions within functions)
  * Processing data structures that are recursive in nature (ex: XML)

It basically boils down to using Scheme/LISP for the problems in which
your brain thinks that way, and using C/perl/Pascal for problems in which
your brain things that way.  It's basically the same argument for C++/Java
versus C.  Some problems fit an object-oriented model better than others.

--Jonathan
[1] Note that solutions are not optimized, but these are the most
    "natural" ways of solving the problems in each language.



More information about the rescue mailing list