[Top][All Lists]

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

Re: (list-head lst k) with k longer than (length lst)

From: Jan Synáček
Subject: Re: (list-head lst k) with k longer than (length lst)
Date: Wed, 18 Nov 2015 09:07:03 +0100

On Tue, Nov 17, 2015 at 10:27 PM, Mark H Weaver <address@hidden> wrote:
> Chris Vine <address@hidden> writes:
>> On Tue, 17 Nov 2015 11:53:05 +0100
>> Jan Synáček <address@hidden> wrote:
>>> Hello,
>>> I'm getting:
>>> scheme@(guile-user)> (list-head '(1 2 3) 5)
>>> ERROR: In procedure list-head:
>>> ERROR: In procedure list-head: Wrong type argument in position 1
>>> (expecting pair): ()
>>> This looks pretty much like a bug to me. Shouldn't list-head return
>>> the entire list when the 'k' is bigger than its length? If that is not
>>> the case, at least the error is really confusing. I'm using Guile
>>> 2.0.11.
>> The error message is confusing, but I guess the behaviour of list-head
>> mirrors R5RS list-tail: instead of mandating the return of an empty
>> list, R5RS states that "It is an error if list has fewer than k
>> elements".
> Exactly right, but I agree that the error message is confusing.
> Unless otherwise specified, Scheme and Guile tend to be strict in cases
> like this.  For example, if a procedure is documented to "Copy the first
> K elements from LST", and says nothing about what happens for lists with
> fewer than K elements, you should assume that it's an error.
>      Mark

Thank you for the explanation.

Jan Synáček

reply via email to

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