blob: 9d6a6bc7bf52cbfd051c0b953ebfe756dc9db4b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
const value = @import("../value.zig");
const Value = value.Value;
pub fn reverse(list: Value) Value {
return reverseWithTail(list, value.nil.nil);
}
pub fn reverseWithTail(list: Value, tail: Value) Value {
var head = list;
var result = tail;
while (!value.nil.check(head)) {
value.pair.assert(head);
const car = value.pair.car(head);
const cdr = value.pair.cdr(head);
result = value.pair.cons(car, result);
head = cdr;
}
return result;
}
|