orangeduck/BuildYourOwnLisp

Errata with online text, Chapter 10

Closed this issue · 1 comments

Well I got driven crazy over the last two days trying to find out a bug, and I fixed it and thought other people might benefit from this. I was getting a segmentation fault (core dump) in chapter_10 when trying to read in q_expressions, and on macOS Sierra it doesn't support valgrind and I tried/failed to use gdb (apparently I needed to install it from source, and then had to sign it using Apple's keychain access...went with EC2 instance instead).

The bug was that in lval_read(), not only do you need to add in
if (strstr(t->tag, "qexpr")) { x = lval_qexpr(); },

but you also needed to add

        if (strcmp(t->children[i]->contents, "{") == 0) { continue; }
        if (strcmp(t->children[i]->contents, "}") == 0) { continue; }

Otherwise it can't parse the '{' and '}' correctly.

At least it's in the reference file, which is where I got this :)

and coming fresh from JS, gdb and valgrind sure are barebones...

Thanks for the report. I didn't notice this was missing from the chapter and I've added a short mention.