Is there any tool to translate Lisp code into Python? [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Because I want to use Lisp's syntax and Python's libraries.
Maybe some tools like Parenscript but generates Python code instead of Javascript.

I've been experimenting a bit with a Lisp compiler targeting Python bytecode.
You can see a small video here.
It's just a proof-of-concept toy but it's IMO a viable path and the end result would be able to call and be called from python freely (and it would be compatible with any python extension library). All this keeping however the power of macros (metaprogramming is probably the area in which Python is farthest from lisp).
Targeting Python source code instead is quite more annoying to do because there are explicit syntax limitations that make compiling Lisp difficult (e.g. assignment is not an expression, no statement is permitted in lambda, captured variables are read-only in Python 2.x).
The VM runtime however doesn't have these limitations and Python bytecode is reasonably nice.
My toy currently can target Python 2.x, Python 3.x and works even with PyPy (so you get a JIT compiler too).
Of course aiming at becoming a full compliant Common Lisp implementation would be IMO nonsense from a technical point of view, but a lisp dialect based on Python runtime types and compatible with Python object system could instead be a reasonable tool with practical applications.

I believe that Hy is what you are looking for. From the tutorial:
Hy converts to python’s own abstract syntax tree, so you’ll soon start
to find that all the familiar power of python is at your fingertips.
However note that Hy isn't Common Lisp, so you can't cut and paste.

Related

What is the best way to learn and master Python, from a procedural programmer perspective? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am Mathematician and I currently work mainly on Operations Research field, building algorithms for solving Mathematical Programming or Optimization problems.
I learnt Fortran, Pascal and C (oh, and Visual Basic) when I was a student, not very deeply, but in the case of C I managed quite well with pointers, structs and so on, for example.
Later, I've been using Visual C++ for my research, building algorithms for my problems and so on. I am not able to create any GUI and I don't use objects but a classical procedural perspective, so in fact I use C with some characteristics from C++.
There was a moment when I tried to learn Python. It seemed so friendly, fresh, interesting, simple but powerful...  But at the end, I was a little bit confused, because of many different reasons, for example:
I was used to procedural languages, and Python is functional oriented, a little bit at least.
I was used to languages that can create .exe files (compiled), and Python is interpreted. Also, I learnt that for that reason C is ---generally speaking--- faster than Pyhton, when we talk about creating complex algorithms and so on.
There are different versions of Python, all of them stable and up-to-date! I mean, there is Python 2.x, and Python 3.x. And there are things that work in version 3 but not in version 2, etc.
Maybe this is even more subjective than the previous reasons, but I find more, better and more stable or reliable libraries in C than in Python.
Also, I found it a bit difficult to choose between different GUIs for Python programming and different flavors, as Python IDE, Tkinter, IronPython...
I do think that Python is a powerful language despite being interpreted. And also I still think it is more beautiful than C. I like Python, but I would like that I liked more!
So, finally, my question is, how can I truly learn and master Python, in a sure way, so that I am able to use it as my main choice for programming mathematical algorithms?
When I say "sure", I mean, which are (in your opinion) the safest path and tools for learning and using Python in a reliable way?, which are the more mature and stable libraries, GUIs, and so on?
Sorry if this question is a little bit strange, but I guess there could be more people with the same kind of doubts about Python as me.

C++ to simpler language (Python, Lua, etc) converter? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I know Python and I've come across a small C++ source file I would like to convert to Python. But the C++ code is too complex for me to understand without learning the language.
So I was wondering if there is a tool that does the opposite of what many people want: convert C++ code to Python, or another simpler language I could understand.
I know these tools work on very simple code and hardly do a perfect job even then, but the code I have is pretty small and simple.
I have found "ctopy", but there is no usage example, if I just pass a .cpp file to it, it just hangs, no error message or anything.
And maybe it won't work for C++ at all.
http://www.catb.org/~esr/ctopy/
Most translators produce inferior code which you can't really use anywhere; and the more complicated your code is, the worse the results are. Only real human brains can do that perfectly. I'd suggest that you learn the language. If you already know python, learning another language shouldn't be too difficult.
I've seen (and wanted) such a programming code converter and found exactly what you want in cpp2py although I personally haven't tried it for myself website https://github.com/hlamer/cpp2python
It's a little painful, but I have gotten some python code using
https://code.google.com/p/ctypesgen/
For some reason it doesn't handle bool's.
It probably uses regex substitutions, and other things like that, but it sure beats writing out your own ctypes wrapper without it.
http://docs.python.org/2/library/ctypes.html
Another option you could look into, is compiling your C++ into an executable and then running the executable using python.
And if you decide you need the power of C/C++ in your tool belt:
https://stackoverflow.com/questions/3973899/learning-c-java-coming-from-python
Hope that helps.

Learning Python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am going to need to learn advanced Python and must be good at it in about a year, Are there any books, recommendations. I am already very familiar with PHP, MySQL, JS + HTML, and know a bit of java and C (arduino programming).
Thanks,
RayQuang
Since you sound like a competent programmer, the best place to start may be the official Python 2.7 Tutorial. It's very thorough, certainly.
After that, I advise looking up through the language reference and standard library reference (the stdlib for Python is pretty massive) to get everything else.
It's not a book, but I found the Google Python Class very useful. There's video, reading material, and practice questions that I found very useful.
There are a lot of good resources, either at the python wiki, or here at previous similar questions.
Generally I would recommend starting with the official python tutorial. Alternatively, you might want to check other tutorials, aimed for people with previous programming experience.
Afterwards, you can try books, such as 'Dive Into Python', but I always preferred sharpening my skills by trying a set of problems, such as python challenge and Project Euler.
I think that trying to solve such problems is a good advice for every programmer who's trying to learn a new language.
It looks like there are a lot of good books being recommended. Be aware that there are two main versions of Python in circulation. 3.0 is the new, and a lot of 2.7 programs won't work with 3.0. Some of the syntax has been tidied up - and one of the most common problems is "print" which now has a syntax more consistent with the rest of the language.
As with any language, the best way to learn it is to start using it. Choose a project which pulls to Python's strengths (eg. text processing and data structures) and your probable needs in 12 months time, and start coding!
take a look at Mark Lutz's book..
it's more than an introduction, but it's not very thorough
http://oreilly.com/catalog/9781565924642
once you finished that one, if you found it useful you might want to pass at:
http://oreilly.com/catalog/9780596158118?green=18666053383&cmp=af-mybuy-9780596158118.IP
another interesting one is the Python Cookbook
http://oreilly.com/catalog/9780596001674 (careful, it's 6 years old)
the official tutorials are very useful, too ;)
I have good books, but I don't know exactly what do you want (CGI's, XML manipulation, ..).
A nice way to start your study is with this book: Apress Beginning Python From Novice to Professional.
After you see the examples and the simple structures, I suggest you to look the oficial site: http://www.python.org/ and the HOWTO examples: http://docs.python.org/dev/howto/index.html

Is there a standard lexer/parser tool for Python? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
A volunteer job requires us to convert a large number of LaTeX documents into ePub file format. It's a series of open-source fiction book which has so far only been produced only on paper via a print on demand service. We'd like to be able to offer the book to users of book-reader devices (such as Kindle) which require the ePub format for best results.
Fortunately, ePub is a very simple format, however there's no trivial way for LaTeX to produce the XHTML output required.
We experimented with alternative LaTeX compilers (e.g. plastex) but in the end we figured that it would probably be a lot easier to simply write our own compiler which understands a tiny subset of the LaTeX language and compiles directly to XHTML / ePub.
Previously I used a tool on Windows called GOLD. This allowed me to go directly from BNF grammars to a stub parser. It also alllowed me to implement the parser in any language I liked. (I'd choose Python).
This product has to work on Linux, so I'm wondering if there's an equivalent toolchain that works as well under Ubutnu / Eclipse / Python. The idea is that we will take the grammar of TeX and just implement a teeny subset of that, but we do not want to spend a huge amount of time worrying about grammar and parsing. A parser generator would obviously save us a great deal of time.
Sal
UPDATE 1: Bonus marks for a solution with excellent documentation or tutorials.
UPDATE 2: Extra bonus if there is grammar file for TeX already available, since all I'd have to do is implement the functions we care about.
Try pyparsing.
Se http://pyparsing.wikispaces.com/WhosUsingPyparsing, search for TeX. There's a project where pyparsing is used to parse a subset of TeX syntax mentioned on that page.
For documentation, I recommend the "Getting started with pyparsing" e-book, by pyparsing's author.
EDIT: According to PaulMcG, Pyparsing is no longer hosted on wikispaces.com. Go to the new GitHub site
Try PLY.
I once used tex4ht to convert LaTeX to XHTML+MathML. Worked quite nice. From that on, you could use the output HTML as base for the ePub.
Of course, this breaks the Python toolchain, so it might not become your favorite method...

Where can I learn more about PyPy's translation function? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I've been having a hard time trying to understand PyPy's translation. It looks like something absolutely revolutionary from simply reading the description, however I'm hard-pressed to find good documentation on actually translating a real world piece of code to something such as LLVM. Does such a thing exist? The official PyPy documentation on it just skims over the functionality, rather than providing anything I can try out myself.
This document seems to go into quite a bit of detail (and I think a complete description is out of scope for a stackoverflow answer):
http://codespeak.net/pypy/dist/pypy/doc/translation.html
The general idea of translating from one language to another isn't particularly revolutionary, but it has only recently been gaining popularity / applicability in "real-world" applications. GWT does this with Java (generating Javascript) and there is a library for translating Haskell into various other languages as well (called YHC)
If you want some hand-on examples, PyPy's Getting Started document has a section titled "Trying out the translator".
PyPy translator is in general, not intended for more public use. We use it for translating
our own python interpreter (including JIT and GCs, both written in RPython, this restricted
subset of Python). The idea is that with good JIT and GC, you'll be able to speedups even
without knowing or using PyPy's translation toolchain (and more importantly, without
restricting yourself to RPython).
Cheers,
fijal
Are you looking for Python specific translation, or just the general "how do you compile some code to bytecode"? If the latter is your case, check the LLVM tutorial. I especially find chapter two, which teaches you to write a compiler for your own language, interesting.
It looks like something absolutely revolutionary from simply reading the description,
As far as I know, PyPy is novel in the sense that it is the first system expressly designed for implementing languages. Other tools exist to help with much of the very front end, such as parser generators, or for the very back end, such as code generation, but not much existed for connecting the two.

Categories

Resources