First step towards dart !!!!

104 views
Skip to first unread message

Shivam Tiwari

unread,
Jun 20, 2012, 5:19:08 AM6/20/12
to mi...@dartlang.org
printf in c = print in dart
but scanf = ? 

Sorry for the dumbness but I really can't find it !!
Is there some document which lists all functions and their usage ??

Rico Wind

unread,
Jun 20, 2012, 5:33:00 AM6/20/12
to Shivam Tiwari, mi...@dartlang.org
I assume you are doing server side programming here (otherwise the
question does not make a lot of sense.

You can use the stdin InputStream to get what you need, e.g.,
#import("dart:io");
void main() {
StringInputStream stdinStream = new StringInputStream(stdin);
stdinStream.onLine = () {
print("You wrote ${stdinStream.readLine()}");
};
}

Or do whatever you need with the InputStream

Cheers,
Rico

Sam McCall

unread,
Jun 20, 2012, 5:33:30 AM6/20/12
to Shivam Tiwari, mi...@dartlang.org
On Wed, Jun 20, 2012 at 11:19 AM, Shivam Tiwari <shivamti...@gmail.com> wrote:
printf in c = print in dart
but scanf = ? 
You can read from standard input using the 'stdin' stream in the 'dart:io' library.
It's non-blocking and asynchronous though, and I don't understand it very well myself.

Dart doesn't really have scanf/printf equivalent functionality facilities yet; you'll need to tokenize the input yourself (RegExp may be helpful here), and then convert appropriately (e.g. Math.parseInt/parseDouble).
 
Sorry for the dumbness but I really can't find it !!
Is there some document which lists all functions and their usage ??

Yep, the docs are at http://api.dartlang.org

Peter Ahé

unread,
Jun 20, 2012, 7:59:17 AM6/20/12
to Sam McCall, Shivam Tiwari, mi...@dartlang.org
Hi Shivam,

Welcome to Dart!

On Wed, Jun 20, 2012 at 11:33 AM, Sam McCall <samm...@google.com> wrote:
> Dart doesn't really have scanf/printf equivalent functionality facilities
> yet; you'll need to tokenize the input yourself (RegExp may be helpful
> here), and then convert appropriately (e.g. Math.parseInt/parseDouble).

If you think that Dart should have something equivalent to scanf,
please file a bug here: http://dartbug.com/new.

Cheers,
Peter

Sam McCall

unread,
Jun 20, 2012, 8:15:04 AM6/20/12
to Peter Ahé, Shivam Tiwari, mi...@dartlang.org
I don't actually - I like the regexes better (I wish Dart had something like Ruby's string#scan, but it doesn't really work without varargs).
For anyone interested, the relevant printf bug is http://code.google.com/p/dart/issues/detail?id=1694

Cheers,
Sam

Lasse R.H. Nielsen

unread,
Jun 21, 2012, 1:46:08 AM6/21/12
to Sam McCall, Peter Ahé, Shivam Tiwari, mi...@dartlang.org
On Wed, Jun 20, 2012 at 2:15 PM, Sam McCall <samm...@google.com> wrote:
> On Wed, Jun 20, 2012 at 1:59 PM, Peter Ahé <a...@google.com> wrote:
>>
>> Hi Shivam,
>>
>> Welcome to Dart!
>>
>> On Wed, Jun 20, 2012 at 11:33 AM, Sam McCall <samm...@google.com> wrote:
>> > Dart doesn't really have scanf/printf equivalent functionality
>> > facilities
>> > yet; you'll need to tokenize the input yourself (RegExp may be helpful
>> > here), and then convert appropriately (e.g. Math.parseInt/parseDouble).
>>
>> If you think that Dart should have something equivalent to scanf,
>> please file a bug here: http://dartbug.com/new.
>
> I don't actually -

I agree. Some kind of pattern-matching and field extraction on strings
would be great, but scanf just isn't very good at it.
It's too low-level for its own good.

> I like the regexes better

... hmm, I don't really. Using pure regexes feels like coding
assembler, and while I'm pretty decent at both, but I still don't
consider it the most productive way to slice a string.
It should be possible to make a better pattern matching framework than
just using plain regexes.

/L
--
Lasse R.H. Nielsen
l...@google.com
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K -
Denmark - CVR nr. 28 86 69 84
Reply all
Reply to author
Forward
0 new messages