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: Panicz Maciej Godek
Subject: Re: srfi-1 take and drop seriously broken
Date: Mon, 21 Nov 2016 11:21:24 +0100



2016-11-21 8:34 GMT+01:00 Jan Synáček <address@hidden>:

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?

The variants of take and drop that you'd like to have would need
to perform additional checks in order to find out whether the object
that you are trying to drop or take is a pair.
When it comes to your code, it's really hard to say if you're doing
something wrong or not, because it doesn't say why you're doing
what you're doing. But in the case of string operations it is often more
convenient to use regular expressions. (However, I admit that I rarely
have the need to use take-upto and drop-upto functions. I ofen use
the split-at function, and I really appreciate that it throws an error
when invoked with an index that lies beyond a given list; otherwise, I'd
have to worry about silent errors that could appear in my code.
Likewise, you could have (car '()) and (cdr '()) return an empty list,
which would make your code "fool proof", but I don't think it would
have good implications in the long run. Anyway, even Haskell's head
and tail don't work like that)


reply via email to

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