Wednesday, March 28, 2012

Java to ActionScript (via Perl)

#!/usr/bin/perl

while(<>)
{
   s/\bfinal//;
   s/\b(int|long) (\w+)/ var $2:int/;
   s/\bboolean (\w+)/ var $1:Boolean/;
   s/\bString (\w+)/ var $1:String/;
   s/System.out.println/trace/;

   s/ (void|int|String) (\w+\(.*?\))/ function $2:$1/;


   print;
}


The Commodore 1541 disk drive is a computer, with a 6502 microprocessor and its own RAM.  It talks to the Commodore 64 via a hastily-built proprietary serial variant of the IEEE488 bus.

And it's a pain to emulate.

Luckily, it's a solved problem, more or less, if your chosen programming language is C++ or Java.  If you want to do it in, say, ActionScript, then you are out of luck.

...unless you know Perl.

ActionScript, as you may know, has a fuzzy relationship with Java.  Its compiler is written in Java.  Its VM may very well be based on the JVM.  So it is no surprise that ActionScript source is in many ways a cipher of Java.

I wrote a very small Perl script to convert Java source to ActionScript source.  It doesn't do a 100% job, but in all things the best is the enemy of the good, and the Burrito Principle holds (80% of the meat is in 20% of the burrito).  So this gets me most of the way there, leaving small scraps to deal with (instead of facing a complete and more tedious rewrite).

Saturday, March 24, 2012

I like Objective C

So far.  I'm not sure if it's as accessible as ActionScript, but I really appreciate its strict adherence to Design Patterns.  Just a few lessons in, and we've already done MVC and Delegates.

And, of course, I always loved the Smalltalk syntax.

Friday, March 2, 2012

Time for a new internet browser

Time to be an old grump for a moment.

I've said it before, I'll say it again.  It's time to rewrite the browser.  Invent, create, realize a new way of browsing the internet.

Forget HTML, JavaScript, FlashPlayer et al.  Computers are powerful; why aren't browsers?  Why can't you develop on the browser the same way you develop directly onto the operating system?  Why isn't there a virtual machine to which you may directly target compilers?  That way, you have your cake and can eat it, too.

I'm not saying the browser should be an operating system; it's an application.  However, it should integrate with operating systems.  For example, security is an OS problem; it should not be an application's problem.  Why solve the same problem over and over again?  There are realtime impacts to this: HTTP and HTTPS are heavy compared to TFTP.

I am saying that HTML is annoying.  I don't think HTML5 will solve that problem - at least, it won't solve it anytime soon.  HTML is to the browser like Java is to the OS: it's a language, a display and layout language.  It defines the View.

Thursday, February 23, 2012

CargoCult, part one

This is a post about my dream language, which I've named CargoCult.  It's a mashup of Perl, Objective-C, JavaScript, Shell, and other things.


It does NOT eschew the use of shifted characters -- it just requires that they be important, with a value greater than the extra effort of typing shift + something.


Object Notation

CargoCult is a dynamic object language.  This means you have type-able structures, potentially dynamic, which have attributes and methods.

Core language features -- arrays, hashes, variables -- are objects.  For example, the implicit array type is an object, so you can do things like this:

    return [d1, d2, d3].sort.reverse.pop; 


Hashes and arrays use the grouping notation of braces. An array is a comma-separated list of scalars.  A hash is a comma-separated list of assignments.

     my array = 1, 2, 3, 'four';  # also [ 1, 2, 3, 'four' ]
     my hash  = [year = 2012, month = two, day = 23];


Hash and array accesses are object calls.

    my value = hash.year;
    my other_value = array.0;


Method Calling with Parameters

When we write methods in any language, we typically name formal parameters.  For example:

string myFunction( foo, bar )
{
   foo + ': ' + bar;
}

foo and bar are formal parameters, i.e. the names used in the method.

When calling a method, parameters are passed in by name.  In other words, the parameters are more or less a hash.

my str = myObj myFunction .foo 'hello' .bar 'world';


When you have to nest the call, use the backslash to indicate a method call (rather than a new array), and then braces for grouping.

           my str = myObj myFunction .foo \[myObj myFunction .foo 'hello' .bar 'world'] .bar '!';






Thursday, October 13, 2011

YSON is a Structured Object Notation

Here's my proposed structure.  I want to keep the quotes to a minimum.

records:
[
    !record record:
    {
      !game &001 game:
      {
        date: 'March 2, 1962',
        versus: New York
      },
      notes: Awesome!,
      number: 100,
      !player &002 player:
      {
        name: Wilt Chamberlain,
        team: Philadelphia
      },
      record: Most points single game
    },
    
    !record record:
    {
        game: *001,
        number: 59,
        player: *002,
        record: 'Most points, one half'
    }
]


object
    hash

hash
    {}
    { pairs }

pairs
    key: value
    key: value, ...

key:
    string
    &id string
    !type string
    !type &id string
    
list
    []
    [ elements ]

elements
    value
    value, elements

value
    key
    string
    number
    object
    hash
    list
    true
    false
    null

Toward a common script grammar

It seems like scripting languages are slowly converging on a small number of common grammars and one structural data representation.


Common Grammars

The two common grammars are (1) simplified C and (2) Smalltalk.

More to the point, the simplification of C includes removing those pesky parentheses in control flow expressions.  I see them dropping everywhere, which I think is probably a good thing.

Anyway, it seems reasonable that most scripting languages' identities are bound by their feature sets and runtime details, rather than their basic grammar, and therefore it's only beneficial that they should converge.  Naturally it won't happen, but it would be nice.  

Alternately, it seems like an ideal scripting language would be able to understand many variants of C grammar, if only because the grammars are so closely related and are, essentially, representing solved problems Solved problems should not have variant grammars.


Common Structure

The structural data rep has little variations, but is essentially curly brackets to hold key-value pairs, a pair operator, and square braces to handle lists.  The data model is more powerful than JSON, and less powerful than YAML, but otherwise looks like them.  Call it JSON with references, or a strict, sane subset of YAML of scalars, lists, hashes, and references.  YSON, perhaps.

Seems that an ideal scripting language would therefore allow the user to specify the pair operator, key decoration, and value decoration.  Should take care of the major players.
 

Monday, October 3, 2011

Deneb sourcebook

...is crawling along, sometimes painfully slowly. But I'm still on schedule, thanks to giving myself lots and lots of time.  I'm currently working on "Fleets" - how duchies and smaller states in the sector squabble with each other by tradewar and skirmishings, and how they do it without provoking an Imperial response.