# [racket] Three questions related DrRacket

 From: Justin Zamora (justin at zamora.com) Date: Wed Jun 1 23:31:56 EDT 2011 Previous message: [racket] Three questions related DrRacket Next message: [racket] disable garbage collection Messages sorted by: [date] [thread] [subject] [author]

```One of the nice things about Racket is that it works a lot like
algebra.  You combine Racket expressions the same way you combine
mathematical expressions.  In math, you would write a single
expression that's built out of smaller expressions, such as 10 * (x +
1).  In Racket, you would write this as: (* 10 (+ x 1)).  Just as in
algebra, the innermost expressions are evaluated first, and the the
results are used by the outer expressions to compute a final result.
You will get farther in Racket by thinking in terms of evaluating
expressions and reducing them to a result than by thinking in terms of
executing a sequence of steps.

You may be interested in looking at some video lectures I made.  The
class got cancelled, so there are only a few lectures, but they deal
with the basics of Racket expressions.  They are at

Justin

On Wed, Jun 1, 2011 at 11:09 PM, Yingjian Ma <yingjian.ma1955 at gmail.com> wrote:
>
> My real need is to use the result of the first function in the second
> function.  Is there a standard way to pass a variable into the next
> function?
>
> On Wed, Jun 1, 2011 at 6:24 PM, Shriram Krishnamurthi <sk at cs.brown.edu>
> wrote:
>>
>> Also note that if you programmed in the Student Language levels, this
>> function would be illegal (and it might give you some insight into how
>> this programming style works).
>>
>> On Wed, Jun 1, 2011 at 9:19 PM, Justin Zamora <justin at zamora.com> wrote:
>> > On Wed, Jun 1, 2011 at 7:22 PM, Yingjian Ma <yingjian.ma1955 at gmail.com>
>> > wrote:
>> >>
>> >> In my question
>> >> (define (p x)
>> >>   (+ x 10)
>> >>   (* x 10)
>> >>   )
>> >> It seems it only executes (* x 10)
>> >
>> > No, it executes both of them.  It evaluates (+ x 10), then throws away
>> > the value it just computed.  Then it evaluated (* x 10), since that is
>> > the last expression, the value gets returned as the value of the
>> > function.  When there is more than one expression in a function body,
>> > all of them get evaluated, but only the last is returned.  If you want
>> > to use the results of both expressions, then you need to use two
>> > functions, one for each expression, as Shriram said.
>> >
>> > Justin
>> >
>> > _________________________________________________