1( import ( chezscheme ) )
2
3
4 ( define ( bigger a b )
5 ( if ( > a b )
6 a
7 b
8 )
9 )
10
11 ( define ( smaller a b )
12 ( if ( < a b )
13 a
14 b
15 )
16 )
17
18
19 ( define ( square x ) ( * x x ) )
20
21
22
23
24 ( define ( sum-of-squares a b )
25 ( + ( square a ) ( square b ) )
26 )
27
28
29
30
31 ( define ( bigger-sum-of-squares a b c )
32 ( sum-of-squares ( bigger a b ) ( bigger( smaller( a b
) ) c ) )
33 )
34
35
36 bigger-sum-of-squares( 1 3 7 )
37
/* I install Chez Scheme Version 9.5.6 When I use this command to compile : chez bigger.ss, it will happen: "Exception: attempt to apply non-procedure 1" I try many times ,but still not solve it , who can tell me where's bug ? */
Here is the code conventionally formatted, with corrected (probably) parentheses:
The error "Exception: attempt to apply non-procedure 1" results from
bigger-sum-of-squares( 1 3 7 )
-- the Scheme processor interprets(1 3 7)
as a procedure application (like(+ 3 7)
), but1
is not a procedure.For testing, the code can be copied from an editor and pasted into a terminal:
...or the definitions in a file can be
load
ed into Chez Scheme's interaction environment: