Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add append #247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/sexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ SexprRef cdr(SexprRef sexpr) {
assert(sexpr_is_pair(sexpr));
return sexpr->data.cons.cdr;
}
SexprRef append(SexprRef xs, SexprRef ys) {
assert(sexpr_is_null(xs) || sexpr_is_pair(xs));
if (sexpr_is_null(xs)) {
return ys;
} else {
xs->data.cons.cdr = append(cdr(xs), ys);
return xs;
}
}

bool sexpr_is_null(SexprRef sexpr) {
return sexpr == NULL;
Expand Down
1 change: 1 addition & 0 deletions src/sexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct Sexpr {
SexprRef cons(SexprRef car, SexprRef cdr);
SexprRef car(SexprRef sexpr);
SexprRef cdr(SexprRef sexpr);
SexprRef append(SexprRef xs, SexprRef ys);

bool sexpr_is_null(SexprRef sexpr);
bool sexpr_is_pair(SexprRef sexpr);
Expand Down