cons
OBJECT OBJECT -> LIST
引数の2つの値をくっつけてリストにする関数
code: alloc.c
DEFUN ("cons", Fcons, Scons, 2, 2, 0,
doc: /* Create a new cons, give it CAR and CDR as components, and return it. */)
(Lisp_Object car, Lisp_Object cdr)
{
register Lisp_Object val;
MALLOC_BLOCK_INPUT;
if (cons_free_list)
{
XSETCONS (val, cons_free_list);
cons_free_list = cons_free_list->u.s.u.chain;
}
else
{
if (cons_block_index == CONS_BLOCK_SIZE)
{
struct cons_block *new
= lisp_align_malloc (sizeof *new, MEM_TYPE_CONS);
memset (new->gcmarkbits, 0, sizeof new->gcmarkbits);
new->next = cons_block;
cons_block = new;
cons_block_index = 0;
}
cons_block_index++;
}
MALLOC_UNBLOCK_INPUT;
XSETCAR (val, car);
XSETCDR (val, cdr);
eassert (!XCONS_MARKED_P (XCONS (val)));
consing_until_gc -= sizeof (struct Lisp_Cons);
cons_cells_consed++;
return val;
}
code: example.el
(cons 1 2)
;; => (1 . 2)
(cons 1 '(2))
;; => (1 2) ;; (1 . (2 . nil)
(cons 1 ())
;; => (1) ;; (1 . nil)
(cons 1 nil)
;; => (1) ;; (1 . nil)