I've started working on the S-expression printer. Here's my WIP
https://github.com/dannas/bitwise/blob/master/homework/main.c
I'm allocating and concatenating strings all over the place, so it's very ineffective. I guess I should create a tree of nodes instead. How have you done it?
Here's a list of things I've learned from the first couple of streams.
* Ctrl-F10 for running up to a line. I can't believe I've never used that before! Super-useful!
* C99 compound literals and C99 designated initializers. Up until now, I've mostly coded in C++ and C89.
* That expression precedence is often expressed as terms, factors and powers.
* This is silly, but using the word 'factor' for describing how to organize code. I've always heard people talked about 'refactoring' and never really thought about why it was named that way. When I heard Per say 'factor code' I realized that it's analogues to factoring mathematical expressions.
* Stretchy buffers. I hadn't expected that the C code would be this succinct.
* Including c-files for fast factoring of code while developing. Is this something that scales to bigger projects, or is it just used during exploration?
* The general workflow of using the debugger for shaking out bugs early. I've tended to rely on printf statements and only use the debugger when I've hit a bug.
* Using a none-value for enum types to ensure they're initialized to something well defined.
* On a tangent: After learning about stretchy buffers I looked up Sean Barretts original code and found a comment about strict aliasing:
https://github.com/nothings/stb/blob/master/stretchy_buffer.h#L12. So I read up on strict aliasing and learned that there's something called 'effective types' in the C standard and that an aliasing violating really is when we're trying to read through a pointer whos type differs from the effective type of the storage we're reading from. And the effective type can change(!) when we write to the storage. That's what's happening when we get a buffer from malloc that has been previously freed.
I'll stop blabbering now. Thank you Per, for what I've learned (and possibly misunderstood so far).