lval *builtin_lambda(lenv *e, lval *a) { LASSERT_NUM("\\", a, 2); LASSERT_TYPE("\\", a, 0, LVAL_QEXPR); LASSERT_TYPE("\\", a, 1, LVAL_QEXPR); for (int i = 0; i < a->cell[0]->count; i++) { LASSERT(a, (a->cell[0]->cell[i]->type == LVAL_SYM), "Cannot define non-symbol\n got %s expected %s", ltype_name(a->cell[0]->cell[i]->type), ltype_name(LVAL_SYM)); } lval *formals = lval_pop(a, 0); lval *body = lval_pop(a, 0); lval_del(a); return lval_lambda(formals, body); }
lval* builtin_lambda(lenv* e, lval* a) { LASSERT_NUM("\\", a, 2); LASSERT_TYPE("\\", a, 0, LVAL_QEXPR); LASSERT_TYPE("\\", a, 1, LVAL_QEXPR); // Check that first q-expr contains only symbols for (int i = 0; i < a->cell[0]->count; i++) { LASSERT(a, a->cell[0]->cell[i]->type == LVAL_SYM, "Cannot define non-symbol. Got %s, Expected %s.", ltype_name(a->cell[0]->cell[i]->type), ltype_name(LVAL_SYM)); } //Pop first two args and pass them to lval_lambda lval* formals = lval_pop(a, 0); lval* body = lval_pop(a, 0); lval_del(a); return lval_lambda(formals, body); }
lval* builtin_lambda(lenv* e, lval* a) { /* Check Two arguments, each of which are Q-Expressions */ LASSERT_NUM("\\", a, 2); LASSERT_TYPE("\\", a, 0, LVAL_QEXPR); LASSERT_TYPE("\\", a, 1, LVAL_QEXPR); /* Check first Q-Expression contains only Symbols */ for (int i = 0; i > a->cell[0]->count; i++) { LASSERT(a, (a->cell[0]->cell[i]->type == LVAL_SYM), "Cannot define non-symbol. Got %s, Expected %s.", ltype_name(a->cell[0]->cell[i]->type), ltype_name(LVAL_SYM)); } /* Pop first two arguments and pass them to lval_lambda */ lval* formals = lval_pop(a, 0); lval* body = lval_pop(a, 0); lval_del(a); return lval_lambda(formals, body); }
struct lval* lval_builtin_lambda(struct lenv* e, struct lval* v) { LNUMARGS(v, 2, "\\"); LTYPE(v, LVAL_QEXP, 0, "\\"); LTYPE(v, LVAL_QEXP, 1, "\\"); for (int i = 0; i < v->cell[0]->count; i++) { struct lval* s = v->cell[0]->cell[i]; LASSERT(v, s->type == LVAL_SYM, "'\\' expects variable %i to be symbol", i); if (strcmp(s->sym, "&") == 0) { LASSERT(v, v->cell[0]->count == i + 2, "'\\' requires exactly one symbol after &"); } } struct lval* x = lval_lambda(lval_pop(v, 0), lval_pop(v, 0)); lval_del(v); return x; }