Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe committed Dec 29, 2024
1 parent b1b18a2 commit 7e417a4
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions native/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@ impl PrimitiveSet for ListPrimitiveSet {

fn operate(&mut self, memory: &mut Memory, primitive: usize) -> Result<(), Self::Error> {
match primitive {
ListPrimitive::CONS => {
let [car, cdr] = memory.pop_many();

let rib = memory.allocate(car, cdr.set_tag(Type::Pair as _))?;
memory.push(rib.into())?;
}
ListPrimitive::MEMQ => {
ListPrimitive::ASSQ => {
let [x, xs] = memory.pop_many();
let mut xs = xs.assume_cons();
let mut y = memory.boolean(false);

while xs != memory.null() {
if x == memory.car(xs) {
y = xs;
let cons = memory.car(xs).assume_cons();

if x == memory.car(cons) {
y = cons;
break;
}

Expand All @@ -54,16 +50,20 @@ impl PrimitiveSet for ListPrimitiveSet {

memory.push(y.into())?;
}
ListPrimitive::ASSQ => {
ListPrimitive::CONS => {
let [car, cdr] = memory.pop_many();

let rib = memory.allocate(car, cdr.set_tag(Type::Pair as _))?;
memory.push(rib.into())?;
}
ListPrimitive::MEMQ => {
let [x, xs] = memory.pop_many();
let mut xs = xs.assume_cons();
let mut y = memory.boolean(false);

while xs != memory.null() {
let cons = memory.car(xs).assume_cons();

if x == memory.car(cons) {
y = cons;
if x == memory.car(xs) {
y = xs;
break;
}

Expand Down

0 comments on commit 7e417a4

Please sign in to comment.