* Jim Ursetto <[email protected]> [130314 08:13]:
> Nice catch.  Actually, it might be better rewritten with (##sys#check-list 
> lst 'alist-update), although that is not that important.
> 
> Related, alist-update! behaves weird but doesn't crash on non-alists:
> 
> (alist-update! 'foo 'bar 3)
> ;=> ((foo . bar) . 3)
> 
> And it's inconsistent when you give it a comparator:
> 
> ;; this uses assoc
> (alist-update! 'foo 'bar '((a . b) 3 (c . d)) equal?)
> Error: (assoc) bad argument type: 3
> 
> ;; this uses an assoc-like loop which does not check for lists 
> (alist-update! 'foo 'bar '((a . b) 3 (c . d)) (cut equal? <> <>))
> ;=> ((foo . bar) (a . b) 3 (c . d))
> 

I propose the following patch, which checks the argument for both
procedures with the usual ##sys#check...

Kind regards,

Christian

-- 
In the world, there is nothing more submissive and weak than
water. Yet for attacking that which is hard and strong, nothing can
surpass it. --- Lao Tzu
>From f4d89b1c2984e5af94a26835e0be32dd15c03eae Mon Sep 17 00:00:00 2001
From: Florian Zumbiehl <[email protected]>
Date: Thu, 14 Mar 2013 05:43:46 +0100
Subject: [PATCH] alist-update: don't segfault on non-list

Check the lst argument for alist-update and alist-update! to be an
actual list.

Signed-off-by: Christian Kellermann <[email protected]>
---
 data-structures.scm |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/data-structures.scm b/data-structures.scm
index 56944ec..36f4dbf 100644
--- a/data-structures.scm
+++ b/data-structures.scm
@@ -198,6 +198,7 @@
 ;;; Alists:
 
 (define (alist-update! x y lst #!optional (cmp eqv?))
+  (##sys#check-list lst 'alist-update!)
   (let* ([aq (cond [(eq? eq? cmp) assq]
                   [(eq? eqv? cmp) assv]
                   [(eq? equal? cmp) assoc]
@@ -217,6 +218,7 @@
        (cons (cons x y) lst) ) ) )
 
 (define (alist-update k v lst #!optional (cmp eqv?))
+  (##sys#check-list lst 'alist-update)
   (let loop ((lst lst))
     (if (null? lst)
         (list (cons k v))
-- 
1.7.6

_______________________________________________
Chicken-hackers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to