Friday, October 27, 2006

hello, world

Just to mark beginning of blog usage, here are my hello-s:


(while t
(message "Hello, all")
(message ""))


def hello_world_generator(msg):
for i in range(0, len(msg)):
yield msg[i]

if __name__ == '__main__':
for char in hello_world_generator('Hello, world'):
print char,

And of course, the C++

#include <string>
#include <algorithm>
#include <iterator>
#include <iostream>

using namespace std;

class hello_world_iterator : public iterator<forward_iterator_tag, char>
static const string msg;
string::const_iterator msg_i;
bool end_;
hello_world_iterator(bool end=false) : msg_i(msg.end()), end_(end) { }

char operator* () const
return (msg_i == msg.end()) ? '\0' : *msg_i;
hello_world_iterator& operator++ ()
if (msg_i == msg.end() && !end_)
msg_i = msg.begin();
if (msg_i == msg.end())
end_ = true;
return *this;

bool operator== (const hello_world_iterator &rhs) const
return msg_i == rhs.msg_i && end_ == rhs.end_;
bool operator!= (const hello_world_iterator &rhs) const
return !(*this == rhs);

const string hello_world_iterator::msg = "Hello, world";

int main(int argc, char* argv[])
copy(hello_world_iterator(), hello_world_iterator(true),
return 0;

(c++ version was written very fast, so sorry, it may contain some flaws).

No comments:

Denis Dzyubenko shadone