> Axel Etzold wrote:
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 ...
The attached is "dirty washing": it can be used but it's not really
fit for polite society, and, well, you get the gist. I'm not
maintaining it at the moment, and it's rather tailored to what I
needed at the time (so chop out references to fsv_common.h for
example), but if your are wearing thick rubber gloves and a boiler
suit you might like to poke around in it to see if there's stuff you
can use.
The concept behind it was to reduce declarations, by getting the function
definitions to produce the prototypes, and thereby the associated header
files, so I don't have to use the "What I tell you three times is true"
approach of C. So it's essentially a macro processor, but more Rubyesque,
and allows you to compute stuff in ruby to insert directly. See things
like "Code Generation in Action" and the website
for things a lot less horrid than this.
It is also based around the idea that a "class" in C works like FILE*,
its a pointer to struct with associated functions that operate on that,
without people having to know how (except those who write such functions).
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.
The only thing that gets near that is the fabled "decompiler", and I've
not seen one myself. I think this translator between computer languages
is going to be "Star Trek technology" for a while yet.
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".
I heard it was "invisible insane".
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
I've played with free software for this recently, and it seems to be extremely
poor quality, usually missing the point entirely. I'd like to be shown
something that works well in this area.
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?)
Human languages only have to be portable across humans, which are basically
the same platform, with the same types of IO, memory constraints and physical
architecture. Computer languages can vary widely, FORTH, Haskell, Cobol...
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
Hugh
cclass_creator.rb (15.4 KB)
···
On Thu, 30 Oct 2008, Axel Etzold wrote: