chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] substring function and bounds checks


From: Jim Ursetto
Subject: Re: [Chicken-hackers] substring function and bounds checks
Date: Tue, 5 Feb 2013 18:30:12 -0600

On Feb 5, 2013, at 5:55 PM, Michele La Monaca wrote:

> What I can say... Well, maybe one day I will see the light, in the
> meanwhile I would just have preferred a more useful substring
> function. I really think that the one provided by chicken is simply
> not on par with other languages, sorry.

I'll get Sussman on the phone.

> The semantic of a
> commonly-found substring function "give me at most N chars starting
> from a certain position in the string" is the most useful according
> me.

Well, your Perl example did that, but the Ruby, Python and Chicken
ones all give you chars between START and END, not N chars from START.
So you would have to write some shim code anyway.

So while you're in there, just add a couple 'min' expressions.

(define (substring/n s start n)
  (let* ((start (min start (string-length s)))
         (end (min (string-length s) (+ start n))))
    (substring s start end)))

> To me, this only means more bloated, unreadable code in the best case,
> unfriendly crashes in the worst one.


> (substring/n "ciao" 1 10)
  "iao"

Presto, now your code isn't bloated, and you have up to N
chars from START.

Jim

P.S. He sent me to voicemail.





reply via email to

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