Saturday, April 30, 2011

Racket Bleg - anyone in the house speak LISPish?

Herself is in Chicago visiting friends.  After doing laundry, raking winter trash from the yard, baking bread, washing rugs, watching Groundhog Day (again) ... I ran out of things to do.  So I picked up the tutorial for Racket.

Exercise 2.2.1.  
Define the program Fahrenheit->Celsius, which consumes a temperature measured in Fahrenheit and produces the Celsius equivalent. Use a chemistry or physics book to look up the conversion formula.

'Deduct 32, multiply by 5, divide by 9.'   The code I came up with works but is unsatisfying - I wanted to cram everything into one expression but can't figure out how.  Or if I can.

(define (fah-celd r)
  (* 5( - r 32)))

(define (fah-celf r)
  ( / (fah-celd r) 9))

> (fah-celf 32)
> (fah-celf 40)

Anyone on my short list of internet friends speak LISPish?
blog comments powered by Disqus