Beispiel #1
0
object *eval_fn (object *sexp, object *env){
  object *symbol = car(sexp);
  object *args = cdr(sexp);

  if(symbol->type == LAMBDA)
    return fn_lambda(sexp,env);
  else if(symbol->type == FUNC)
    return (((func_object *) (symbol))->fn)(args, env);
  else
    return sexp;
}
Beispiel #2
0
// TODO: defun not acting same as (define x (lambda ...))
atom *fn_defun(env *e, atom *args) {
  atom *name = car(args);
  atom *fn = fn_lambda(e, cdr(args));

  if (atom_len(args) != 3)
    return atom_make(A_ERROR, "wrong number of args passed to defun");
  
  if (car(args)->typ != A_SYMBOL)
    return atom_make(A_ERROR, "first arg must be symbol");

  env_bind(e, name->val, fn);
  return name; 
}
Beispiel #3
0
object *eval_fn(object *sexp, object *env) {
	object *symbol = first(sexp);
	object *args = second(sexp);

	if (symbol->type == LAMBDA) {
		// Return a new lambda based on the symbol and args.
		return fn_lambda(sexp, env);
	}
	else if (symbol->type == FUNC) {
		// return the appropriate C-binding funcobject
		return (((func_object *) (symbol))->fn)(args, env);
	}
	else
		return sexp;
}