2016-11-21 8:34 GMT+01:00 Jan Synáček <jan.syna...@gmail.com>:

>
> 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