Wishlist

githug edited this page Jun 27, 2012 · 9 revisions

On this page you can put your ideas about enhancements to clay.

Table syntax

Known from modern scripting languages like python (dictionaries) and lua, table syntax is very beloved and would be pleasing to have in clay as well. However, there seem to be quite some obstacles in the way because clay is a sytem-level language, and that means (at least):

  • Clay should not decide for a specific table implementation but leave the decision to the programmer, which implies that the implementation details are kept in modules and thus outside the language core.
  • The syntax though needs to refer to a well-defined set of overloadable functions (a protocol) that must be known to the language core and followed in the module.
  • The table protocol needs to take into account that table implementations can be more narrow or more complicated, more flexible or more straight. Though, the generic table syntax is only for declaring the table structure and assigning content. Further options should be available via functions and overloads on common operators (access to keys, etc.), which all goes into the table module.
  • The table syntax can be based on operators as well, but the operators must be treated special because:
    • There might be different overloads for static and runtime creation?
    • Do compile-time tables and their values need the keyword 'static'?
    • There are no good enclosing operators left, a re-use of {} would be nice.
    • Same for both the update and the extend operator, where =< and =<< would be nice.
    • The inner operators (for key/data-assignment) need a 'this-reference' to the declared/accessed table, which isn't available so.
  • What table operators are necessary?
  • What symbols can be used for the table syntax?
  • Another question is what is allowed to be written between the enclosing table operators beside keys, data and nested tables?
  • Are nested tables truly nested, and is this a pure implementation detail?

Am not shure of more yet except that clay could profit from table syntax though the implementation seems to be complicated, at least to me as a non-developer.

I'd also like to use the same syntax for both declaration and access. The typical access-syntax, the dot-notation, is a path-syntax invented for single/individual access but not for bulk updates. Some languages have a with-statement to at least spare the name of the table/object from the paths, but that's still uncomfortable (and somewhat over-engineered.) My idea looks like this:

// Assuming that {}, =< and =<< could be used for table syntax.
// The operators won't be available, I know!

// creating and initializing a new table
var table = { name = "duke" ; surname = "ofEarl" ; age:Int }

// updating and/or extending the table
table =< {
    age = 42;
    private = {
        shoes = "snake leather";
        drinks = "milk"
    }
}

// only extending the table
table.private =<< { haircut = "short" }

Something like that.