So I’ve just completed the first challenge from dailyprogrammer. It’s a pretty
easy challenge but that didn’t stop me WTF’ing all the way through.
The challenge itself was simple (embarrasingly simple)
Write a program that will ask the users name, age, and reddit username. Have
it tell them the information back, in the format: your name is (blank), you are
(blank) years old, and your username is (blank)”
Here are the questions I asked myself throughout and the answers that I (think)
- How do I display stuff?
- Use the
- How do I read user input
(read). Note that I think newer schemes actually have something called
(read-line) which casts the user input from a symbol to a string for you
- Why is the variable stored from
(read) not a string?
- As mentioned before, it’s returned as a symbol, you need to convert it
- How can I convert symbols?
(symbol->string) to convert a symbol to a string
- How do I concatenate strings
- What is the scheme filetype extension so I can actually save my work?
- I’m using ‘.scm’ though I could be wrong…
(display "What is your name")
(define name (symbol->string (read)))
(display "What is your age")
(define age (number->string(read)))
(display "What is your username")
(define user (symbol->string(read)))
"Your name is " name
" and you are " age " years old"
" and your username is " user))
Things I enjoyed
I like the naming conventions and consistency of the procedures. You barely
have to look at the documentation because your guess of a procedure name usually
is the procedure name.
For example, I had no idea how to convert a number to a string. I used
and hey presto!