unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* (list-head lst k) with k longer than (length lst)
@ 2015-11-17 10:53 Jan Synáček
  2015-11-17 13:44 ` Chris Vine
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Synáček @ 2015-11-17 10:53 UTC (permalink / raw)
  To: guile-devel

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.

Cheers,
-- 
Jan Synáček



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: (list-head lst k) with k longer than (length lst)
  2015-11-17 10:53 (list-head lst k) with k longer than (length lst) Jan Synáček
@ 2015-11-17 13:44 ` Chris Vine
  2015-11-17 21:27   ` Mark H Weaver
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Vine @ 2015-11-17 13:44 UTC (permalink / raw)
  To: guile-devel

On Tue, 17 Nov 2015 11:53:05 +0100
Jan Synáček <jan.synacek@gmail.com> 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".

Chris



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: (list-head lst k) with k longer than (length lst)
  2015-11-17 13:44 ` Chris Vine
@ 2015-11-17 21:27   ` Mark H Weaver
  2015-11-18  8:07     ` Jan Synáček
  0 siblings, 1 reply; 4+ messages in thread
From: Mark H Weaver @ 2015-11-17 21:27 UTC (permalink / raw)
  To: Chris Vine; +Cc: guile-devel

Chris Vine <chris@cvine.freeserve.co.uk> writes:

> On Tue, 17 Nov 2015 11:53:05 +0100
> Jan Synáček <jan.synacek@gmail.com> 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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: (list-head lst k) with k longer than (length lst)
  2015-11-17 21:27   ` Mark H Weaver
@ 2015-11-18  8:07     ` Jan Synáček
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Synáček @ 2015-11-18  8:07 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-devel

On Tue, Nov 17, 2015 at 10:27 PM, Mark H Weaver <mhw@netris.org> wrote:
> Chris Vine <chris@cvine.freeserve.co.uk> writes:
>
>> On Tue, 17 Nov 2015 11:53:05 +0100
>> Jan Synáček <jan.synacek@gmail.com> 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



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-11-18  8:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17 10:53 (list-head lst k) with k longer than (length lst) Jan Synáček
2015-11-17 13:44 ` Chris Vine
2015-11-17 21:27   ` Mark H Weaver
2015-11-18  8:07     ` Jan Synáček

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).