• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

Scheme help

Grandeza

Smash Master
Joined
Nov 11, 2007
Messages
4,035
Location
Brooklyn,New York
So I'm taking my first computer programming class and we're learning a program called DrScheme although I think it is now DrRacket. So i was wondering if you could help me with a homework problem that I can't figure out =\

Write the (max2 x y) operator that evaluates to the larger argument.
Hint: Use these basic arithmetic operators: +,-,/, abs.

Test Cases:

(max2 3 5) -> 5
(max2 5 3) -> 5
(max2 3 3) -> 3
(max2 -2 -3) -> -2
 

Masky

Smash Master
Joined
Dec 16, 2007
Messages
3,665
Code:
(define max2
  (lambda (x y)
    (cond ((> x y) x)
             (else y))))
It's been a long time since I've used Scheme, but I think that's valid

That being said, this is a pretty simple function, so you might want to do some studying... :laugh:
 
Top Bottom