@@ -681,11 +681,19 @@ void mark(lisp x) {
681681///--------------------------------------------------------------------------------
682682// Primitives
683683
684+ lisp nullp (lisp a ) { return a ? nil : t ; }
685+ lisp consp (lisp a ) { return IS (a , conss ) ? t : nil ; }
686+ lisp atomp (lisp a ) { return IS (a , conss ) ? nil : t ; }
687+ lisp symbolp (lisp a ) { return IS (a , atom ) ? t : nil ; } // rename struct atom to symbol?
688+ lisp numberp (lisp a ) { return IS (a , intint ) ? t : nil ; } // TODO: extend with float/real
689+ lisp integerp (lisp a ) { return IS (a , intint ) ? t : nil ; }
690+
691+ lisp lessthan (lisp a , lisp b ) { return getint (a ) < getint (b ) ? t : nil ; }
692+
684693lisp plus (lisp a , lisp b ) { return mkint (getint (a ) + getint (b )); }
685694lisp minus (lisp a , lisp b ) { return mkint (getint (a ) - getint (b )); }
686695lisp times (lisp a , lisp b ) { return mkint (getint (a ) * getint (b )); }
687696lisp divide (lisp a , lisp b ) { return mkint (getint (a ) / getint (b )); }
688- lisp lessthan (lisp a , lisp b ) { return getint (a ) < getint (b ) ? t : nil ; }
689697lisp terpri () { printf ("\n" ); return nil ; }
690698lisp eq (lisp a , lisp b ) {
691699 if (a == b ) return t ;
@@ -1125,13 +1133,22 @@ lisp lispinit() {
11251133 SETQc (lambda , LAMBDA );
11261134 SETQ (t , 1 );
11271135 SETQ (nil , nil );
1136+
1137+ PRIM (null ?, 1 , nullp );
1138+ PRIM (cons ?, 1 , consp );
1139+ PRIM (atom ?, 1 , atomp );
1140+ PRIM (symbol ?, 1 , symbolp );
1141+ PRIM (number ?, 1 , numberp );
1142+ PRIM (integer ?, 1 , integerp );
1143+
1144+ PRIM (< , 2 , lessthan );
1145+
11281146 PRIM (+ , 2 , plus );
11291147 PRIM (- , 2 , minus );
11301148 PRIM (* , 2 , times );
11311149 // PRIM("/", 2, divide);
11321150 PRIM (eq , 2 , eq );
11331151 PRIM (= , 2 , eq );
1134- PRIM (< , 2 , lessthan );
11351152 PRIM (if , -3 , iff );
11361153 PRIM (terpri , 0 , terpri );
11371154 PRIM (princ , 1 , princ );
@@ -1141,11 +1158,13 @@ lisp lispinit() {
11411158 PRIM (cdr , 1 , cdrr );
11421159 PRIM (setcar , 2 , setcar );
11431160 PRIM (setcdr , 2 , setcdr );
1161+
1162+ PRIM (list , 16 , _quote );
11441163 PRIM (assoc , 2 , assoc );
11451164 // PRIM(quote, -16, quote);
11461165 // PRIM(list, 16, listlist);
11471166
1148- PRIM (eval , - 1 , eval );
1167+ PRIM (eval , 1 , eval );
11491168 PRIM (evallist , 2 , evallist );
11501169
11511170 PRIM (read , 1 , read );
0 commit comments