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.
_______________________________________________
Chicken-hackers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-hackers