Mailing List ArchiveSupport open source code!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]java question
- To: B0Ti <9915104t@example.com>
- Subject: java question
- From: "Stephen J. Turnbull" <turnbull@example.com>
- Date: Thu, 14 Jun 2001 13:32:55 +0900
- Cc: tlug <tlug@example.com>
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=us-ascii
- In-Reply-To: <3B278493.388731B4@example.com>
- References: <3B278493.388731B4@example.com>
- Reply-To: tlug@example.com
- Resent-From: tlug@example.com
- Resent-Message-ID: <zEHywC.A.oZH.G8DK7@example.com>
- Resent-Sender: tlug-request@example.com
B0Ti> Maybe it's trivial, but I cannot find a clean solution to B0Ti> this. I need to read in an integer and it must be within a B0Ti> limit. Something like this: try { int someInt = Integer.parseInt(readUserInput()); if (someInt > 10 || someInt < 0) throw new NumberFormatException; } catch (NumberFormatException) { /* goto begin :( ...*/ } B0Ti> How should this be done cleanly and effectively? Recursively. This is why functional programming rules. In Lisp it looks like this: (defun integer-mung () (let ((i (read))) (if (and (> i 10) (< i 0)) ; check range (integer-mung) (throw 'value i)))) (catch 'value (integer-mung)) (In Scheme this would be detected as tail-recursive, and executed as a loop as efficient as could be hand-coded within the restrictions of Scheme, using no extra stack space.) The same strategy should work (I don't know Java syntax anymore, sorry) but it may not be possible to do this efficiently in Java without a loop. In Lisp exceptions are not inefficient because of the need to maintain closures all the time anyway. OTOH, no matter how inefficient Java exceptions are, a human user will never notice the time lag. -- University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN Institute of Policy and Planning Sciences Tel/fax: +81 (298) 53-5091 _________________ _________________ _________________ _________________ What are those straight lines for? "XEmacs rules."
- References:
- java question
- From: B0Ti <9915104t@example.com>
Home | Main Index | Thread Index
- Prev by Date: Re: selecting DB on linux
- Next by Date: Re: Nomikai attendance list
- Prev by thread: Re: java question
- Next by thread: Re: java question
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links