APL Object Notation

General APL language issues
Post Reply
paulmansour
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm

APL Object Notation

Post by paulmansour »

When you want to specify a data structure to send over the internet, JSON or JavaScript object notation is quite useful. You can specify objects, arrays, numbers and text. JSON was intentionally designed to work well with many languages and it maps easily to APL.

I find myself in the position of wanting to describe an APL data structure that I want to send over a Conga Command connection. I found myself trying to approximate JSON, and wrote this:

Code: Select all

:Namespace                                           
    Class←'DataTable' 
    Columns←:Array                                   
                :Namespace                           
                    Class←'DataColumn'               
                    Name←'First'                     
                    Type←'Char(9)'                   
                    Structure←1                     
                    Value←'Friedrich' 'Ludwig' 'Adam'
                :EndNamespace                       
                :Namespace                           
                    Class←'DataColumn'               
                    Name←'Last'                     
                    Type←'Char(5)'                   
                    Structure←1                     
                    Value←'Hayek' 'Mises' 'Smith'   
                :EndNamespace                       
                :Namespace                           
                    Class←'DataColumn'               
                    Name←'Age'                       
                    Type←'Int8'                     
                    Structure←1                     
                    Value←92 57 83                   
                :EndNamespace                       
            :EndArray                               
:EndNamespace


Now this is clearly not executable because :Array does not exist (but Phil Last has suggested maybe it should) and you can't create a unnamed namespace as a sub space in a namespace script. Also you can't assign the result :Namespace or :Array. The alternative to the above is APL code that creates namespaces, accumulates them in array, stuffs them into a var, etc. In other words, code, much of which all sorts of people would write totally differently.

In JSON this would be written as:

Code: Select all

{                                                      
    Class: "DataTable",                               
    Columns: [                                         
             {                                         
                 Class: "DataColumn",                 
                 Name: "First",                       
                 Type: "Char(9)",                     
                 Structure: 1,                         
                 Value: ["Friedrich", "Ludwig", "Adam"]
             },                                       
             {                                         
                 Class: "DataColumn",                 
                 Name: "Last",                         
                 Type: "Char(5)",                     
                 Structure: 1,                         
                 Value: ["Hayek", "Mises", "Smith"]   
             },                                       
             {                                         
                 Class: "DataColumn",                 
                 Name: "Age",                         
                 Type: "Int8",                         
                 Structure: 1,                         
                 Value: [92, 57, 83]                   
             }                                         
             ]                                         
}             


I wonder is it worth thinking about something like APLON (APL object notation)? Now since JSON maps nicely to APL, you can could just use JSON to describe the APL structure. This gives a limited set of APL functionality, but that is probably all you want when describing data structures going over the wire. Maybe not so limited, actually. But it is somewhat annoying that JavaScript has a more concise notation for an object than APL: {} vs :NameSpace :EndNamespace. Morten has suggested that [[]] might create a new empty namespace. This might go a long way. Perhaps then we could write something like as:


Code: Select all

[[
  Class←'DataTable
  Columns←[[ 
          Class←'DataColumn'
          Value←1 2 3
          etc
          ]]
          [[
          etc
          ]]
]]   


It would be nicer if there were a single character but I guess { and [ are used up. Just some thoughts for Version 20.
Post Reply