'Build Your Own Lisp' Solutions: 4.9

Q: If _WIN32 is defined on windows, what is defined for Linux or Mac?

A: __linux__, and __APPLE__, not to mention __ANDROID__ (which is a type of __linux__, so something like __linux__ && !__ANDROID__ is possible).

'Build Your Own Lisp' Solutions: 4.8

Q: What does the preprocessor command #define do?

A: It creates a macro, which is to say, it let's you associate a word with an expression. Before compiling your code, the precompiler will replace every instance of that word with that expression. While most macros you see are quite simple, you can do pretty amazing things with them. See here for a detailed reference.

'Build Your Own Lisp' Solutions: 4.7

Q: What does the preprocessor command #ifndef do?

A: Checks if a token has already been defined earlier in the file, or in a previous file, then includes anything between it and #else or #endif.

'Build Your Own Lisp' Solutions: 4.6

Q: What happens when you pass printf a variable that does not match the pattern?


#include <stdio.h>

int main(void)
  // This depends heavily on the kind of mistake you want to make. Some 
  // examples:

  // A character is really a number, so this is fine.
  printf("%c\n", 109);
  // And vice-versa.
  printf("%d\n", 'm');
  // A string really just points to the memory address of the first character,
  // and %d will try to interpret that address as a base ten number, so this
  // will be something different every time you run the program.
  printf("%d\n", "moo");

  // These examples all happen to give you something, but the compiler has no 
  // idea what to do with something like 'printf("%s\n", 13);', and will give 
  // you a Segment Fault error.

  return 0;
> ./wrong 

'Build Your Own Lisp' Solutions: 4.5

Q: What other patterns can be used with printf?

A: More than are worth memorizing (at least all at once). As the chapter states, it's best to check a good reference.

19-04-21 Weekly Links
	(DESC "brown sack")
"On the table is an elongated brown sack, smelling of hot peppers.")
	(SIZE 9)

'Build Your Own Lisp' Solutions: 4.4

Q: What does the \n mean in those strings?

A: '\n' signifies a newline character, so the startup information doesn't appear on the same line as the first prompt.

'Build Your Own Lisp' Solutions: 4.3

Q: Add an extra message to the Version and Exit Information.


int main(int argc, char** argv) {

  puts("Lispy Version, Something Something Something");
  puts("Press Ctrl+c to Exit. Happy Trails!\n");

  while (1) {

    /* Now in either case readline will be correctly defined */
    char* input = readline("lispy> ");

    printf("No you're a %s\n", input);


  return 0;

'Build Your Own Lisp' Solutions: 4.2

Q: Change what is echoed back to the user.


  while (1) {
    /* Now in either case readline will be correctly defined */
    char* input = readline("something of my choice> ");

    printf("%s\n", input);