I have to create the following:
A Scheme procedure named ‘proc2’ which takes 4 numbers as arguments
and returns the value of the largest argument minus the smallest.
So I want to write
(define proc2
lambda(a b c d)
…
)
Is there any way I can evaluate (> a b), (> a c), (> a d) at the same time? I want to get the largest (and the smallest)number without having to write nested ifs.
Can you use the
maxandminprocedures? if the answer is yes, it’s pretty simple:If not, remember that
<,>,<=,>=accept a variable number of arguments, so this is valid code and will tell you ifais smaller thanbandbis smaller thancandcis smaller thand(although you’ll have to test more combinations ofb,c,dto make sure thatais the smallest value).Also remember to consider the cases when two or more numbers are equal (that’s why it’s a good idea to use
<=instead of<).Anyway, you’ll have to use conditionals. Maybe nested
ifs, or perhaps acondto make things simpler – you can work out the details yourself, I’m guessing this is homework.