a.nastaev
2019-3-6 14:22:55

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!


soegaard2
2019-3-6 14:27:54

@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.


soegaard2
2019-3-6 14:28:36

In DrRacket find the menu “Language” then pick the menu item “Choose Language” then find the beginner language.


soegaard2
2019-3-6 14:28:52

Remove the (require ... 2htdp/batch-io) line.


soegaard2
2019-3-6 14:29:25

Then add the teachpack. I think that’s also in the language menu(?)


a.nastaev
2019-3-6 14:31:50

@soegaard2 thank you so much as usual for your help! Let me try it and I will let you know shortly.


a.nastaev
2019-3-6 14:39:02

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!


soegaard2
2019-3-6 14:45:35

Hmm. I see " Now Add (require 2htdp/batch-io) to " in the text.


soegaard2
2019-3-6 14:45:47

Sorry - I remember that exercise from the first edition of the book.


soegaard2
2019-3-6 14:46:14

What happens when you click run?


a.nastaev
2019-3-6 14:47:58

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…


soegaard2
2019-3-6 14:48:19

C is the function that converts a number to Celsius.


soegaard2
2019-3-6 14:48:34

Try (define (C x) (* 2 x)) for now.


a.nastaev
2019-3-6 14:48:35

Aaaaaaa….


a.nastaev
2019-3-6 14:48:40

ok!!!!


soegaard2
2019-3-6 14:48:45

Then later replace it with the correct formula.


a.nastaev
2019-3-6 14:48:51

Yes!!!!


a.nastaev
2019-3-6 14:50:14

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!


soegaard2
2019-3-6 14:53:50

Consider it a rite of passage (learning how to interpret error messages).


a.nastaev
2019-3-6 14:55:56

^^^ that is a great way to think about it! :slightly_smiling_face: Thanks again! Everything works now!


samth
2019-3-6 14:58:36

Which of those parts doesn’t work for you?


a.nastaev
2019-3-6 15:00:57

@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!