Keep It Simple, Shauna (Recurse Day 4)
Originally at https://notes.shaunagm.net/post/643491351556653056/keep-it-simple-shauna-recurse-day-4
Today I finally tackled making a code madlibs program.
I spent the morning, though, reading the rest of the Fear of Macros tutorial. And perhaps I shouldn’t have - while it was engaging reading and I felt like I learned something, I spent much of the afternoon mired in confusion from trying to apply more advanced concepts/syntax than I really needed. This is more or less the same problem I had on Tuesday. I think it’s tempting when you run into a problem, especially in a new language, to think “oh! I don’t know enough! I need to learn more and then do more!” but sometimes you do already know enough. Except when you don’t. ;)
I’ve put the final working code in a gist again. It’s not all that different from the story version of madlibs so far. The main difference is that we can’t just throw whatever we get back from the user into one long string of text. It needs to be converted into a number, an operator, etc.
Tomorrow, I’d like to add a few more code elements for the user to potentially specify - I’d like for this to be more than just mathlibs. On the other hand, it seems fairly tedious to define a function to convert all of these code elements like I did with “string->procedure”. Perhaps I’ll investigate if there’s a more Lispish way to do it. I couldn’t find anything today, but I didn’t google very hard.
Another thing I might do is see if I can’t print the full operation for the user, so they can see the steps as well as the result.
Finally, it might be worth it to spend some time making this code robust. The code errors if the user gives it anything invalid.