Home > front end >  Why my Racket program does not give me any output?
Why my Racket program does not give me any output?

Time:12-06

I have this code written for converting measurements. However when I run it with command (fce cm mm 5) I don't see any output and any error.

 #lang racket
    (define eq equal?)
    (define (fce jednotka jednotka2 cislo)
    (cond
    ((eq jednotka "mm") (mm cislo jednotka2))
    ((eq jednotka "cm") (cm cislo jednotka2))
    ((eq jednotka "m") (m cislo jednotka2))
    ((eq jednotka "km") (km cislo jednotka2))))
    (define (mm c j)
    (cond
    ((eq j "cm") (format "~a mm = ~a ~a" c (* c 0.1) j))
    ((eq j "m") (format "~a mm = ~a ~a" c (* c 0.001) j))
    ((eq j "km") (format "~a mm = ~a ~a" c (* c 0.000001) j))))
    
    (define (cm c j)
    (cond
    ((eq j "mm") (format "~a mm = ~a ~a" c (* c 0.1) j))
    ((eq j "m") (format "~a mm = ~a ~a" c (* c 0.001) j))
    ((eq j "km") (format "~a mm = ~a ~a" c (* c 0.000001) j))))
    
    (define (m c j)
    (cond
    ((eq j "cm") (format "~a mm = ~a ~a" c (* c 0.1) j))
    ((eq j "mm") (format "~a mm = ~a ~a" c (* c 0.001) j))
    ((eq j "km") (format "~a mm = ~a ~a" c (* c 0.000001) j))))
    
    (define (km c j)
    (cond
    ((eq j "cm") (format "~a mm = ~a ~a" c (* c 0.1) j))
    ((eq j "m") (format "~a mm = ~a ~a" c (* c 0.001) j))
    ((eq j "km") (format "~a mm = ~a ~a" c (* c 0.000001) j))))

CodePudding user response:

You forgot to quote the strings, and you're comparing procedures. You should do this instead:

(fce "cm" "mm" 5)

The logic doesn't look right, though. The above prints:

"5 mm = 0.5 mm"

You need to work out the proper conversions and displayed messages in each of the helper procedures.

  • Related