Archetype language

Jacob Carlborg doob at me.com
Mon Mar 21 06:00:31 PDT 2011


On 2011-03-20 18:36, bearophile wrote:
> Through I've found a link to a language I didn't know, named Archetype. This blog post contains some pointers and references about the language:
> http://dvanderboom.wordpress.com/2010/04/26/new-language-code-named-archetype/
>
> Some comments and quotations and notes about the language. Some of the things I write are already translated to a D-like syntax.
>
> Archetype is far from being finished. It's built on top of C# and shares many things with it. C# isn't a small language.
>
> Archetype looks designed to make handy practical/industrial high level coding with GUIs, databases, etc. Archetype seems to contain many pre-built high level features, even more than C#. D seems to focus to lower level features, smaller features that you combine in many more ways.
>
> ----------------------------------
>
> The idea of optional curly braces for functions with 1 expression inside (just a return):
> int foo(int x) return x * x;
> Instead of:
> int foo(int x) { return x * x; }

Like it.

> It is similar to a syntax like:
> foreach (x; 0 .. 10) y *= x;
> Instead of:
> foreach (x; 0 .. 10) { y *= x; }
>
> ------------------------
>
> In Archetype (and maybe C# too) delegates support the + and += operators. When you add two delegates, they get chained. When you call the result of the sum, both get called, in sequence. Probably this is handy to attach chains of callbacks to GUI elements.

As far as I know, in C#, this is only for events and not plain delegates.

> ------------------------
>
> Imports inside functions, etc.:
>
> void foo(int x) {
>      import std.stdio;
>      writeln(x * x);
> }

Like it.

> ------------------------
>
> There is a very short syntax to perform the simplest loops, here translated to D-like:
>
> foreach(10) {
> }
>
> ------------------------
>
> In Archetype, the exclamation point can be placed before the parentheses. It is the only part of the condition that can appear outside the parentheses.
>
> if !(expression)
>      statement;

Weird.

> ------------------------
>
> There is a form of pattern matching:
>
>
> var x = 1;
> var number = 4;
> match (number) {
>    x ->  number += 3;
>    3 | 5 ->  number++;
>    2 | 4 | 6..10 ->  {
>      number–;
>      Log("Numbers are getting too big");
>    }
> }
>
> ------------------------
>
> In Archetype if you have an Color enum, in some situations you don't need to write Color.Green, you are allowed to use just Green.
>
> ------------------------
>
> There are nullable types:
>
> int? x = 4;
> auto x? = 4;
>
> ------------------------
>
> There are tuples, used like this:
>
> (int, int) getMouseLocation() {
>      return (100, 50);
> }
>
>
> Or with named fields too:
>
> (x int, y int) getMouseLocation() {
>      return (100, 50);
> }

Like it.

>
> At the call site:
>
> auto (x, y) = getMouseLocation();
>
> ------------------------
>
> It has "Streams", that are iterators, very similar to the yield syntax sugar I have suggested:
> http://d.puremagic.com/issues/show_bug.cgi?id=5660
>
>
> yield(int) Numbers() {
>    yield 1, 2, 3;
>
> }
>
> Or even (I have kept the Archetype syntax here):
>
> yield(int) Numbers() {
>    yield 0..100 skip 5;
> }

Like it.

> ----------------------
>
> It has Pascal/Ada-style ranged numbers (I have kept the Archetype syntax here):
>
> // an int that can only have a value from 0 to 105
> type ValidAge int in [0..105];
>
>
> An anonymous subrange type, when you don't need to define the type:
> Age int in [0..105];
>
> ----------------------
>
> It has List Comprehensions (I have kept the Archetype syntax here):
>
> var FirstHundred = [ 1..100 ];
>
> var FirstHundred = from x in [ 1..100 ] where x*x>  3 select x*2;
>
>
> In my opinion the map/filter/reduce of Phobos2 have almost failed because their syntax is too much noisy and heavy, I don't want to see them used a lot in production code. Even in Python code map/filter/reduce are uncommon. Modern Python programmers use mostly lazy/eager sequence comprehensions. But I don't like the List Comprehensions syntax of Archetype.
>
> ----------------------
>
> In Ruby arrays (lists) support the - infix operator too, to remove the first item equal to the one given on the right of the minus sign (similar to the list.remove() method in Python). But this operator is not present yet in Archetype design.
>
> ----------------------
>
> A cute quote:
>
>> In my study of linguistics, I learned that legends like Noam Chomsky could learn hundreds of langauges; the previous librarian at the Vatican could read 97.<
>
> ----------------------
>
> There are ways to define infix binary operators (this is dangerous/troubled stuff):
>
> // "ABC" dup 3 == "ABCABCABC"
> binary dup string (left string, right int)
> return string.Repeat(left, right)
>
>
> Even infix spaces that mean something (there was a C++0x joke about this):
>
> // "123" "45" == "12345"
> binary adjacent string (left string, right string)
> return left + right;
>
>
> And just suffixes:
>
> // 12 minutes == TimeSpan.FromMinutes(12)
> unary suffix minutes TimeSpan (short, int)
> return TimeSpan.FromMinutes((int)value);
>
> ----------------------
>
> If not specified there is a default constructor, ad in D structs:
>
> class Foo {
>    string x;
>    int y;
> }
> void main() {
>    Foo f = new Foo("hello", 10);
> }
>
> Is this going to cause problems in D?
>
> ----------------------
>
> I have omitted several other things.
>
> (Just to be sure: with this post I am not proposing to add all that stuff to D2/D3. I like only part of the things I've shown.)
>
> Bye,
> bearophile


-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list