From 430667bd5e9ec29c6a307aaada259e419713fbc6 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Thu, 24 Oct 2019 21:23:38 +0200 Subject: [PATCH] core: memq: Prepare for M2-Planet. * src/lib.c (memq): Prepare for M2-Planet. --- src/lib.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/lib.c b/src/lib.c index 9dcf6213..8676946a 100644 --- a/src/lib.c +++ b/src/lib.c @@ -128,19 +128,31 @@ memq (SCM x, SCM a) if (t == TCHAR || t == TNUMBER) { long v = VALUE (x); - while (a != cell_nil && v != VALUE (CAR (a))) - a = CDR (a); + while (a != cell_nil) + { + if (v == VALUE (CAR (a))) + return a; + a = CDR (a); + } + return cell_f; } - else if (t == TKEYWORD) + if (t == TKEYWORD) { - while (a != cell_nil && (TYPE (CAR (a)) != TKEYWORD || string_equal_p (x, CAR (a)) == cell_f)) - a = CDR (a); + while (a != cell_nil) + { + if (TYPE (CAR (a)) == TKEYWORD) + if (string_equal_p (x, CAR (a)) == cell_t) + return a; + a = CDR (a); + } + return cell_f; } - else - while (a != cell_nil && x != CAR (a)) + while (a != cell_nil) + { + if (x == CAR (a)) + return a; a = CDR (a); - if (a != cell_nil) - return a; + } return cell_f; }