Re: [eclipse-clp-users] Read integer from user (without a dot)

From: Sergey Dymchenko <kit1980_at_gmail.com>
Date: Wed, 21 Sep 2011 22:28:44 +0300
read_token works for me for my particular problem (only positive
numbers), thanks!

I use http://eclipseclp.org/doc/bips/fullindex.html and I saw
read_token/2 and read_token/3 before, but for some reason I decided
that these predicates can't do what I need.

In a case of signed numbers 3 strings look like a lot for this mundane
task. It can be combined to a custom predicate, but why there is no a
standard utility predicate for this?

Sergey.

On Wed, Sep 21, 2011 at 10:14 PM, Joachim Schimpf <jschimpf_at_coninfer.com> wrote:
> Kish Shen wrote:
>> On 21/09/2011 18:22, Sergey Dymchenko wrote:
>>> Sorry for probably stupid question, but I can't find an answer.
>>>
>>> How to read an integer from user?
>>> read(N) requires user to end input with dot,
>>> read_line(N) returns a string, not an integer...
>>>
>>> Sergey.
>>>
>  >
>> Hi,
>>
>> If you use ECLiPSe's help/1 with the query "help read.", this would give
>> you a list of all builtins whose name has read in it (a predicate that
>> provides the functionality you want is likely to have read as part of
>> its name), including
>>
>> read_token/2 and read_token/3, which is probably what you want - call it
>> with Class set to integer:
>>
>> read_token(stream, X, integer)
>>
>
>
> In Sergey's case, a better choice might be the combination
>
>     read_string(Stream, end_of_line, _, String),
>     number_string(X, String),
>     integer(X)
>
> because (unlike read_token) it handles negative numbers and
> it will fail if there are any junk characters after the number
> (read_token would just leave these unread).
>
>
> -- Joachim
>
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>
Received on Wed Sep 21 2011 - 19:28:51 CEST

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET