C++ code into Ruby, I need it fast, no time for RTFM

Andrei Ursan wrote:

Sammy Larbi wrote:

Andrei Ursan wrote, On 4/25/2007 4:29 AM:

Can somebody translate this into ruby ? I need it fast...

I don't mean to be rude, but I'm with most of the others on this. I
found it amusing (is that mean of me?) that you have no time to RTFM,
but you have time to wait longer than it would have taken to RTFM for
someone to answer. You don't need an entire book for loops and printing
strings. Thats page one stuff in any language, I would think.

No, i did rftm and i'm doing it even now :)) :stuck_out_tongue:
It's ok... I'm fine, don't need to worry 4 me, btw if u have some good ruby doc pleas links gimme to me i'm ruby doc hungry.

Welcome to Ruby, Andrei.

A Ruby book like no other can be found at

http://poignantguide.net/ruby/

HTH,

Michael

···

--
Michael Ulm
R&D Team
ISIS Information Systems Austria
tel: +43 2236 27551-542, fax: +43 2236 21081
e-mail: michael.ulm@isis-papyrus.com
Visit our Website: www.isis-papyrus.com

---------------------------------------------------------------
This e-mail is only intended for the recipient and not legally
binding. Unauthorised use, publication, reproduction or
disclosure of the content of this e-mail is not permitted.
This email has been checked for known viruses, but ISIS accepts
no responsibility for malicious or inappropriate content.
---------------------------------------------------------------

Hi Andrei...i went pretty much through the ring-a-mole my self once...one
good link for ruby is RDoc Documentation and
Ruby | zenspider.com | by ryan davis
for quick ruby ref...atleast i found so...enjoying RUBYing...

-ciao
AG

···

On 4/26/07, bpfurtado <bpfurtado@gmail.com> wrote:

On Apr 25, 11:54 am, "Tim Pease" <tim.pe...@gmail.com> wrote:
> On 4/25/07, Andrei Ursan <steelheart...@gmail.com> wrote:
>
> > Strings value are read from the keyboard, and i need a getch and
clrscr
> > method.
> > And how can I export the ruby code into *.exe ?
>
> > Can somebody translate this into ruby ? I need it fast...
>
> Have you gotten a suitable answer yet?
>
> There are several options for you here.
> 1) Transliterate into Ruby (as you imply)
> 2) Leave your code as-is and wrapper it using Ruby's C api
> 3) Leave your code as-is and use the Ruby DL module to load your
> library and invoke the methods
> 4) Use the RubyInline module to simply "inline" your C/C++ code into a
> Ruby program
>
> By far the quickest solution is going to be the RubyInline route.
> You'll need a compiler installed on your machine to handle the C++
> code compilation step RubyInline performs. You can install RubyInline
> via the gem command:
>
> gem install -r rubyinline
>
> Shoot a nice note of thanks off to Eric Hodel and Ryan Davis. They've
> done a great job with that little gem.
>

> Have fun learning Ruby! I've learned far more about programming by
> using Ruby than I ever learned using C/C++ or Java.
>

You can´t blame C/C++ or Java or any programming language for your
learning skills.

--
"Minds are like parachutes, they work best when open."
"I know nothing except the fact of my ignorance."
Bruno Patini Furtado
Software Developer
text adventures suite: http://bpfurtado.net/tas
software development blog: http://bpfurtado.livejournal.com
Ruby related topics: http://bpfurtado.livejournal.com/tag/ruby

The magic behind RubyInline is the rbconfig.rb file. This little Ruby
script contains the build environment used to compile the Ruby
interpreter for your particular platform. When RubyInline compiles
code, it uses the build environment found in rbconfig.rb.

So, the catch is that your machine environment
(compilers/libraries/etc) needs to agree with what is in rbconfig.rb.

For my Ruby/Cywin installation, rbconfig.rb can be found here ...

/usr/lib/ruby/1.8/i386-cygwin/rbconfig.rb

Blessings,
TwP

···

On 4/26/07, Leslie Viljoen <leslieviljoen@gmail.com> wrote:

Just tried RubyInline - amazing!
I had one GCC hiccough on my Ubuntu 6 system, I had to do this:

ln -s /usr/lib/gcc/x86_64-linux-gnu/4.0.3/cc1 /usr/bin/cc1plus

..to get GCC to recognise that G++ had been installed. Otherwise it
gave me this:
gcc: installation problem, cannot exec `cc1plus': No such file or directory

We can show you how to do this in Ruby,
which might be surprisingly different from
a line-by-line translation of the code you posted.

But line by line is more fun:

  void p_string(int n, int v)

Throw out return type, argument type and give the method a rubyesque name:

  def chunky_chunky_bacon(chunky, bacon)

  {
lose the burly bracket.

  int i;
get rid of the local declaration.

  cout<<"\nThe string is : ";

cout is called STDOUT, you don't need semicolons, and the string
you're printing isn't ruby enough;

  STDOUT << "\nWelcome to the madhouse :"

  for(i=0;i<n;i++)

for loop is different

  for ding_dong in 0..chunky-1

   cout<<v[i]<<" ";
turns into
   STDOUT << bacon[dingdong] << " " # this should look familiar by now
   end

end the closely curly brace
   }
becomes:
   end

Putting it all together:

void p_string(int n, int v)
{
int i;
cout<<"\nThe string is : ";
for(i=0;i<n;i++)
   cout<<v[i]<<" ";
}

becomes:

def chunky_chunky_bacon(chunky, bacon)
  STDOUT << "\nWelcome to the madhouse :"
  for ding_dong in 0..chunky-1
    STDOUT << bacon[ding_dong] << " "
  end
end

···

s

Though that one's for people of alternative brain.

···

On 4/26/07, Michael Ulm <michael.ulm@isis-papyrus.com> wrote:

Andrei Ursan wrote:
> Sammy Larbi wrote:
>> Andrei Ursan wrote, On 4/25/2007 4:29 AM:
>>> Can somebody translate this into ruby ? I need it fast...
>>>
>>
>> I don't mean to be rude, but I'm with most of the others on this. I
>> found it amusing (is that mean of me?) that you have no time to RTFM,
>> but you have time to wait longer than it would have taken to RTFM for
>> someone to answer. You don't need an entire book for loops and printing
>> strings. Thats page one stuff in any language, I would think.
>
> No, i did rftm and i'm doing it even now :)) :stuck_out_tongue:
> It's ok... I'm fine, don't need to worry 4 me, btw if u have some good
> ruby doc pleas links gimme to me i'm ruby doc hungry.
>

Welcome to Ruby, Andrei.

A Ruby book like no other can be found at

http://poignantguide.net/ruby/

And those ways vary by culture. Andrei is painfully obviously not a
native English speaker. Cut the guy some slack. What happened to the
whole "Matz Is Nice So...." meme that supposedly dominates this
community?

···

On Wed, 2007-25-04 at 21:12 +0900, David Jones wrote:

There are still ways to ask for things.

--
Michael T. Richter <ttmrichter@gmail.com> (GoogleTalk:
ttmrichter@gmail.com)
A well-designed and humane interface does not need to be split into
beginner and expert subsystems. (Jef Raskin)

Just installed the next Ubuntu, so I'll look at this. Thanks!

···

On 4/26/07, Tim Pease <tim.pease@gmail.com> wrote:

On 4/26/07, Leslie Viljoen <leslieviljoen@gmail.com> wrote:
>
> Just tried RubyInline - amazing!
> I had one GCC hiccough on my Ubuntu 6 system, I had to do this:
>
> ln -s /usr/lib/gcc/x86_64-linux-gnu/4.0.3/cc1 /usr/bin/cc1plus
>
> ..to get GCC to recognise that G++ had been installed. Otherwise it
> gave me this:
> gcc: installation problem, cannot exec `cc1plus': No such file or directory
>

The magic behind RubyInline is the rbconfig.rb file. This little Ruby
script contains the build environment used to compile the Ruby
interpreter for your particular platform. When RubyInline compiles
code, it uses the build environment found in rbconfig.rb.

So, the catch is that your machine environment
(compilers/libraries/etc) needs to agree with what is in rbconfig.rb.

For my Ruby/Cywin installation, rbconfig.rb can be found here ...

/usr/lib/ruby/1.8/i386-cygwin/rbconfig.rb

Blessings,
TwP

--
If you could create a machine that copies hamburgers — you put one
hamburger in and two equally good hamburgers come out the other side —
it would be unethical not to do so and make it freely available.

c'est bon!

···

On Apr 25, 2007, at 10:16 PM, Tim Becker wrote:

We can show you how to do this in Ruby,
which might be surprisingly different from
a line-by-line translation of the code you posted.

But line by line is more fun:

void p_string(int n, int v)

Throw out return type, argument type and give the method a rubyesque name:

def chunky_chunky_bacon(chunky, bacon)

{
lose the burly bracket.

int i;
get rid of the local declaration.

cout<<"\nThe string is : ";

cout is called STDOUT, you don't need semicolons, and the string
you're printing isn't ruby enough;

STDOUT << "\nWelcome to the madhouse :"

for(i=0;i<n;i++)

for loop is different

for ding_dong in 0..chunky-1

  cout<<v[i]<<" ";
turns into
  STDOUT << bacon[dingdong] << " " # this should look familiar by now
  end

end the closely curly brace
  }
becomes:
  end

Putting it all together:

void p_string(int n, int v)
{
int i;
cout<<"\nThe string is : ";
for(i=0;i<n;i++)
  cout<<v[i]<<" ";
}

becomes:

def chunky_chunky_bacon(chunky, bacon)
STDOUT << "\nWelcome to the madhouse :"
for ding_dong in 0..chunky-1
   STDOUT << bacon[ding_dong] << " "
end
end

s

Um, what do you mean by *that*? I have just one brain - am I old fashioned?

SCNR

  robert

···

On 26.04.2007 09:45, Leslie Viljoen wrote:

On 4/26/07, Michael Ulm <michael.ulm@isis-papyrus.com> wrote:

http://poignantguide.net/ruby/

Though that one's for people of alternative brain.

Thanks all of you for the links and support.
It's realy amazing and funny what you can do with Ruby.

···

--
Posted via http://www.ruby-forum.com/.

It just worked on Feisty, so they must have fixed the GCC installation.
Looked at rbconfig though. Thanks for the tip.

Les

···

On 4/26/07, Leslie Viljoen <leslieviljoen@gmail.com> wrote:

On 4/26/07, Tim Pease <tim.pease@gmail.com> wrote:
> On 4/26/07, Leslie Viljoen <leslieviljoen@gmail.com> wrote:
> >
> > Just tried RubyInline - amazing!
> > I had one GCC hiccough on my Ubuntu 6 system, I had to do this:
> >
> > ln -s /usr/lib/gcc/x86_64-linux-gnu/4.0.3/cc1 /usr/bin/cc1plus
> >
> > ..to get GCC to recognise that G++ had been installed. Otherwise it
> > gave me this:
> > gcc: installation problem, cannot exec `cc1plus': No such file or directory
> >
>
> The magic behind RubyInline is the rbconfig.rb file. This little Ruby
> script contains the build environment used to compile the Ruby
> interpreter for your particular platform. When RubyInline compiles
> code, it uses the build environment found in rbconfig.rb.
>
> So, the catch is that your machine environment
> (compilers/libraries/etc) needs to agree with what is in rbconfig.rb.
>
> For my Ruby/Cywin installation, rbconfig.rb can be found here ...
>
> /usr/lib/ruby/1.8/i386-cygwin/rbconfig.rb
>
> Blessings,
> TwP

Just installed the next Ubuntu, so I'll look at this. Thanks!

I agree, this mailing list seems to be getting a lot more hostile towards
people new to ruby. Posting a link to google or how to ask questions, or
making a snide remark about how they format their messages is not going to
get people into ruby. I know if someone just posted a link to google with
nothing else if I asked a question about a new language, I would be turned
off from it, even if I could have asked it better.

···

On 4/26/07, Michael T. Richter <ttmrichter@gmail.com> wrote:

On Wed, 2007-25-04 at 21:12 +0900, David Jones wrote:

There are still ways to ask for things.

And those ways vary by culture. Andrei is painfully obviously not a
native English speaker. Cut the guy some slack. What happened to the whole
"Matz Is Nice So...." meme that supposedly dominates this community?

  --
*Michael T. Richter* <ttmrichter@gmail.com> (*GoogleTalk:*
ttmrichter@gmail.com)
*A well-designed and humane interface does not need to be split into
beginner and expert subsystems. (Jef Raskin)*

--
Chris Carter
concentrationstudios.com
brynmawrcs.com

>> http://poignantguide.net/ruby/
>
> Though that one's for people of alternative brain.

Um, what do you mean by *that*? I have just one brain - am I old fashioned?

It seems that one is above average :wink: (at least if you take YHS as sample)

SCNR

        robert

idem

···

On 4/26/07, Robert Klemme <shortcutter@googlemail.com> wrote:

On 26.04.2007 09:45, Leslie Viljoen wrote:
> On 4/26/07, Michael Ulm <michael.ulm@isis-papyrus.com> wrote:

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Alternative as in abnormal. I just mean that the book is highly
strange, for people who appreciate strange. I really enjoyed it
myself.

Ah the scarf eaters... so wistful.

···

On 4/26/07, Robert Klemme <shortcutter@googlemail.com> wrote:

On 26.04.2007 09:45, Leslie Viljoen wrote:
> On 4/26/07, Michael Ulm <michael.ulm@isis-papyrus.com> wrote:
>> http://poignantguide.net/ruby/
>
> Though that one's for people of alternative brain.

Um, what do you mean by *that*? I have just one brain - am I old fashioned?

Hmm are you not exaggerating a bit?
I was *very* amused that OP got answers at all!
Personally I feel that this is still a great community and that this
community should not stretch to be more popular at any cost.
I had pretty much preferred to ignore that post but others decided,
very honorably, to tell OP to change his attitude if he wants to
obtain something.
I think that your statement "could have asked it better" is the
euphemism of the month ;).
Cheers
Robert

···

On 4/26/07, Chris Carter <cdcarter@gmail.com> wrote:

On 4/26/07, Michael T. Richter <ttmrichter@gmail.com> wrote:
>
> On Wed, 2007-25-04 at 21:12 +0900, David Jones wrote:
>
> There are still ways to ask for things.
>
> And those ways vary by culture. Andrei is painfully obviously not a
> native English speaker. Cut the guy some slack. What happened to the whole
> "Matz Is Nice So...." meme that supposedly dominates this community?
>
> --
> *Michael T. Richter* <ttmrichter@gmail.com> (*GoogleTalk:*
> ttmrichter@gmail.com)
> *A well-designed and humane interface does not need to be split into
> beginner and expert subsystems. (Jef Raskin)*
>
I agree, this mailing list seems to be getting a lot more hostile towards
people new to ruby. Posting a link to google or how to ask questions, or
making a snide remark about how they format their messages is not going to
get people into ruby. I know if someone just posted a link to google with
nothing else if I asked a question about a new language, I would be turned
off from it, even if I could have asked it better.

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Leslie Viljoen wrote:

> Though that one's for people of alternative brain.

Um, what do you mean by *that*? I have just one brain - am I old fashioned?

Alternative as in abnormal. I just mean that the book is highly
strange, for people who appreciate strange. I really enjoyed it
myself.

Ah the scarf eaters... so wistful.

I probably would have loved _why's book, except I was so impatient to learn ruby that I skipped over all the non-technical parts. It was pretty informative, but its strange beauty was lost on a student that pretty much wanted to learn Ruby in one night.

Not to harp on the issue, but had the same post gone to C or C++ mailing-list, it would've been flamed only with no solutions. The beauty of the Ruby world is that (in the words of Masayoshi Takahashi, of Ruby Kaigi) "Ruby is for lazy people" "java and c++ are for diligent people". It means Ruby is fun and not painful like many languages, so people actually enjoy responding to the list and trying to make nice code!
The culture of those other languages tends to be the anal-retentive, I'm-smarter-than-you, RTFM attitude.
In Ruby, RTFM is RTWFM, where W = wonderful. Unlike those other languages, this stuff isn't terse and most of the books are good ones. (Nothing is more annoying to me than being referred to K&R2, one of the least accessible texts I've ever read, even though it does have a wealth of good information in it.)

···

On Apr 27, 2007, at 5:05 PM, Robert Dober wrote:

On 4/26/07, Chris Carter <cdcarter@gmail.com> wrote:

On 4/26/07, Michael T. Richter <ttmrichter@gmail.com> wrote:
>
> On Wed, 2007-25-04 at 21:12 +0900, David Jones wrote:
>
> There are still ways to ask for things.
>
> And those ways vary by culture. Andrei is painfully obviously not a
> native English speaker. Cut the guy some slack. What happened to the whole
> "Matz Is Nice So...." meme that supposedly dominates this community?
>
> --
> *Michael T. Richter* <ttmrichter@gmail.com> (*GoogleTalk:*
> ttmrichter@gmail.com)
> *A well-designed and humane interface does not need to be split into
> beginner and expert subsystems. (Jef Raskin)*
>
I agree, this mailing list seems to be getting a lot more hostile towards
people new to ruby. Posting a link to google or how to ask questions, or
making a snide remark about how they format their messages is not going to
get people into ruby. I know if someone just posted a link to google with
nothing else if I asked a question about a new language, I would be turned
off from it, even if I could have asked it better.

Hmm are you not exaggerating a bit?
I was *very* amused that OP got answers at all!
Personally I feel that this is still a great community and that this
community should not stretch to be more popular at any cost.
I had pretty much preferred to ignore that post but others decided,
very honorably, to tell OP to change his attitude if he wants to
obtain something.
I think that your statement "could have asked it better" is the
euphemism of the month ;).
Cheers
Robert

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

I'm a long time ruby user, but I just joined this list tonight. It's disappointing to see drama already. I hope this is not the norm.

- Philip

···

On Apr 27, 2007, at 1:41 AM, John Joyce wrote:

On Apr 27, 2007, at 5:05 PM, Robert Dober wrote:

On 4/26/07, Chris Carter <cdcarter@gmail.com> wrote:

On 4/26/07, Michael T. Richter <ttmrichter@gmail.com> wrote:
>
> On Wed, 2007-25-04 at 21:12 +0900, David Jones wrote:
>
> There are still ways to ask for things.
>
> And those ways vary by culture. Andrei is painfully obviously not a
> native English speaker. Cut the guy some slack. What happened to the whole
> "Matz Is Nice So...." meme that supposedly dominates this community?
>
> --
> *Michael T. Richter* <ttmrichter@gmail.com> (*GoogleTalk:*
> ttmrichter@gmail.com)
> *A well-designed and humane interface does not need to be split into
> beginner and expert subsystems. (Jef Raskin)*
>
I agree, this mailing list seems to be getting a lot more hostile towards
people new to ruby. Posting a link to google or how to ask questions, or
making a snide remark about how they format their messages is not going to
get people into ruby. I know if someone just posted a link to google with
nothing else if I asked a question about a new language, I would be turned
off from it, even if I could have asked it better.

Hmm are you not exaggerating a bit?
I was *very* amused that OP got answers at all!
Personally I feel that this is still a great community and that this
community should not stretch to be more popular at any cost.
I had pretty much preferred to ignore that post but others decided,
very honorably, to tell OP to change his attitude if he wants to
obtain something.
I think that your statement "could have asked it better" is the
euphemism of the month ;).
Cheers
Robert

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Not to harp on the issue, but had the same post gone to C or C++ mailing-list, it would've been flamed only with no solutions. The beauty of the Ruby world is that (in the words of Masayoshi Takahashi, of Ruby Kaigi) "Ruby is for lazy people" "java and c++ are for diligent people". It means Ruby is fun and not painful like many languages, so people actually enjoy responding to the list and trying to make nice code!
The culture of those other languages tends to be the anal-retentive, I'm-smarter-than-you, RTFM attitude.
In Ruby, RTFM is RTWFM, where W = wonderful. Unlike those other languages, this stuff isn't terse and most of the books are good ones. (Nothing is more annoying to me than being referred to K&R2, one of the least accessible texts I've ever read, even though it does have a wealth of good information in it.)

NOT the norm!

···

On Apr 27, 2007, at 6:17 PM, Philip Gatt wrote:

I'm a long time ruby user, but I just joined this list tonight. It's disappointing to see drama already. I hope this is not the norm.

- Philip

Everywhere where there are people together there will be conflict. On
the whole ruby-talk is the greatest forum I have been a part of.
"Drama" is extremely rare, mostly it's just a hundred questions a day
being answered with a thousand answers.

Also, some really great programmers regularly post here.

···

On 4/27/07, Philip Gatt <gattster@gmail.com> wrote:

I'm a long time ruby user, but I just joined this list tonight. It's
disappointing to see drama already. I hope this is not the norm.

- Philip