[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-hackers] substring function and bounds checks
From: |
Michele La Monaca |
Subject: |
Re: [Chicken-hackers] substring function and bounds checks |
Date: |
Thu, 7 Feb 2013 19:20:09 +0100 |
On Wed, Feb 6, 2013 at 12:47 AM, Felix
<address@hidden> wrote:
>> # perl -e 'print substr("ciao",0,10);'
>> ciao
>> # ruby -e 'puts "ciao"[0..10]'
>> ciao
>> # python -c 'print "ciao"[0:10];'
>> ciao
>> # csi -e '(print (substring "ciao" 0 10))'
>> Error: (substring) out of range 0 10
>>
>> Call history:
>>
>> <syntax> (print (substring "ciao" 0 10))
>> <syntax> (substring "ciao" 0 10)
>> <eval> (print (substring "ciao" 0 10))
>> <eval> (substring "ciao" 0 10) <--
>>
>
> The string is shorter than the limit you gave to "substring"
> in the third argument. Of course you know that, but why did
> you pass an incorrect length in the first place?
>
> This looks like it does what you want:
>
> csi -e '(print (substring "ciao" 0))'
Well, no. I was looking for a python-like substring function. Anyway,
thanks for the (substring "ciao" 0) trick, it is a very handy method
to trim strings on the left (not documented in the wiki, btw):
(substring "ciao" 1) => "iao"
In my ideal world, there would room also for that:
(substring "ciao" 0 -1) => "cia"
but I know, I know... it will never happen :-(
Regards,
Michele
Re: [Chicken-hackers] substring function and bounds checks, Moritz Heidkamp, 2013/02/05
Re: [Chicken-hackers] substring function and bounds checks, Felix, 2013/02/05
- Re: [Chicken-hackers] substring function and bounds checks,
Michele La Monaca <=
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, 2013/02/05
- 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