Beispiel #1
0
int eval(int addr){
        int res;
    
    if(atomp(addr)){
                if(IS_NUMBER(addr))
                return(addr);
        if(IS_SYMBOL(addr)){
                res = findsym(GET_NAME(addr));
            switch(GET_TAG(res)){
                case NUM:       return(makenum(GET_NUMBER(res)));
                case SYM:       return(GET_BIND(res));
                case LIS:       return(GET_BIND(res));
            }
        }
    }
    else{
    if(HAS_NAME(car(addr),"quote"))
        return(cadr(addr));
    if(subrp(car(addr)))
        return(apply(symname(car(addr)),evlis(cdr(addr))));
    if(fsubrp(car(addr)))
        return(apply(symname(car(addr)),cdr(addr)));
    if(lambdap(car(addr)))
        return(apply(symname(car(addr)),evlis(cdr(addr))));
    }
    return(NIL);
}
Beispiel #2
0
int read(void){
    gettoken();
    switch(stok.type){
        case NUMBER:    return(makenum(atoi(stok.buf)));
        case SYMBOL:    return(makesym(stok.buf));
        case QUOTE:             return(cons(makesym("quote"), cons(read(),makeempty())));
        case LPAREN:    return(readlist());
    }
}
Beispiel #3
0
int read(void){
    gettoken();
    switch(stok.type){
    	case NUMBER:	return(makenum(atoi(stok.buf)));
        case SYMBOL:	return(makesym(stok.buf));
        case QUOTE:		return(cons(makesym("quote"), cons(read(),makeNIL())));
        case LPAREN:	return(readlist());
    }
    error(CANT_READ_ERR,"read",NIL);
}
Beispiel #4
0
int f_minus(int arglist){
        int arg,res;
    
    res = GET_NUMBER(car(arglist));
    while(!(IS_NIL(arglist))){
        arg = GET_NUMBER(car(arglist));
        arglist = cdr(arglist);
        res = res - arg;
    }
    return(makenum(res));
}
Beispiel #5
0
int f_plus(int arglist){
    int arg,res;
    
    checkarg(NUMLIST_TEST, "+", arglist);
    res = 0;
    while(!(IS_NIL(arglist))){
        arg = GET_NUMBER(car(arglist));
        arglist = cdr(arglist);
        res = res + arg;
    }
    return(makenum(res));
}
Beispiel #6
0
int f_length(int arglist){
    checkarg(LEN1_TEST, "length", arglist);
    checkarg(LIST_TEST, "length", car(arglist));
    return(makenum(length(car(arglist))));
}