Stephen Edwards (edwards@CS.VT.EDU)
Fri, 3 Mar 2000 12:11:19 -0500
Message-ID: <38BFF237.B3DAFD88@cs.vt.edu> Date: Fri, 3 Mar 2000 12:11:19 -0500 From: Stephen Edwards <edwards@CS.VT.EDU> Subject: Re: [CS3304_1381] variable storing value from function
> I've been practically banging my head on my desk over this one... someone
> please tell me what's wrong with this:
Stick to using "let" for introducing local names, and only use
"define" for creating top-level (global) names. The correct use
of "let" in your example looks like this:
(define eval-line "blah")
(define (function)
(let ((line-value (eval-line)))
(write-string line-value)
#t
)
)
The structure of a "let" looks like:
(let
<declaration list>
<expressions>
.
.
.
)
In a "named let", a single symbolic name precedes the <declaration
list>. The <declaration list> is a *single* list. Each element in the list
is itself another list representing a single declaration--it is a list
with two elements: the new variable name followed by the variable's value.
In general, that looks something like this.
(let
( ; start of the declaration list
(variable1 value1) ; first declaration
(variable2 value2) ; second declaration
... ; more declarations
) ; end of declaration list
(expression1) ; first "statement" in body of let
... ; more statements, as necessary
)
In your example, there was only one local name being introduced,
so stripping out the comments and combining the lines a bit gives:
(let ((line-value (eval-line)))
(expresssion1)
...
)
If you count the parentheses, you'll see how they match up to the
more expanded version shown above. My advice: if the more expanded
version is easier for you to read, then use it! There are no bonus
points or speed increases just because you write compact source
code :-).
-- Steve
-- Stephen Edwards 641 McBryde Hall Dept. of Computer Science e-mail : edwards@cs.vt.edu U.S. mail: Virginia Tech (VPI&SU) office phone: (540)-231-5723 Blacksburg, VA 24061-0106 -------------------------------------------------------------------------------
This archive was generated by hypermail 2.0b3 on Fri Mar 03 2000 - 12:11:33 EST