chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] PATCH: wrong type for alist-delete!


From: Peter Bex
Subject: Re: [Chicken-hackers] PATCH: wrong type for alist-delete!
Date: Thu, 14 Jan 2016 21:32:40 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Jan 15, 2016 at 09:00:54AM +1300, Evan Hanson wrote:
> On 2016-01-14 15:14, Jörg F. Wittenberger wrote:
> > the srfi document wants a different type for alist-delete! than types.db
> > declares.
> > 
> > Patch attached.
> 
> Looks good to me. Debatably it ought to have an undefined return value,
> as with typical destructive update procedures, but hey.

Not for SRFI-1, where the return value should be the same as the
non-destructive variant:

"alist-delete! is the linear-update variant of alist-delete. It is
 allowed, but not required, to alter cons cells from the alist parameter
 to construct the result."

But more to the point, isn't this type wrong?  (which would then
technically be wrong for _all_ the alist procedures)

> (alist-delete! (forall (a b) (#(procedure #:enforce) alist-delete! (a 
> (list-of b) #!optional (procedure (a b) *)) list)))

If I have an alist '((1 . x) (2.0 . y) (foo . 3)), then the type is
"(list-of pair)", and you can't get any more precise than that I think.
The types of the keys are mixed, which is somewhat weird but it's allowed
in an alist.

Anyway, in the above type signature, if the list is of type (list-of pair),
then "b" is "pair".  However, the procedure receives (a b) as arguments.
That's incorrect: it wouldn't receive the PAIRS in the list, but the
KEYS (so alternating, a fixnum, flonum and symbol).

Usually you'd pass a comparison procedure that accepts only keys of the
same type, but as you can see above that's not necessarily the case (this
example works fine if we use EQUAL? as the procedure).

I'm not 100% sure what the type should be though.  Perhaps something like
this?

(alist-delete! (forall (a b) (#(procedure #:enforce) alist-delete! (a (list-of 
pair) #!optional (procedure (a b) *)) (list-of pair))))

I kept the b in there to indicate that the comparison procedure doesn't
necessarily receive two arguments of the same type.

Thoughts?

Cheers,
Peter

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]