/lispet

a mini lisp

Primary LanguageC

A mini lisp written by C

Errors in the book

Chapter 9

function builtin_op
   if (y->num == 0) {
        lval_del(x); lval_del(y); 
        lval_del(a);//cannot delete a here.
        x = lval_err("Division By Zero!"); break;
      } else {
        x->num /= y->num;
      }

Chapter 12

function lval_copy

case LVAL_FUN:
        if(v->builtin){
            x->builtin = v->builtin; 
        }else {
            x->builtin = v->builtin; //here, we should make sure x->builtin is initialize to 0, otherwise it could be any value so I add this line.
            x->env = lenv_copy(v->env);
            x->formals = lval_copy(v->formals);
            x->body = lval_copy(v->body);
        }
        break;

This bug is fixed in the book, but this bug should be explicitly pointed out. Otherwise, reader will confuse and take times to fix this bug.

Chapter 15 standard library

  • I think (def {curry} {unpack}) should be (def {curry} unpack)
  • “Minimum of Arguments” -> “Maximun of Arguments”

Questions

  • test case + 2 (head {2 4}) cannot eval correctly, because head return a qexpr, which is not number, and not able to caculate. Edit: I can do it this way + 2 (eval (head {2 4})), this could be right.
  • We need to prevent user to def the builtin symbols, like head, user can redefine it like def {head} 1, then we will lose this builtin function.
  • ‘exit’ function, to implement it. We let func envoke even only no argument is needed. I’ve considered (S-expression) as (eval (S-expression)), but this also confuse user. The problem here is that LISPET Couldn’t distinguish “function itself” and “function call without any argument”. This should be done later, otherwise, any function should at least has one argument.