Friday, May 18, 2012

Resurrecting Object Curry - Part 4 : Managed or Native ?

As I mentioned in earlier posts Object Curry was a language I was designing so to speak in my college days (1996-1998) and that I am planning to resurrect it and make it more modern.

One important issue is whether object curry is "Managed" or "Native" ?
It is very hard question for me to answer correctly but lets just go back to source and see what were original thoughts.
As it often happens ideas about language turn into a platform and then into OS concepts.  So for a while I started calling Object Curry by various names like Component Mantra , OS Mantra and even the name Winix
Here are the original thoughts , I think many of the ideas are still valid...
I'll add commentary to the posts and ideas in my next post after the weekend. But for now just paste the original notes..so here you go straight from the source.

Virtual Machine for C.



Two stage architecture.




  Web Pointers for Distributed Computing !


Some object memory layout stuff
Final thoughts

  1. I think I will still go with the C virtual machine design. The "C pointers" here are garbage collectable.
  2. For now we'll just output C code (instead of C++11) and pretend there is VM that handles it.
  3. Support web pointers . 
  4. I have a set of hand written documents that tell why VM should not be low level but should have very high level instruction set. (so that linker-loader has more knowledge that it can use to optimize , something very relevant even today. )  I will go over it again...


Wednesday, May 16, 2012

Resurrecting Object Curry - Part 3 : New/Experimental Parsing Algorithm.

In part two I talked about using parsing strategy that is inspired from Generalized Phrase Structure Grammar.  In Object Curry compiler I am going to use a new and experimental strategy.

Separation of Immediate Dominance and Linear Precedence

In BNF form of grammar the production rules are given in the following manner
A ::= B C D
Where A is a parent and it can have three child nodes in that order.
However my parsing strategy will separate immediate  dominance and linear precedence.
To best of my knowledge no one has attempted to define parsing strategy and grammar specification as defined below..


Immediate Dominance : In simple terms it says A is the parent of B, C and D . It does not specify in which order  B, C, D should occur.
Eg Rule A--> B, C, D specifies that A can have three children

Linear Precedence : Specifies order in which children are. Orders can be partially specified
Eg Rule  B < C specifies that under A,  B must occur before  C

Head Identifying Rule: Each such production has exactly one head element and must occur in the production.
Eg.  ConditionalBlock ~ IfClause

if {} is valid
if {} else {} is valid
but else {} is not because the head is missing.


[place holder for the diagram]

Example is
QueryExpression --> SelectClause, WhereClause, FromClause.

With the separation of Dominance and Precedence all of following are valid production of the rules.

select * from tbl where col == 10;
from tbl where col ==10 select *;
...

Syntax Directed Translation and Attribute Value Calculation.

The values of attributes at each node in a syntax tree is calculated in following manner.
Synthesized attributes : Values of the parent is a function of values of its children.
Eg.  In expression   from x join y , the value of tuple type is determined by value of its children

Inherited Attributes: Attribute value is inherited from parents to the children.
In java like try catch block the closable variables are inherited.

Inferred attributes : The attributes are calculated using rules that are applicable to only nodes that have certain properties.

Algorithm
1. Variant of recursive descent for creating syntax tree.
2.  Topological sort based evaluation of dependency graph of attribute values.

I might stumble upon unexpected problem.

Useful References : 
[1] Generalized Phrase Structure Grammar by Gazdar,Klien, Pullum and Sag
 - Book about theory of natural languages!
 - chapter 3 , nature of grammatical rules.
[2] Compilers : Principles, Techniques and Tools by Aho, Sethi, Ullman
- the compiler book
- chapter 5,  Syntax directed translation.


Resurrecting Object Curry - Part 2 : To Write is to think

In my earlier post I indicated that I plan to resurrect "my" language Object Curry. The source of this "inspiration" was my handwritten notes that I have kept from college days.
Many of the writeups seem silly ( but sme are really interesting) and had some new ideas.
But what are these "notes" and why I have kept them for so long ?

To teach is to understand - To write is to think.
I have just too many teachers in my family. My grandma was a teacher , my father is a medical doctor and of course a head of the department in a medical college. My mom was a principal of  high school. My other grandma's sister was teacher. Both my uncles married  teachers and my other aunt married a english professor and one of my cousin ... well you get the point. Something like Marisa Tomei in My Cousin Vinny.
The point is that my father says that to teach is to really understand. When you teach something to someone, you benifit the most during the process. You aquire clearer , crisper and potentially profound understanding ...
Somewhere in my my highschool years I started writing notes for myself as if I am teaching it myself! That habit remained though out the college days and even trace of it today .
Though I am writing for myself my tone was always as if I am teaching class or writing a tutorial.

Putting your fuzzy thoughts in writting helps make them concrete, crystal clear and most importantly durable.

Language is defined by how it is used.
Any language is ultimately defined by how it is used and how it feels to program in it. So instead of defing a precise spec and BNF grammar I will just go with sketch of an idea. Language is what my compiler will implement it ! 
I have tried thousands of syntax variations on my whiteboard and every time I try something out I discover some problem with it.


What's the plan then ?
  1. I will go through with my old writeups and try to see what is still useful and what can be extended. May be create new write ups. Benefit: may be I'll come up with something cool. 
  2. Implement parser in at least three langauges ( one of  C#, java, Objective C) Benefit: I will practice parser writing and practice writing in 4 different dev environments.
  3. Write as many algorithms in Object Curry as you possibly can. (Graph colouring or k-mean or page rank etc) Benefit: Revise my algorithms ! Make my Object Curry truely useful.
Unless of course I take project some place else or come up with even better idea.

Ground Rules for Parser
I am going to use parsing strategy that is recursive descent styled. But a twist taken from Generalized Phrase Structure Grammar. where child nodes may not be ordered and where there are still partial ordering.

The parser will for now output C++11 source code for now. 

Resurrecting "Object Curry" - Part 1: SQL/NF and Datalog

In my college days I was working on a language called Object Curry. (Around 1996-1998).
As I was cleaning my stuff yesterday,  I came across treasure trove of large numbers of my handwritten notes from college days. That's where I found "specs" for my language "Object Curry ™".


Many of the ideas are still applicable and I have decided to write a compiler and updated spec for the language. I plan to use parsing strategy from natural languages called Generalized Phrase Structure Grammar.
If the output is sensible enough I'll take it further.


What's in the name ?
The name is derived from my attempt to mix object oriented programming with sql/nf like querying.
That sounded like a tasty Indian Curry. On top of it can claim connection to currying in functional programming.


Renovation of syntax
I actually found two syntax for the language on Pascal like and other C like.  But over the years I have kind of merged it look like below.
The syntax remains pascal inspired but with more curly braces than before.


class Foo
{
    public x : int;
    private y : char; //note reverse order and pascal like colon
    protected arr : int { 1, 2 ,3};
    public Fn(param:string): int 
    { ... }


}


SQL/NF
SQL NF is form of nested relational calculus first published in 1985 , it has nested tables and two new operators nest and unnest.
Here are some of the original hand written notes. These ideas are still valid and used in new version of Object Curry. 

  • Original Object Curry was an attempt to solve impedance  mismatch between querying collections using declarative syntax and still being able to use in memory data structures. (see this note or this one
  • The enum keyword from C++ is repurposed to create some amazing syntax possibilities including piping and sequence generation. Mixing C++ pointers, streaming and iterators there was some good facility for cursor management.
  • The dynamic queries were also a possibility.
I will blog about the new syntax and semantics very soon.


How is this different than LINQ?

  • "Discovered" or rather stumbled upon by me before C# and Linq.
  • Uses SQL/NF as its basis and does not have group by.
  • Not Library based but syntax based. Compiler knows a lot more about the underlying collections.
  • "Query plan" so to speak is decided at compile time.  
Integration with Datalog and Prolog.
I was very fascinated by possibility of Object Curry having some capabilities like Datalog and better integration with Prolog.
Here are some initial thoughts from my college days  

Am I being nostalgic or this has some practical applications?
I think the concepts and syntax elements in the Object Curry are still valid in the era of NoSQL, json, GPGPU and map reduce. Hopefully I am able to come up with a practically useful implementation.