guile-devel
[Top][All Lists]
Advanced

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

Re: srfi-1 take and drop seriously broken


From: Jan Synáček
Subject: Re: srfi-1 take and drop seriously broken
Date: Mon, 21 Nov 2016 08:34:07 +0100

On Sun, Nov 20, 2016 at 7:31 PM,  <address@hidden> wrote:
>
> ---- Panicz Maciej Godek <address@hidden> wrote:
>> 2016-11-20 11:42 GMT+01:00 Jan Synáček <address@hidden>:
>>
>> >
>> > >> Please, tell me that this is just a mistake... This can't be true. I
>> > >> still can't believe it. This is from 2.0.11. Please, tell me that the
>> > >> implementation is fixed in 2.2.
>> > >>
>> > >> Yours truly puzzled,
>> > >
>> > >
>> > > I don't know why you find it so puzzling. You can't take or drop
>> > something
>> > > that "isn't there" (you can't take a car or cdr from an empty list as
>> > well,
>> > > although e.g. in the language of "The Little Prover" (car '()) and (cdr
>> > '())
>> > > both evaluate to '() to assure their totality). If you need, you can
>> > define
>> > > your own variants that take/drop at most n elements of list.
>> >
>> > Not only that you "can", it's also IMHO a fool-proof implementation
>> > and I can't see any reason why it should behave differently.
>> >
>>
>> Because someone might think that if he took 7 elements, then he has 7
>> elements, so it is good that he knows earlier that this is not the case. I
>> don't see a point in referring to Haskell documentation when discussing
>> Scheme functions, though (if you try Racket, you'll note that although its
>> take has a reversed order of arguments compared to srfi-1, it still doesn't
>> allow to take or drop a positive number of elements from an empty list)
>>
>> I agree though that the srfi-1 document isn't explicit enough about this
>> point.
>
> Yes.   Srfi-1 ( http://srfi.schemers.org/srfi-1/srfi-1.html ) says that drop
> "is exactly equivalent to performing i cdr operations on x", and notes that 
> for
> car and cdr "it is an error to apply them to the empty list"
>
> Also for take and drop: "For a legal i, take and drop partition the list in a 
> manner which can be inverted with append"
> Implying that not all i are "legal".

Ok. Apart from the fact that it's written in srfi, I wonder what the
reasoning for such behavior is. I mean, what makes the "i" bigger than
the length of the list so illegal that you have to bail out? When is
such behavior useful? On the other hand, not having to worry about the
list length is very useful. Because now my code is littered with
things like

;; Let's hope that string-length is O(1).
(if (>= width (string-length item))
    item
    (string-take item width))

or

(if (string-null? text)
    ""
    (string-drop-right text 1))

Maybe I'm just doing something wrong?

Cheers,
-- 
Jan Synáček



reply via email to

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