mirror of
https://github.com/samsonjs/lake.git
synced 2026-03-27 09:15:49 +00:00
fix cons
This commit is contained in:
parent
6a8a737f57
commit
34ee57d759
1 changed files with 28 additions and 3 deletions
31
src/list.c
31
src/list.c
|
|
@ -45,9 +45,16 @@ LakeList *list_make(void)
|
|||
|
||||
LakeList *list_cons(LakeVal *car, LakeVal *cdr)
|
||||
{
|
||||
LakeList *list = list_make_with_capacity(2);
|
||||
list->vals[0] = car;
|
||||
list->vals[1] = cdr;
|
||||
LakeList *list;
|
||||
if (IS(TYPE_LIST, cdr)) {
|
||||
list = LIST(cdr);
|
||||
list_unshift(list, car);
|
||||
}
|
||||
else {
|
||||
list = list_make_with_capacity(2);
|
||||
list->vals[0] = car;
|
||||
list->vals[1] = cdr;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
@ -129,6 +136,24 @@ LakeVal *list_shift(LakeList *list)
|
|||
return head;
|
||||
}
|
||||
|
||||
LakeVal *list_unshift(LakeList *list, LakeVal *val)
|
||||
{
|
||||
if (list->n == 0) {
|
||||
list_append(list, val);
|
||||
}
|
||||
else {
|
||||
if (list->n >= list->cap) {
|
||||
list_grow(list);
|
||||
}
|
||||
size_t i = list->n++;
|
||||
while (i--) {
|
||||
list->vals[i] = list->vals[i - 1];
|
||||
}
|
||||
list->vals[0] = val;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LakeVal *list_pop(LakeList *list)
|
||||
{
|
||||
LakeVal *tail = NULL;
|
||||
|
|
|
|||
Loading…
Reference in a new issue