guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nesting guidelines?


From: Martin Grabmueller
Subject: Re: nesting guidelines?
Date: Wed, 14 Feb 2001 15:32:02 +0100 (MET)

> From: address@hidden
> Date: Wed, 14 Feb 2001 6:37:29 +0100
> 
> Hey list,
> 
> I'm trying (slowly) to get my head around scheme/guile.  I'm
> having a bit of difficulty with the most basic of things: the
> nesting of parenthesis.  Can someone give me or point me to
> info on scheme's order of evaluation?

First of all, I recommend to read a tutorial on Scheme.  A good one is
Dorai Sitaram's" Teach Yourself Scheme in Fixnum Days", to be found
at:

http://www.cs.rice.edu/~dorai/t-y-scheme/t-y-scheme.html

(when reading it, you have to change references to mzscheme with
guile, of course ;-)

The evaluation rules are simple.

- All constants, like strings, numbers, characters etc. evaluate to
  themselves:

guile> "as"
"as"
guile> 1
1
guile> #\a
#\a

- Quoted expressions evaluate to themselves, also:

guile> '"as"
"as"
guile> '1
1
guile> '(foo bar) 
(foo bar)

(the last example is a a quoted list. Lists are treated specially when
not quoted. See below.)

> What gets included in the "same set" of parenthesis, and what
> gets nested?  

When you enter a parenthesized expression, it is treated as a
procedure application, that means that the first element in the list
is used as a procedure, and the remaining elements are operands to the
procedure.

Example: (+ 1 1)

`+' is the procedure, and the two 1s are the operands.

It is important, that in Scheme all these list elements are evaluated
before they are used.  That means, first the variable named `+' and
the constants 1 and 1 are evaluated, then the procedure is applied to
the operands, and the result (2) is returned.

When you have nested parentheses, they are evaluated from the
innermost nested expression to the outermost.

Example: (+ (* 2 3) (- 3 1))

First the expressions (* 2 3) and (- 3 1) are evaluated (in an
unspecified order), and then the addition procedure is applied to the
results of the inner expressions.

I hope that helps,
  'martin
-- 
Martin Grabmueller              address@hidden
http://www.pintus.de/mgrabmue/  address@hidden on EFnet



reply via email to

[Prev in Thread] Current Thread [Next in Thread]