views:

300

answers:

11

Is there a programming language which can be programmed entirely in interactive mode, without needing to write files which are interpreted or compiled. Think maybe something like IRB for Ruby, but a system which is designed to let you write the whole program from the command line.

+6  A: 

Smalltalk can be programmed entirely interactively, but I wouldn't call the smalltalk prompt a "command line". Most lisp environments are like this as well. Also postscript (as in printers) if memory serves.

Are you saying that you want to write a program while never seeing more code than what fits in the scrollback buffer of your command window?

John Knoeller
I didn't think about it fitting into the scrollback buffer, but yes, I guess it would keep commands to a much smaller length.
Zubair
this is why you need introspection as well!
jk
+6  A: 

I assume you are looking for something similar to how BASIC used to work (boot up to a BASIC prompt and start coding).

IPython allows you to do this quite intuitively. Unix shells such as Bash use the same concept, but you cannot re-use and save your work nearly as intuitively as with IPython. Python is also a far better general-purpose language.

Edit: I was going to type up some examples and provide some links, but the IPython interactive tutorial seems to do this a lot better than I could. Good starting points for what you are looking for are the sections on source code handling tips and lightweight version control. Note this tutorial doesn't spell out how to do everything you are looking for precisely, but it does provide a jumping off point to understand the interactive features on the IPython shell.

Also take a look at the IPython "magic" reference, as it provides a lot of utilities that do things specific to what you want to do, and allows you to easily define your own. This is very "meta", but the example that shows how to create an IPython magic function is probably the most concise example of a "complete application" built in IPython.

Mike
I looked at the IPython web site but I could not see any examples of a complete application built using IPython. Do you have any links that could help me?
Zubair
I read the tutorials you mentioned, but it doesn't seem that trivial to create functions in IPython. It seems to save everything as a .py file
Zubair
I'm not sure how much more trivial you want an interactive function definition to be. You still have to write the code for it somewhere, and you can type it into the command line then same way you'd write it into a .py file. Try it, the python command line is very convenient.
Paul McMillan
Also of note is that the interactive shell is not limited to iPython. The standard c-python distribution also includes it.
Paul McMillan
+2  A: 

The only way to avoid writing any files is to move completely to a running interactive environment. When you program this way (that is, interactively such as in IRB or F# interactive), how do you distribute your programs? When you exit IRB or F# interactive console, you lose all code you interactively wrote.

Smalltalk (see modern implementation such as Squeak) solves this and I'm not aware of any other environment where you could fully avoid files. The solution is that you distribute an image of running environment (which includes your interactively created program). In Smalltalk, these are called images.

Tomas Petricek
Of course, the interactive shell would have to have built in version control to save your code.
Zubair
You would have a command like "make image", "make exe", or something like that to distribute your program
Zubair
@Zubar: What you're looking for doesn't exist because isn't useful or safe outside of a learning environment. Your "make image/exe" wish isn't very practical, how would you test your code? How would you fix the exe without re-keying the entire program again, which has the obvious dangers of introducing new bugs?
Binary Worrier
Hi Binary, what I meant was that you could redistribute the running program via an exe. But the source code remains in the interactive system. Is that even possible to do what I am saying?
Zubair
+2  A: 

There's always lisp, the original alternative to Smalltalk with this characteristic.

bmargulies
I checked on the web, but couldn't find much. How do I for example list all the functions I have created in lisp?
Zubair
That depends on which Lisp implementation you're using, Zubair. Fortunately and unfortunately, Lisp has lots of implementations, and several philosophically-driven variations (Scheme, Common Lisp, Emacs Lisp, etc.)
JasonTrue
Which is the most used Lisp which is interactive?
Zubair
I haven't made extensive use of Lisp for 20 years. In the day, all lisps had a way to save the universe, and various introspective ways of, e.g. listing functions. I'm afraid I can't help you with modern details except to suggest reading the common lisp standard.
bmargulies
+1  A: 

Most variations of Lisp make it easy to save your interactive work product as program files, since code is just data.

Charles Simonyi's Intentional Programming concept might be part way there, too, but it's not like you can go and buy that yet. The Intentional Workbench project may be worth exploring.

JasonTrue
+1  A: 

As already mentioned, Python has a few good interactive shells, I would recommend bpython for starters instead of ipython, the advantage of bpython here is the support for autocompletion and help dialogs to help you know what arguments the function accepts or what it does (if it has docstrings).

Carlos
ipython does that too.
Steve
Very cool, never heard of bpython before, I will check it out. It should be noted, however, that ipython also supports auto-completion and docstrings, although bpython definitely is prettier in that respect. It does _not_ look like bpython supports re-executing, editing, and saving "slices" of your command history like ipython does.
Mike
How does this differ to IPython? (in another answer to this question)
Zubair
How do you add functions in BPython?
Zubair
+1  A: 

This is really a question about implementations, not languages, but

  • Smalltalk (try out the Squeak version) keeps all your work in an "interactive workspace", but it is graphical and not oriented toward the command line.

  • APL, which was first deployed on IBM 360 and 370 systems, was entirely interactive, using a command line on a modified IBM Selectric typewriter! Your APL functions were kept in a "workspace" which did not at all resemble an ordinary file.

  • Many, many language implementations come with pure command-line interactive interpreters, like say Standard ML of New Jersey, but because they don't offer any sort of persistent namespace (i.e., when you exit the program, all your work is lost), I don't think they should really count.

Interestingly, the prime movers behind Smalltalk and APL (Kay and Iverson respectively) both won Turing Awards. (Iverson got his Turing award after being denied tenure at Harvard.)

Norman Ramsey
Intersting about smalltalk. I am looking for something that works from the command line, and optionally has a GUI, but that is not a must.
Zubair
+2  A: 

TCL can be programmed entirely interactivly, and you can cetainly define new tcl procs (or redefine existing ones) without saving to a file.

Of course if you are developing and entire application at some point you do want to save to a file, else you lose everything. Using TCLs introspective abilities its relatively easy to dump some or all of the current interpreter state into a tcl file (I've written a proc to make this easier before, however mostly I would just develop in the file in the first place, and have a function in the application to resources itself if its source changes).

jk
I almost always prototype my programs first in tkcon. Tkcon allows you to open a more friendly editor to edit functions by using the `edit` command.
slebetman
yes tkcon is certaily more freindly then the default console for a number of reasons e.g. syntax highlighting
jk
A: 

Any unix shell conforms to your question. This goes from bash, sh, csh, ksh to tclsh for TCL or wish for TK GUI writing.

mouviciel
Can you give an example of this? Haow does it compare to IRB or IPython for example?
Zubair
Which TCL implementation should I use?
Zubair
+1  A: 

Many Forths can be used like this.

kotlinski
+1  A: 

Someone already mentioned Forth but I would like to elaborate a bit on the history of Forth. Traditionally, Forth is a programming language which is it's own operating system. The traditional Forth saves the program directly onto disk sectors without using a "real" filesystem. It could afford to do that because it didn't ran directly on the CPU without an operating system so it didn't need to play nice.

Indeed, some implementations have Forth as not only the operating system but also the CPU (a lot of more modern stack based CPUs are in fact designed as Forth machines).

In the original implementation of Forth, code is always compiled each time a line is entered and saved on disk. This is feasible because Forth is very easy to compile. You just start the interpreter, play around with Forth defining functions as necessary then simply quit the interpreter. The next time you start the interpreter again all your previous functions are still there. Of course, not all modern implementations of Forth works this way.

slebetman
Which is the most popular Forth, I would like to try this.
Zubair