From 7e417a4d9a134e21a8427c264ec15dd442c8d21f Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Sun, 29 Dec 2024 23:03:10 +0900 Subject: [PATCH] Fix --- native/src/list.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/native/src/list.rs b/native/src/list.rs index 0568aa7ea..e23b50a83 100644 --- a/native/src/list.rs +++ b/native/src/list.rs @@ -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; } @@ -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; }