From: Axel Etzold Date: 2008-10-30T08:45:50+09:00 Subject: Re: automatic code conversion from Ruby to C ? > Axel Etzold wrote: > > I was just wondering whether there'd be some tool that would translate > > some of my Ruby > > code into C/C++ to speed up the development process. > > If it did, at best it would generate something like this: > > /* > str = "hello" > str.upcase! > */ > VALUE str = rb_str_new2("hello"); > rb_funcall(str, rb_intern("upcase!"), 0); > > That is, it would use entirely Ruby data structures, so the rest of your > C code would have to be written to use Ruby data structures too. So it's > nothing like hand-written C. > Dear Brian, well, the examples in the RubyToC gem as well as the Cplus2ruby gem suggested that maybe, C or C++ code could be produced from Ruby scripts that are fed into them (for some subset of Ruby). But I have not been able to translate my Ruby scripts just like that into C using these softwares. I am not looking for swig or an extension of Ruby by C, but a way of producing C/C++ code from a Ruby script containing some magical part that saves me the trouble of declaring all the variables, assigning memory etc and all these things that make writing C/C++ so tedious in comparison with Ruby ... For the project I am working on right now, this is not so dramatic. I just wanted to know if I had missed something that would spare me all the troubles of C/C++ development ;-) > What's a "C hash"? Perhaps you mean glib, or STL, or a zillion other > possible C/C++ libraries? > Ruby doesn't use any of these, and Ruby's hashes don't map directly to > any of them (for example, coders can subclass Hash, or override methods > in it; and a Ruby Hash can contain mixed types for both keys and values) > > Even simple things like "Integer" don't map directly to C. I am of course aware that there are conceptual differences between languages ... Maybe a conversion tool between programming languages would then need to be able to capture some of these by analyzing a lot of parallel code from detailed guidebooks explaining how to program task X "idiomatically" in both languages. In automated translation between natural languages, results used to be poor as long as individual words were translated -- there is the famous joke that a 1950ies automated translation of "out of mind, out of sight" into Russian and back gave "invisible idiot". On the other hand, it is possible to summarize texts automatically and return their gist quite well using statistical methods, such as Latent Semantic Analysis (there's the classifier gem in Ruby implementing this for English texts). This will map count word occurrences in each sentence or paragraph of a text (after having removed the most frequent ones, that are likely to occur in any text), and perform some operations on the resulting matrix, so that sentences can be mapped to some object from linear algebra which allows to classify them and introduce distances between them. If you now have a long text, say, a novel in English, and its (human-made) translation into Russian, it should be possible to extract some correspondence between word groups, words, expressions in English to those in Russian from this training set, including several alternative ways to express approximately the same idea in either language. I am wondering whether it's possible to do something similar between programming languages and what could be the connection between them (S-expressions?) That's of course more an academic question than a practical one, but if someone had done it already, and I'd be able to write C in Ruby with an automatic translator, I'd still like to know ;-) From all the responses I got, this doesn't seem to be the case ... and I'd truly expect that to be a huge undertaking as well. Thank you to all who responded to my question! Best regards, Axel -- Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten Browser-Versionen downloaden: http://www.gmx.net/de/go/browser