Print Function
If we are running programs from the command line we might want them to output some data, rather than just define functions and other values. We can add a print
function to our Lisp which makes use of our existing lval_print
function.
This function prints each argument separated by a space and then prints a newline character to finish. It returns the empty expression.
lval* builtin_print(lenv* e, lval* a) {
/* Print each argument followed by a space */
for (int i = 0; i < a->count; i++) {
lval_print(a->cell[i]); putchar(' ');
}
/* Print a newline and delete arguments */
putchar('\n');
lval_del(a);
return lval_sexpr();
}
当前内容版权归 orangeduck 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 orangeduck .