Using the Python Interpreter as a Reference

Travis Parks jehugaleahsa at gmail.com
Mon Nov 21 19:07:45 EST 2011


On Nov 21, 12:44 am, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Mon, 21 Nov 2011 13:33:21 +1100, Chris Angelico wrote:
> > What's your language's "special feature"? I like to keep track of
> > languages using a "slug" - a simple one-sentence (or less) statement of
> > when it's right to use this language above others. For example, Python
> > is optimized for 'rapid deployment'.
>
> "Python will save the world"
>
> http://proyectojuanchacon.blogspot.com/2010/07/saving-world-with-pyth...
>
> --
> Steven

The language, psuedo name Unit, will be a low-level language capable
of replacing C in most contexts. However, it will have integrated
functional programming features (tail-end recursion optimization,
tuples, currying, closures, function objects, etc.) and dynamic
features (prototypical inheritance and late binding).

It is a hybrid between C#, C++, F#, Python and JavaScript. The hope is
that you won't pay for features you don't use, so it will run well on
embedded devices as well as on desktops - that's to be seen. I'm no
master compiler builder, here.

The functional code is pretty basic:

let multiply = function x y: return x * y # automatic generic
arguments (integer here)
let double = multiply _ 2 # short-hand currying - inlined if possible
let doubled = [|0..10|].Apply(double) # double zero through 10

The dynamic code is pretty simple too:

dynamic Prototype = function value: self.Value = value # simulated
ctor
Prototype.Double = function: self.Value * 2 # self refers to instance
new Prototype(5).Double() # 10
new Prototype(6).Double() # 12
dynamic x = 5 # five wrapped with a bag
x.Double = function: self * 2
x.Double() # 10
dynamic y = 6
y.Double = x.Double # member sharing
y.Double() #12

The language also sports OOP features like are found in Java or C#:
single inheritance; multiple interface inheritance; sealed, virtual
and abstract types and members; explicit inheritance; extension
methods and namespaces.

The coolest feature will be its generics-oriented function signatures.
By default everything is generic. You apply constraints to parameters,
rather than specific types. For instance:

let Average = function values:
    where values is ICountable<Integer32> IIterable<Integer32>
    assert values.Count > 0 "The values list cannot be empty."
    throws ArgumentException
    returns Float64
    let sum = 0
    for value in values:
        sum += value
    return sum / values.Count # floating point division

As you can see, the function headers can be larger than the bodies
themselves. They support type constraints, assertions (argument
checking), exceptions enumeration, default parameters and return type
information. All of them can be left out if the type of arguments can
be inferred.

This will not be an overnight project. :-)



More information about the Python-list mailing list