develooper Front page | perl.perl6.language | Postings from April 2005

Sun Fortress and Perl 6

Thread Next
Autrijus Tang
April 27, 2005 00:32
Sun Fortress and Perl 6
Message ID:
Fortress is Sun's project at making a next-generation computer language.
I like its technical report very, very much:
    (via )

Syntax aside (eg. their `=` and `:=` has the reverse meaning
in Perl 6), so far everything I'm seeing in it has a very close
correspondence to Perl 6, most notably the roles/traits system, use of
unicode symbols (see Appendix C for a cute way to transcribe unicode
programs in ASCII), and its creator's desire to make a language
optimized for evolvability.  Oh, and it has return type MMD. ;-)

There are a few things in that spec, though, that makes me wonder
if Perl 6 should have it too:


1. Type variables as role parameters

Fortress's List type is as this:

    trait List [T]
	first(): T
	rest(): List [T]
	cons(x: T): List [T]
	append(xs: List[T]): List [T]

Curiously, A12 and S12 already allows something like that:

    role List[Type $t] {
	method first() returns ::($t);
	method rest() returns List[::($t)];
	method cons(::($t) $x) returns List[::($t)];
	method append(List[::($t)] $xs) returns List[::($t)];

But I am not at all sure if this is the correct notation --
specifically, the "Type" type is not explained, and I'm not sure
how they are instantiated during the type checking phase at the
compile time.  Furthermore, I'm not sure that the ::($t) notation
is correct above.


2. Tuple types

    sub foo () returns (Int, Bool, Array) {

Currently per S09, Perl 6 collection types all have uniform types,
so one has to use the `List of Any` or `Array of Any` return type
instead.  That seriously hinders inference and typechecking; however,
I wonder if it is a design decision already made... :)


3. Labels applies to blocks, not statements

Instead of this:

	say "Hello!"
	say "Hi!"

One has to write this (essentially creating named blocks):

    LABEL: {
	say "Hello!"
	say "Hi!"

It makes sense because labels are frequently only used for block
control; the only thing that requires them at the statement level
is goto(), and you can still goto(LABEL) if you really want to.


4. Software Transaction Memory

Like GHC Haskell, Fortress introduces the `atomic` operator that takes a
block, and ensures that any code running inside the block, in a
concurrent setting, must happen transactionally -- i.e. if some
precondition is modified by another thread before this block runs
completely, then it is rolled back and tried again.  This slides covers
some aspects of STM as used in GHC:

In Fortress, there is also an `atomic` trait for functions, that
declares the entire function as atomic.

I mention this, instead of the more powerful automatic parallelization 
features, because STM can be retrofitted on any VM with boxed storage
types, while parallelization is a much harder problem that may not be
in Parrot's interest to tackle.


5. Macro model based on syntax expanders.

See section 3.4, "Support for Domain-specific Languages" in the
technical report.  For example, it allows:

    syntax sql exp end escape ~ = parseSQL(exp)

Which defines, in Perl 6 terms, a `macro prefix:<sql>` that allows
the ~ symbol as an escape clause:

    sub find_things (Field $thing) {
	sql {
	    SELECT description FROM
		SELECT ~$thing FROM things

The thing here is that all syntax error and type error is detected at
compile time, unlike the usual qq{} solution.


6. Database-indexed module management

An embedded database (such as SQLite) can be used to track different
revisions of installed modules on the local machine, manage upgrades,
check api compatibility, and keep related logs; see Chapter 4 for
details.  I have long wanted something like that for CPANPLUS, instead
of the current, limited, nonversioned, unrevertable, partial information
provided by .packlist files.


7. AST definition

Appendix A has "A Description of Fortress Abstract Syntax in Fortress
Concrete Syntax", which lays out the SyntaxTree class and all traits and
objects it may contain with Perl 6 concrete definitions.  I think this
will complement nicely with the Rule-based Perl 6 grammar file, as the
grammar itself does not neccessary contain AST information it generates.

Is there something like it that exists somewhere for Perl 6?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About