[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-dev] Empty string .asInteger returns 0
- To: sc-dev <sc-dev@xxxxxxxxxxxxxxxx>
- Subject: Re: [sc-dev] Empty string .asInteger returns 0
- From: James Harkins <jamshark70@xxxxxxxxx>
- Date: Sun, 29 Dec 2013 20:31:56 +0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=G6fHkXrV0UmyojaThHydAXYHc3sGxCmcXJMCZoqWlhQ=; b=sm6DHxDun3dV8uoSWymScEUyKoDk1+u9tTWh36vVLGHzSruFCpcmgitRYumu7JAmDV 5LftC2VlRWW3xX5LsFEqfsHQlimRDJp7f3TlbD119NkTAWmPt7jMbP1yGear9iAd15R6 eDghiChiR9skjVtr64HHaFR3qoFiJXTwmY3aJyMlxB2aGQwUfW7KEwnQ/9usl77ehb09 dtqHTKw3otC/hooiytVtpUsHY1QQZP2w0IeTDlvrIHd609i5h0oNk4zs/XmIZMwTybfj YVeMVf0uIrEjE3zq0v7cVPwzEy92I+xEczywRNO/4wzoJ3ldmCTTB+oajcE85wMcyNik hiYQ==
- In-reply-to: <CAMEj9eu2QTKU8jAGbxS=GcbNihgGfzYYpeq3z4JDT28KaqAA2w@mail.gmail.com>
- List-id: SuperCollider developers mailing list <sc-devel.create.ucsb.edu>
- References: <CAMEj9eu2QTKU8jAGbxS=GcbNihgGfzYYpeq3z4JDT28KaqAA2w@mail.gmail.com>
- Reply-to: sc-dev@xxxxxxxxxxxxxxxx
- Sender: owner-sc-dev@xxxxxxxxxxxxxxxx
On Dec 29, 2013 7:45 PM, "Eirik Arthur Blekesaune" <eirik.blekesaune@xxxxxxxxx> wrote:
>
> Why does "".asInteger return 0? Wouldn't it be more correct to return nil?
> Same goes for "".asInt btw?
I think, if you're converting a string to an integer, you should get an integer back. Nil isn't an integer, so...
The precedent is the atoi() function in C:
http://www.cplusplus.com/reference/cstdlib/atoi/
"If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed and zero is returned."
hjh