FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

streams

 
Post new topic   Reply to topic     Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
egon



Joined: 16 May 2004
Posts: 1

PostPosted: Sun May 16, 2004 8:26 am    Post subject: streams Reply with quote

Hi
I didn't find any examples of stdin and stdout streams so I made one.
Please be free to do whatever you want with it Smile

/Egon
Back to top
View user's profile Send private message
qbert



Joined: 30 Mar 2004
Posts: 209
Location: Dallas, Texas

PostPosted: Sun May 16, 2004 10:44 am    Post subject: Reply with quote

Cool!

Im confused though , how the hell does this work

// Convert to upper and print it
output = input.toupper();

??

In std.string toupper is defined as

char[] toupper(char[] s)

After some playing around it looks like all of std.string's functions act as methods on char [] ?!?

It wasn't always this way was it ??

I tried doing this with other objects

Code:

class xyz { }

char [] convert( xyz a ) {
   return xyz.classinfo.name;
}

int main () {
   xyz Z;
   stdout.writeLine(Z.convert () );
   return 1;
}


But it didnt take Sad , that would be super cool though.

Charlie
Back to top
View user's profile Send private message MSN Messenger
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Sun May 16, 2004 11:57 am    Post subject: Re: streams example Reply with quote

egon wrote:
I didn't find any examples of stdin and stdout streams so I made one.
Thanks. It's a keeper.

Also, I can't figure out how
Code:
 output = input.toupper();
works. Perhaps, Walter has been sneaking in undocumented string properties. Did you just guess this would work, or did you see some other code that uses this?
Back to top
View user's profile Send private message AIM Address
qbert



Joined: 30 Mar 2004
Posts: 209
Location: Dallas, Texas

PostPosted: Sun May 16, 2004 4:31 pm    Post subject: Reply with quote

Yes I guess he did, it seems that for all functions expecting char [] as its first argument can be used this way, like stuff in std.conv , std.path , even user defined functions

Code:


char [] something(char [] x ) {
   return x ~ " manipulated";
}

int main()
{
    char[] input;
    char[] output;

    input = "Something";
    stdout.writeLine( input.something() );

    return 0;
}



Its cool!
Back to top
View user's profile Send private message MSN Messenger
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Sun May 16, 2004 5:15 pm    Post subject: Reply with quote

This is pretty cool. I wonder exactly how it works. It doesn't seem to work for int (yet?).
Code:
char[] alwaysWhatever(char[] c) {
    return "alwaysWhatever" ~ c;
}

int squareit(int i) {
    return i * i;
}

void main() {
    char[] d = "Hi";
    int i = 9;

    /* works */
    printf("?.*s\n", d.alwaysWhatever());

    /* doesn't work... */
    //printf("?.*s\t?d\n", d.alwaysWhatever(), i.squareit());
}
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group