Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!travelers.mail.cornell.edu!news.kei.com!news.mathworks.com!newsfeed.internetmci.com!howland.reston.ans.net!swrinde!sgigate.sgi.com!sgiblab!news.cs.indiana.edu!jrossie@cs.indiana.edu
From: "Jon Rossie" <jrossie@cs.indiana.edu>
Subject: Re: A couple MORE simple questions
Message-ID: <1995Oct24.090949.895@news.cs.indiana.edu>
Organization: Computer Science, Indiana University
References: <45u7g0$b20_002@watstar.uwaterloo.ca> <FOX.95Oct20050018@graphics.cs.nyu.edu>
Date: Tue, 24 Oct 1995 09:09:40 -0500 (EST)
Lines: 64

In article <FOX.95Oct20050018@graphics.cs.nyu.edu>,
David Fox <fox@graphics.cs.nyu.edu> wrote:
>In article <45u7g0$b20_002@watstar.uwaterloo.ca> MACHAPUT@ARTSU1.uwaterloo.ca (Matthew Allan Chaput) writes:
>
>] How can I set up contingent variables in scheme? Take the problem
>] 
>] > (define rent 250)
>] > (define months 4)
>] > (define total (* rent months))
>] > total
>] 1000
>] > (define rent 500)
>] > total
>] 1000
>
>Why would you want to do that?  The object you call total here is
>a function of rent and months:
>
>> (define (total rent months) (* rent months))
>> (total)
>1000
>> (set! rent 500)
>> (total)
>2000
>-- 
>David Fox	   I have spoken.  All depart.		xoF divaD
>NYU Media Research Lab			   baL hcraeseR aideM UYN
>		  http://found.cs.nyu.edu/fox/


This is nonsense.  You have made total a function of two arguments, and
called it with none.  That should be an error.  Are you just making this
up, or is your implementation that forgiving?

You have actually implied two solutions:

ONE --- use global variables and assignments to model parameter passing:

(define rent 250)
(define months 4)
(define total (lambda () (* rent months)))
(total) => 1000
(set! rent 500)
(total) => 2000

TWO -- use the modern language feature "parameter passing" ...

(define total (lambda (rent months) (* rent months)))
(total 250 4) => 1000
(total 500 4) => 2000

 which doesn't preculde named values ....

(define rent 250)
(define months 4)
(total rent months) => 1000
(total (* rent 2) months) => 2000

Okay, enough.  
-- 
                                  Jon Rossie <jrossie@cs.indiana.edu>
                             Ph.D. Candidate in Programming Languages
                        Indiana University Computer Science
                   <http://www.cs.indiana.edu/hyplan/jrossie.html>
