Prothon - A New Prototype-based Language
Ben Collins writes "Prothon is a new industrial-strength, interpreted, prototype-based, object-oriented language that gets rid of classes altogether in the way that the Self language does. It uses the sensible, practical syntax and add-on C module scheme from Python. This major prototype improvement over Python plus many other general improvements make for a clean new revolutionary breakthrough in language development. Prothon is simple to use and yet offers the combined power of Python and Self. Check out the first public pre-alpha release at prothon.org."
Prothon Description:
/* and */. This is useful for temporarily blocking out large blocks of code and inserting inline comments.
/*no response*/ or is_too_long:
.get_hdr(text): # define func "get_hdr" as attribute of self .text = text # attribute "text" loaded from local "text" .hdr = Mime
This document assumes a working knowledge of Python. Many features are described as differences to Python features. If you are new to Python, a good starting point can be found at www.python.org.
Comments
Standard Python comments using the # character work exactly the same in Prothon. Prothon also supports the C comment format of
# this line is a comment
x=5 # this is a trailing comment
if not rlst
Indentation is Tab-Only
Like Python, Prothon uses indentation to control the block structure of the program instead of block/end or {}. However, Prothon only allows tabs for indentation. Any space in an indent will cause an error. This allows each programmer to set the editor to show the tab width to whatever he pleases and the Python problems of mixed spaces and tabs cannot happen in Prothon. It also allows for minimum typing.
Line Continuation
A line can be continued by placing a backslash ( \ ) as the last character of a line as in Python. Also, any tab indent of more than one level deeper than the previous indent level will cause the line to be considered a continuation of the previous line, which is a new feature to Prothon. The automatic continuation of lines in comma separated lists found in Python is not allowed in Prothon because of parsing differences, but usually the auto-continuation from indents alleviates the need for this.
Note that you can put spaces after tabs when in an auto-continuation. This allows you to line up the continued line for appearance.
x = 1 + 2 + 3 + 4 + \
5 + 6 + 7 + 8 + 9 # backslash continuation
s = "this is a normal line \
this is a continuation" # backslash works in quotes
y = long_function_name() +
another_function_name() # extra indent continuation
z = function_name(variable_name_1, # this is legal in Prothon because
variable_name_2) # of extra indents, not commas
Variable Names and Scope (No more "self variable")
The syntax for a variable name (label) is the same as Python except that one exclamation mark is allowed at the end and only at the end. This usage should be reserved for functions that modify the object's content in place. This allows a function such as list.sort!() to return the modified list, which was not allowed in Python. One should ALWAYS use this naming convention for in-place modification functions to warn programmers.
Prothon has a very different concept of self than Python. Any and every object can be "self", whether the code is in a function or not. So the Python tradition of using the variable named "self" does not fit in Prothon. The next section shows how an object becomes the "self". For now just imagine that somehow there is always one special "self" object at any one time.
Prothon code needs a way to differentiate between local variables, attributes in the self our code is running on, and global variables (in Prothon, globals are attributes of the module running our code). Prothon is introducing a relatively new concept in order to make it very easy to know which of these three types of variable you are referring to. This is the use of character case. Just as Python pioneered the use of white-space (indentation) to control syntax, Prothon is using case to control syntax.
Local variables always start with a lower-case letter or underbar ( _ ). Global variables always start with an upper-case letter. Attributes in the self object are prefixed by a period ( . ), but the name of the attribute itself can start with any case.
def
Why a new language?
Python is a interpreted language with object-oriented features that is practical, powerful, and fun to program at the same time. Over time capabilities have been added to the core Python language, while compatibility with earlier versions has been maintained, and Python has became loaded with features, some quite complex. The metaclass is an example of a recent feature addition. Even Python experts admit that metaclasses are brain-achingly complex.
Prothon is a fresh new language that gets rid of classes altogether in the same way that Self does and regains the original practical and fun sensibility of Python. This major improvement plus many minor ones make for a clean new revolutionary break in language development. Prothon is quite simple and yet offers the power of Python and Self.
Prothon is also an industrial-strength alternative to Python and Self. Prothon uses native threads and a 64-bit architecture to maximize performance in applications such as multiple-cpu hosting.
What is Prothon like?
See a quick description of the Prothon language.
Take a look under the hood at how Prothon is implemented.
Summary of differences from Python.
Development status?
As of 3/04 Prothon exists as a pre-alpha interpreter with minimum capabilites, just enough to try out the language.
Summary of currently implemented functions. Known problems.
Tested platforms: i386-linux, , sparc-linux, sparc64-linux, i386-Win2K, i386-XP, Dual-Opteron-Win2K
Target Schedule:
7/04: Freeze core language specs (keywords, etc.)
10/04: Release version 0.1
Download
Stable (build 115) Source tarball (175 KB)
Stable (build 115) Windows executable zip file (400 KB)
Latest (probably broken) SVN access: svn://svn.prothon.org/prothon/trunk
Latest source view and tarball: http://www.prothon.org/viewcvs/trunk
How can I contribute?
(Mailing list)
For now, the biggest contribution you can make would be adding to the discussion of 0.1 features. Please join the mailing list. Of course helping with the coding effort is always welcome.
Credits
Language design & win32 coding: Mark Hahn
Linux/Unix coding: Ben Collins
- If you're using indentation for structure, then it's horribly confusing to allow both tabs and spaces. How many spaces is a tab worth? You could add a "tabsize=" variable to the core language, but you have to be able to parse a file before you can start evaluating it, so that would necessarily have to be an ugly hack.
- An (old) Python topic-of-heated-discussion was the relative merit of tabs vs. spaces. Setting one as the standard avoids the whole issue and lets everyone get back to work.
My only gripe is that out of the two choices, they picked the wrong one <ducks>.Dewey, what part of this looks like authorities should be involved?
Found a little example code inside the tarball, that shows what they mean by no classes:
.name = ""
.__init__(name): .name = name .hello() .
.hello(): .name
Emp_proto = Object()
with Emp_proto:
def
return
def
print "My name is:",
Emp_proto.hello()
emp = Emp_proto("Jim")
emp.hello()
As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
implementing classes, the OOP approach
The OOP approach isn't limited to the class based languages. Class based languages have traditionally been more popular. The only recent mainstream prototype based language I can think of is javascript.
Saying one is better than the other is only ever likely to generate an argument, they're just different.
Have a look here for the classic paper on the prototype based approach.
you're forgetting OOSQL (which is basically completely different) and all the various DBMS-particular languages like Oracle's PL/SQL
Other prototype languages. The only one (other than JavaScript) to attain some real use is NewtonScript (the language for the Apple Newton).
Okay, in a class-based language, inheritence is statically decided at compile-time. In a prototype-based language, inheritience is just another operation that can be done at run time. You don't define classes statically, with each object having a predefined class. Rather, you copy an existing object (in the process copyings its existing members) and add new members to it.
A deep unwavering belief is a sure sign you're missing something...
You can use regexp's if you use Postgres.
--AP
I wonder if the twist on being prototype based will catch on in the script world.
It already has. Javascript is also prototype-based.
Umm, that's what object orientation is. It is possible to write OO code in C. It's easier in a language like Objective-C, which provides syntactic constructs to help.
For a good explanation of OOP, read the beginning chapters of Stroustrup's `The C++ Programming Language'. He gives a good description of the difference between object oriented code (which can be written in almost any language) and code written in a language which supports object orientation.
I am TheRaven on Soylent News
Not improved - just as bad:
..."
"Like Python, Prothon uses indentation
Oh joy.
THL.
Keeping
Smalltalk uses and enforces this convention, and Smalltalk is an industrial strength language. This convention is really effective, makes sense, is consistent and intuitive. You should improve your culture before bashing gratuitously.
BTW right now we're all using a software that embeds a prototype-based object oriented language: JavaScript. If you want to grab the concept I suggest you give it a try (note that I'm talking about the language, which is fine, not about the library or the implementations, which mostly suck). That makes JavaScript, a prototype-based language, the most widely deployed scripting language in the world.
Everybody nowadays seem to think that classes are mandatory in a OO language. Nothing can be farther from the truth.
Don't learn about it from your officemate, or your college instructor, especially if they say they haven't used it in over ten years. You wouldn't believe the opinions of someone who learned C from K&R without upgrading their knowledge, would you?
Instead, start from places like the ALU web site or Cliki or Paul Graham's Lisp FAQ.
If you do this right, you will learn that computer languages:
are not inherently fast or slow - implementations are fast or slow, not languages
can be both dynamic and have good performance
can be cross-platform without swallowing POSIX whole
can have multiple inheritance without damaging your brain
can be object-oriented without being object-obsessed
If you like, you can quit as soon as you understand how static scoping and closures work - at least that way you will avoid the primary mistake in pretty much every recent scripting language.
There is a small risk you will become a SmugLispWeenie by doing this, so be forwarned.
To a Lisp hacker, XML is S-expressions in drag.
I used LISP back in the dark ages. Lighten up! Code is meant to be read by humans, and only incidentally for the computer to parse.
Actually, the quote is:
"Programs must be written for people to read, and only incidentally for machines to execute."
- H. Abelson and G. Sussman (in "The Structure and Interpretation of Computer Programs)
For those not familiar with "The Structure and Interpretation of Computer Programs" it is one of the most famous introductory texts to computer science. All the code examples, of course, are written in Scheme...
PS: The full text is available here.
A deep unwavering belief is a sure sign you're missing something...
Not as powerful and simple as a relational language would be.
Leandro Guimarães Faria Corcete DUTRA
DA, DBA, SysAdmin, Data Modeller
GNU Project, Debian GNU/Lin
Getting new syntax into Python is tough. You have to write a PEP and submit it to the newsgroup where it will get picked on, critiqued, slandered, and trashed. Then, if it survives, months later it may get voted on, and given Guido van Rossum's official stamp of approval. And Guido is very hard to please! Given the nature of the changes in Prothon, it would have taken years to agree on anything. In most cases, this is a good thing because it keeps the language stable as opposed to changing every month.
Forking your own branch means you can do what you want. And I have a feeling Prothon's features wouldn't have made it into Python. IMHO.
Time is an illusion. Lunchtime doubly so. --Ford Prefect
Just so that non-Pythonistas don't get the wrong idea: Python doesn't restrict your identation that much: it only restricts you as to the *consistency* of your identation: i.e. if you use a tab for an outer for-loop and then 1 tab and 3 spaces inside that loop for an inner if-then block, that is fine by python; but if you switch to 6 spaces for the inner loop (i.e. no tab for the outer block), you will get a syntax error.
Python doesn't try to enforce a particular style of whitespace, just a consistent one, and I think that any professional programmer comes to appreciate that almost immediately.
It's added as a set of functions and operators, rather than existing in a separate language like pl/SQL. Consequently, you can use it just fine in the SELECT within PostgreSQL. E.g., to match all users with first_name being some variant of "John", you could do:
SELECT name FROM users WHERE first_name ~ '^Joh?(n|nathan)$';
The regexes have been even more supercharged as of 7.4 I believe. See here for more on it: PostgreSQL Pattern Matching
John C. Worsley - Artist, Musician, Coder
Portfolio
We already have perfectly good prototype-based programming in Python. Do a search for "metaclass programming in python" for links to my articles on this topic. You can do -everything- with Python metaclasses (which isn't to say you -should-).
But actually, prototype programming is even simpler:
new = old.__class__(init, args, here)
Just what 'old' is is determined at runtime. And if you like, you can poke around at 'obj.__bases__' to futz with inheritence.
Not having read my _Charming Python_ articles isn't really a sufficient reason to create a new programming language.
Buy Text Processing in Python
Check David McGoveran, Chris(topher) J Date, Fabian Pascal, Hugh Darwen, and BTW Eduard F 'Ted' Codd. Start at DMoz, then Google around...
Leandro Guimarães Faria Corcete DUTRA
DA, DBA, SysAdmin, Data Modeller
GNU Project, Debian GNU/Lin
It is already possible to do prototype-based programming in Python. Also in Perl. But the syntax may be a little awkward.
-- Ed Avis ed@membled.com