|
Re: Put a Flex UI On Your Application
|
Posted: Jun 26, 2007 2:56 AM
|
|
> > I would prefer a > > lean and mean programming language with as few > constructs > > as possible, instead of the behemoths we have today. > > If you were to imagine taking 6 months off to write it, > what would it look like? What would you implement it in? > Can you show some pseudocode for how it would handle SQL, > UI, performance optimizations, Web fu, etc.? > > (I'm honestly curious - I think if you started sketching > out the idea, it would be very interesting, at least to > some folks.)
UI (a login window):
function loginWindow username password = (Window text = "Login" layout = (Grid 2 3) children = [ (Label text="username:" alignment=RIGHT) (TextBox model=username) (Label text="password:" alignment=RIGHT) (TextBox model=password echo='*') (Button text="login" click={(close true)}) (Button text="cancel" click={(close false)}) ] ) let username = "" let password = "" let login = (do (loginWindow username password))
Any UI can be easily built by using functions laid out in hierarchical fashion.
SQL (a simple customers, products, sales schema):
let db = (Database "//localhost:1433/;username=sa" [ customers = (table [ id = (column AUTOINCREMENT) firstName = (column (VARCHAR 50)) lastName = (column (VARCHAR 50)) ]) products = (table [ id = (column AUTOINCREMENT) name = (column (VARCHAR 50)) price = (column MONEY) ]) sales = (table [ id = (column AUTOINCREMENT) customerId = (foreignKey customers.id) productId = (foreignKey products.id) date = (column DATETIME) ]) ] )
The above code does the following things:
1) it creates the DB schema at compile time. 2) it creates the structure 'db', which contains members 'customers', 'products' and 'sales', again, at compile time; each member of the above contains the necessary member for each column.
Here is a query:
let todaysSales = (select fields=[db.customers db.products] where=( db.sales.customersId == db.customers.id and db.sales.productId == db.products.id and db.sales.date == (getTodaysDate))) (forEach sale todaysSales {(print sale)})
The above code does the following things:
1) 'select' is a macro which accepts a tuple of columns and creates a function that, when evaluated at run-time, it will create an SQL string and submit it to the database. It also defines a struct with relevant fields, locally defined, which is the result of the query.
2) the struct members that are columns have overloaded operators so as that the boolean expression '==' creates an expression tree which, when evaluated, creates an SQL where expression.
3) when the code runs, the function behind 'select' creates a string from its parameters, and returns a list of records which have members named after the field names of the database.
The language syntax is very clean and easy:
1) parentheses mean 'evaluate function with optional parameters'. 2) square brackets mean 'tuples of values'. 3) curly brackets mean 'a lazily evaluated block of code'. 4) 'let' declares a variable in the local scope. 5) 'function' declares a function in the local scope.
Hierarchical schemas can be easily expressed. The above covers HTML, XML, DB schemas etc.
A macro mechanism which evaluates the code at compile time allows the developer to create the necessary infrastructure at compile time.
In fact, source code is nothing more than a set of macros evaluated at compile time, which create the program to run at run time.
This mechanism can be used for doing script jobs, without the need to either use XML or invent new tools and syntaxes. For example, java's ant is redundant, because the language can do anything at compile-time, and thus all that is required is writing the necessary program as a macro and compile it.
If anyone needs any other example, please feel free to request it.
|
|