reset password
Author Message
evik89
Posts: 32
Posted 08:23 Nov 11, 2015 |

I used the same structure from week 3 lecture notes in "A function that uses cond and recursion" instead i used letters for argument.

(define (extreme-secret-number f l v)
  (cond
    ((empty? l) v)
    ((f (game-secret (first l)) v) (extreme-secret-number f (rest l) (game-secret (first l))))
    (else (extreme-secret-number f (rest l) v))))

hal255
Posts: 51
Posted 09:51 Nov 11, 2015 |

Would you be able to remember what f l v is if someone was to spot check you in 3 weeks from now? Other than that, logic is good.

evik89
Posts: 32
Posted 09:52 Nov 11, 2015 |

yes f is either > or <

v is the max or min

and l is the list

rabbott
Posts: 1649
Posted 10:57 Nov 11, 2015 |

l is not a good name for an identifier since it's difficult to tell what it is. On this forum it looks like upper case i.

v is not a good name for the max or min found so far.

You could do better than f for the operator which will be either > or <.

In any event, the function should include comments above it (which you may have) that document what the parameters are.

It's a convention to use square brackets rather than parentheses around each cond clause. That way the clauses stand out and are easier to see. It also helps to avoid parenthesis mistakes. 

 

Last edited by rabbott at 10:57 Nov 11, 2015.