Hey guys, I have a question regarding htdp2e book. So, I’m at 2.5 Programs
, more specifically - Batch Programs
: https://htdp.org/2018-01-06/Book/part_one.html#%28part._sec~3aprogs%29
Everything is clear here regarding a function itself to convert F => C, write-file
and read-file
along with 'stdout
and 'stdin
.
My question: is everything in this part right until Exercise 31
basically a concept without a real implementation? Or there is a way to connect everything together and make it work through DrRacket GUI?
When I’m trying to run a program from the file it is not working: (require 2htdp/batch-io)
(define (convert in out)
(write-file out
(string-append
(number->string
(C
(string->number
(read-file in))))
"\n")))
(write-file "sample.dat" "212")
;> (write-file "sample.dat" "212") ; to create an input file for convert
;"sample.dat"
;(convert "sample.dat" 'stdout) ; use 'stdout to view what convert outputs
;100
;'stdout
;> (convert "sample.dat" "out.dat") ; Fahrenheit temperature deposited in the file
;"out.dat"
;> (read-file "out.dat") ; read the content of "out.dat" file
;"100"
I’m sure I’m missing something!
I appreciate any possible help.
Thanks in advance!
@a.nastaev In this exercise the intension is to use one of the teaching languages (the beginner one I think) and a the batch teach pack.
In DrRacket find the menu “Language” then pick the menu item “Choose Language” then find the beginner language.
Remove the (require ... 2htdp/batch-io)
line.
Then add the teachpack. I think that’s also in the language menu(?)
@soegaard2 thank you so much as usual for your help! Let me try it and I will let you know shortly.
ok, I’ve installed Teachpack: batch-io.rkt
. But how can I run that batch program? Where the formula’s function should be: (define (convert in out)
(write-file out
(string-append
(number->string
(C
(string->number
(read-file in))))
"\n")))
in data.dat
file? I guess - not, since it is our input. Thanks again for all your help!
Hmm. I see " Now Add (require 2htdp/batch-io) to " in the text.
Sorry - I remember that exercise from the first edition of the book.
What happens when you click run?
Yes, I’ve already added (require 2htdp/batch-io)
, same error: C: this function is not defined
which is make sense. That is why I confused…
C is the function that converts a number to Celsius.
Try (define (C x) (* 2 x))
for now.
Aaaaaaa….
ok!!!!
Then later replace it with the correct formula.
Yes!!!!
I’m dumb!!!! I’m always repeating myself to read all the error messages carefully and think about them… Thank you so much! Appreciate your help!
Consider it a rite of passage (learning how to interpret error messages).
^^^ that is a great way to think about it! :slightly_smiling_face: Thanks again! Everything works now!
Which of those parts doesn’t work for you?
@samth everything works now! I didn’t add Teachpack: batch-io.rkt
and forgot to supply the file with the actual formula to convert F to C. But thanks a lot for trying to help here! I appreciate it!