I'd like to write notes for class in plain text.
I was wondering if there was a markup language for doing this, where I could parse the notes for key terms, titles, page #s etc programmatically with a language such as Ruby or Python.
In the Python world, reStructuredText is probably the most widely used markup language, and it's the result of a long-term and fairly rigorous design and development. It's the markup underlying the Sphinx documentation tool which, among other things, is used for the Python docs and many Python projects.
I also haven't seen a formal specification for other markup languages, at least not with the same thoroughness.
LYX! I used lyx all last semester and it was great. It takes a little while to get used to (like a week). By the end of the first week I was formatting equations and matrices just as fast as my classmates could write them down. The only problem is diagrams, but if you have a sheet of paper handy or even a tablet, it shouldn't be a problem at all.
http://www.lyx.org/
Note: Lyx is a tex parser that translates code in real time. You could also just use tex, but then you might not format things right. You could also use the openoffice tex plugin, but that doesn't work as well as LYX, but it does make life easier with the plain text formatting. Also, the openoffice plugin is not current.
here's a link to that project ooolatex:
http://ooolatex.sourceforge.net/
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Is it feasible to script in a Lisp, as opposed to Ruby/Python/Perl/(insert accepted scripting language)? By this I mean do things like file processing (open a text file, count the number of words, return the nth line), string processing (reverse, split, slice, remove punctuation), prototyping/quick computations, and other things you would normally use Python, etc. for. How productive would doing such tasks in a Lisp be, as opposed to Ruby/Python/Perl/scripting language of choice?
I ask because I want to learn a Lisp but also use it to do something instead of only learning it for the sake of it. I looked around, but couldn't find much information about scripting in a Lisp. If it is feasible, what would be a good implementation?
Thank you!
Today, using LISP as if it's certain that anyone would understand what language one is talking about is absurd since it hasn't been one language since the 70's or probably some time earlier too. LISP only indicates that it's fully parenthesized Polish prefix notation just like Pascal, Ruby, Python and Perl are just variations of ALGOL.
Scheme is a standard and Common LISP is a standard. Both of those are general purpose though Common LISP is a batteries included while Scheme is a minimalistic language. They are quite different in style so comparing them would be like comparing Java with Python.
Embedded LISPS
There are lots of use of Scheme and specialized LISP dialects as embedded languages. Emacs is the most widely used editor in the unix segment and its lisp elisp is the most used lisp language because of this. Image processing applpication GIMP has a Scheme base with extensions for image processing.
Stand alone scripts
It's possible in many Common LISP implementation with the standard #!-notation to make a script work as an executable and run it as an application. Eg. I use CLISP and have scripts using #!/usr/bin/clisp -C as first line. I also use Scheme the same way and in the very fast incremental compiler ikarus you use #!/usr/bin/ikarus --r6rs-script. Clojure has all power of Java libraries and you can use your own classes from it and it also can be made an application with #!/usr/bin/env java -cp /path/to/clojure-1.2.0.jar clojure.main
more permanent application
In Common LISP you can dump an image. It will be a Common Lisp binary with your code already compiled in. Many Scheme implementations has compilation to native and Clojure can compile to java bytecode (though it's not the most common way to do it). Still I have had experience with Ikarus sometimes interpreting faster than a compiled executable from racket, chicken and gambit so I often do my programming in DrRacket and running it in ikarus in Scheme.
Try both Common LISP and Scheme as both of them are good enough for the tasks you specified in your question. There are many free books on the subject and some are worth their price as well. You may also try Racket too, which is a Scheme deviate with lots of libraries for everyday tasks, but it's not conforming to any standard.
About productivity
I imagine you are referring to how quick you can write a certain task in a Lisp dialect. I imagine it depends on how used you are to the syntax. It takes a while to get used to it after only knowing Algol dialects. It takes different approaches as well as you need to think in a more functional manner, especially for Scheme. I imagine when you are as good in Scheme as in your favorite Algol dialect it will be similar. Eg. some algol dialects are faster to prototype inn than others and that is true for Lisp dialects as well.
When I first started to poke around Lisp I used it to write shell scripts... I'm somewhat OCD about order and uniformity and I really liked Lisp languages because they have saner syntax (fewer syntax rules, no random decisions related to particular syntax elements).
If you are looking into Common Lisp, then SBCL, as installed by default on any Linux distro is available right away for CGI scripting. SBCL also has its means to process command line arguments, access pipes, processes and so on. If you aren't after portability between different Lisps, then I'd say that you are good to go. Just to give you examples of where I used this scripting: a girl in our office compiled and maintained a list of words which I had to further process in our application. This list was available as Googledoc spreadsheet. My script would download the words table and parse it into the format I needed. I had scripts that helped me with file manipulation and preprocessing before the project was compiled (the project wasn't in Lisp).
Finally, SBCL has its own means of being used with FastCGI http://kdr2.com/project/sb-fastcgi.html , but of course there are several full-blown HTTP-servers, which you could either use as is, or put behind a proxy. Hunchentoot was historically most popular one, but there are others too, like cl-http, here are some more links: http://www.cliki.net/web .
#!/usr/bin/env sbcl --script
would be the shebang comment to use.
Furthermore, I use Common Lisp for my classes, simply to do my homework, which is, I imagine, what you were after when you said "open a text file, count the number of words, return the nth line". Here's an example I used for the class on introduction to logic: https://github.com/wvxvw/coursera-logic/blob/master/formula.lisp .
Since there was a discussion on the matter, here's something else to be considered.
Typically scripting languages have twofold nature: they are written in in a low-level language, while exposing high-level API to the programmer. This can be a blessing or a curse. On one hand languages like Python, Ruby, JavaScript have highly optimised libraries for dealing with common tasks, while Common Lisp typically, similarly to C++ or Java implements everything in Lisp. Thus, for example, strings are a lot less sophisticated in CL then they are in JavaScript: in CL they are simple arrays of characters, while in JS they are a special kind of trees known as ropes.
Typically, a programmer writing in scripting language is neither required nor expected to pull out a high performance code. The language compensates for it with the base level highly optimized library code. Unfortunately, once the programmer actually wants to squeeze as much performance as possible from the scripting language, it appears that they just don't have the tools to do it, because they can't get to the bottom of the implementation.
On the other hand, dealing with the lower level of details means that the programmer will be less productive overall, and this would require more skill, because optimizing the code to get on par with the industry standard implementations requires skill.
Common Lisp generally falls under the second category, but I'd argue it to be still good for one-liners and casual programming because of the extensive library and highly developed macro system, which allows to reduce verbosity usually associated with low-level languages.
I understand that you have asked two questions:
Is it possible to run scheme scripts from a command line
How effective is that?
I can answer your first question, but not your second. It highly depends on your scheme skills and how much code you want to (re)write in scheme how feasible it is.
So I just answer your first questions :)
Have a look at this SO question: Running Scheme from the command line.
If you have installed, for example, DrRacket (which is a good IDE for many scheme dialects) as your scheme interpreter, you may use the shebang line #! /usr/bin/env mzscheme in your scheme script.
This test script (test.scm)
#!/usr/bin/env mzscheme
#lang scheme
(print (+ 40 2))
can be made executable (with chmod +x test.scm) and executed (with ./test.scm).
I'd say that Lisp/Scheme could be used to write small scripts or big application. But they are not yet ready for wide use.
The big difference between python/ruby and scheme is that python has a huge library of modules centralized in one place. Ruby is quite similar to python with ruby gems.
Scheme on the other hand might have a small library of modules scattered accross the internet. The quality of modules doesn't always compare to the popular modules in python and ruby.
One could say that they are aiming at different goal but I'd say scheme just got old and people started to forget about it and how it could be used as a tool instead of just a school subject.
About Lisp, I can't really say. But from your description, it's possible to write scripts that you'd like to write but if you need something specific it's possible that it's not there and you'll have to rewrite it yourself.
All I can say, is jump in. And become someone who gives a future to this language. Don't be scared. This language has a bright future and you'll learn a lot from it.
WRT to your tasks, what about using Emacs, which comes with an interactive Python-shell. So you have the convenience of editing alongside with running scripts.
Stylus is a language that compiles into normal CSS. The language is a huge time- and space saver for many reasons. For instance, I can put selectors inside each other:
div.foo
color: red
div.bar
color: blue
font-weight: bold
div.baz
color: green
background-color: pink
I can also do stuff like make vendor-specific properties work without the prefixes, which saves a lot of space.
My question is: Are there any alternatives to Stylus? I can't really think of a description of what Stylus is, so I'm finding it hard to find any alternatives using Google.
Note: By alternatives, I mean languages that compile into CSS and offer time-saving goodies.
The reason I'm looking for alternatives is that I use Stylus for all my projects, and I want to see if there's a better solution out there. The reason I'm not 100% happy with Stylus is that the TextMate bundle for it is terrible, and Stylus requires Node.js to compile which is also a step I'd like to avoid. I use mainly Python.
Stylus' older siblings are LESS and Sass. I prefer Stylus to both, both because of features and speed, but they are pretty much interchangeable, AFAIK.
LESS is also written in javascript, and so will not release you from your node.js dependency. Sass is written in Ruby.
There is a Stylus implementation in Python. It's called Stilus and is nearing completion. You find it here: https://github.com/jw/stilus
CSS-On-Diet is written in Python. You can install it easily by
pip install CSSOnDiet
It saves a lot of time and space, but syntax is different
I can't really think of a description of what Stylus is
The term you are looking for is CSS preprocessor.
Check this ones:
Less: Unlike Stylus is a css super-set. In other words, every valid CSS document is also a valid Less document. This way is easier to migrate from existing CSS.
Sass: Very similar to Less. It has a variant (SCSS) which notation is also a SCC super-set. Some people prefer Sass over Less because his control-structures syntax (selection, iteration) is more natural for most programmers, since is very similar to the one used in most imperative programming languages (C++, Java, etc) while Less uses a recursive approach, more similar to functional programming languages.
Absurd JS: The styles are described by writting pure JavaScript code, given that his notation for objects literals is very similar to the CSS notation. This interesting approach allows you to manipulate and preprocess the styles in any form you can imagine, since you are no longer limited by a small bunch of control structures like in the two above, but you can use the whole toolset of features provided by a programming language. I strongly recommend this options if you are a programmer, or if as a designer you are interested in learning how to code, or if you want to describe and reuse your style definitions in a non-trivial or crazy way you can't achieve with just a preprocessor.
I didn't know Stylus before reading this question. It seems to be pretty nice. I like his Python-like approach of use line breaks and tabulations to define the structure of the code. I will give it a try. If you already use this preprocessor and you don't find any important drawback, I would stick with it.
I'm interested in writing a parsing engine such as the ones in Inform, which is very robust.
I've tried a couple of different approach:
regex. For regex, I can only match {verb} {noun1 optional-noun2} {optional-preposition} {indirect-noun1 optional-indirect-noun2} This doesn't work that well.
list of predefined verbs and their matched preposition and nouns. This approach is too complex, since there has to be A LOT of predefined data.
splitting into different words and run them through a dictionary maps. Again this is too complex and not practical due to the amiguity of certain words such as "look" or "put (on, out)"
I know about language processing though I have actually no idea how to start and some of the stuff are too complicated. (No CS background, I'm just learning on my own right now).
Some ideas I have:
As I've said, natural language processing.
Design a parser that parses something similar to SQL.
Is there any other ideas? How would I go about design and implementing them?
Note I'm using Python as my language. and in case you missed it, I'm not design a programming language, I'm just parsing user command such as "go north" or complex stuff, like "put the fire out with the blanket"
Besides the mentioned pyparsing, which looks very appropriate (I've only used it a tiny bit), you should look into using nltk. It's a great collection of tools for natural language processing, and there's even a book.
Hey as a project to improve my programing skills I've begun programing a nice code editor in python to teach myself project management, version control, and gui programming. I was wanting to utilize syntax files made for other programs so I could have a large collection already. I was wondering if there was any kind of universal syntax file format much in the same sense as .odt files. I heard of one once in a forum, it had a website, but I can't remember it now. If not I may just try to use gedit syntax files or geany.
thanks
If you're planning to do syntax highlighting, check out Pygments, especially the bit about lexers.
Since you mentioned Geany, you might want to look at the Scintilla docs. (Geany is built upon Scintilla).
You might find this post interesting.
Also, be sure to get familiar with the venerable lex and yacc.
Not sure what .odt has to do with any of this.
I could see some sort of BNF being able to describe (almost) any syntax: Just run the text and the BNF through a parser, and apply a color scheme to the terminals. You could even get a bit more fancy, since you'd have the syntax tree.
In reality, I think most syntax files take an easier approach, such as regular expressions. This would put then somewhere above regular expressions but not really quite context-free in terms of power.
As for file formats, if you re-use something that exists, then you can just loot and pillage (subject to license agreements) their syntax file data.
i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any programming language implemented in pure python which i can see as a reference ( or use directly ? ) -- i need simple language ( simple statements and ifs can do )
edit: sorry if i did not make myself clear but what i want is "a language to customize the running of program" , even though pypi seems a great option, what i am looking for is more simple which i can study and extend myself if need arise. my google searches pointing towards xml based langagues. ( BMEL , XForms etc ).
The question isn't completely clear on scope, but I have a hunch that PyPy, embedding other full languages, and similar solutions might be overkill. It sounds like iamgopal may really be interested in something more like Interpreter Pattern or Little Language.
If the language you want to support is really small (see the Interpreter Pattern link), then hand-coding this yourself in Python won't be too hard. You can write a simple parser (Google around; here's one example), then walk the AST and evaluate user expressions.
However, if you expect this to be used for a long time or by many people, it may be worth throwing a real language at the problem. (I'd recommend Python itself if your users are already familiar with basic Python syntax).
Ren'Py is a modification to Python syntax built on top of Python itself, using the language tools in the stdlib.
For your user's sake, don't use an XML based language - XML is an awful basis for a programming language and your users will hate you for it.
Here is a suggestion. Use a strict subset of Python for your language. Use the compiler module to convert their code into an abstract syntax tree and walk the tree to to validate that the code conforms to your subset before converting the AST into python bytecode.
N.B. I just checked the docs and see that the compiler package is deprecated in 2.6 and removed in Python 3.x. Does anyone know why that is?
Numerous template languages such as Cheetah, Django templates, Genshi, Mako, Mighty might serve as an example.
Why not Python itself? With some care you can use eval to run user code.
One of the good thing about interpreted scripting languages is that you don't need another extra scripting language!
PLY (Python Lex-Yacc)
is something of your interest.
Possibly Common Lisp (or any other Lisp) will be the best choice for that task. Because Lisp make it possible to easily extend host language with powerful macroses and construct DSL (domain specific language).
If all you need is simple if statements and expressions, I'm sure it wouldn't be an awful task to parse each line. Something like
if some flag
activate some feature
deactivate some feature
elif some other flag
activate some feature
activate some feature
else
logout
Just write a class which, while parsing takes the first word, checks if it's "if, elif, else," etc, and if so, check a flag and set a flag saying you either are or are not executing until the next conditional. If it's not a conditional, call a function based on the first keyword that would modify the program state in some way.
The class could store some local execution state (are we in an if statement? If so are we executing this branch?) and have another class containing some global application state (flags that are checkable by if statements, etc).
This is probably the wrong thing to do in your situation (it's very prone to bugs, it's dangerous if you don't treat the data in the scripts correctly), but it's at least a start if you do decide to interpret your own mini-language.
Seriously though, if you try this, be very, very, srs careful. Don't give the scripts any functionality that they don't definitely need, because you are almost certainly opening security holes by doing something like this.
Don't say I didn't warn you.