[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.
- Re: [Chicken-hackers] substring function and bounds checks, (continued)
- Re: [Chicken-hackers] substring function and bounds checks, Jim Ursetto, 2013/02/05
- Re: [Chicken-hackers] substring function and bounds checks, Michele La Monaca, 2013/02/05
- Re: [Chicken-hackers] substring function and bounds checks,
Jim Ursetto <=
- Re: [Chicken-hackers] substring function and bounds checks, Peter Bex, 2013/02/06
- Re: [Chicken-hackers] substring function and bounds checks, Michele La Monaca, 2013/02/06
- Re: [Chicken-hackers] substring function and bounds checks, John Cowan, 2013/02/06
- Re: [Chicken-hackers] substring function and bounds checks, Peter Bex, 2013/02/06
- Re: [Chicken-hackers] substring function and bounds checks, Alex Shinn, 2013/02/06
- Re: [Chicken-hackers] substring function and bounds checks, Michele La Monaca, 2013/02/07
- Re: [Chicken-hackers] substring function and bounds checks, Alex Shinn, 2013/02/07
- Re: [Chicken-hackers] substring function and bounds checks, Michele La Monaca, 2013/02/07
- Re: [Chicken-hackers] substring function and bounds checks, Alex Shinn, 2013/02/07
- Re: [Chicken-hackers] substring function and bounds checks, John Cowan, 2013/02/07