|
|||
|
Roelof Wobben writes:
> > Something like this should work: > > > > (define (h x) (- (f x) (g (f x)))) > > (define (g x) (* x 0.15)) > > (define (f x) (* x 12)) > > > > Oke, > > Thanks for the tip. > > Just to be sure. > > When function h is executed with argument x. > Then in the calculation area (- f x) (g (f x)) > First function f is executed and after that function g with as > argument function f . Let's be pedantic with the parens: (- (f x) (g (f x))). You got the order of execution right: - is called with two arguments, the first is the value of (f x), the second the value of (g (f x)). In the second argument expression, g is called with the value of (f x). Scheme is said to use call-by-value (eager), as opposed to policies like call-by-name (old) and call-by-need (lazy) that may not evaluate argument expressions in this order (or at all). |
|
|
||||
|
||||
|
|
|
|||
|
Everyone thanks for the explanation and patience with me.
I begin to understand how scheme works. Roelof Op 2-2-2012 14:05, Jussi Piitulainen schreef: > Roelof Wobben writes: > >>> Something like this should work: >>> >>> (define (h x) (- (f x) (g (f x)))) >>> (define (g x) (* x 0.15)) >>> (define (f x) (* x 12)) >>> >> >> Oke, >> >> Thanks for the tip. >> >> Just to be sure. >> >> When function h is executed with argument x. >> Then in the calculation area (- f x) (g (f x)) >> First function f is executed and after that function g with as >> argument function f . > > Let's be pedantic with the parens: (- (f x) (g (f x))). > > You got the order of execution right: - is called with two arguments, > the first is the value of (f x), the second the value of (g (f x)). In > the second argument expression, g is called with the value of (f x). > > Scheme is said to use call-by-value (eager), as opposed to policies > like call-by-name (old) and call-by-need (lazy) that may not evaluate > argument expressions in this order (or at all). |
|
|||
|
Jussi Piitulainen <jpiitula@ling.helsinki.fi> writes:
> Roelof Wobben writes: > >> > Something like this should work: >> > >> > (define (h x) (- (f x) (g (f x)))) >> > (define (g x) (* x 0.15)) >> > (define (f x) (* x 12)) >> > >> >> Oke, >> >> Thanks for the tip. >> >> Just to be sure. >> >> When function h is executed with argument x. >> Then in the calculation area (- f x) (g (f x)) >> First function f is executed and after that function g with as >> argument function f . > > Let's be pedantic with the parens: (- (f x) (g (f x))). > > You got the order of execution right: - is called with two arguments, > the first is the value of (f x), the second the value of (g (f x)). In > the second argument expression, g is called with the value of (f x). > > Scheme is said to use call-by-value (eager), as opposed to policies > like call-by-name (old) and call-by-need (lazy) that may not evaluate > argument expressions in this order (or at all). As this dude says, you're in a REPL, when you put a parens you call a function, when you have a variable the result gets printed. CF |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|