http://duncan-cragg.org/blog/ What Not How - Posts tagged 'fjord' Duncan Cragg on Declarative Architectures Duncan Cragg /favicon.gif /favicon.ico All content including photos and images by Duncan Cragg. Copyright (c) Duncan Cragg, your rights preserved: see /CXL.html A Django Production. 2013-01-16T17:09:00Z http://duncan-cragg.org/blog/post/cyrus-2013/ Cyrus in 2013 2013-01-16T17:09:00Z 2013-01-16T17:09:00Z

Well that worked out pretty well: I have a 3D environment on Android programmed in a simple but powerful declarative language which I've called "Cyrus".

Cyrus basically uses JSON all the way through: from user interface and scene graph to rewrite rules, on the wire and on disk. The Cyrus programming language is essentially JSON itself, as JSON rewrite rules. I've reduced the noise of JSON in Cyrus by taking out redundant double-quotes, square brackets and commas. It looks very nice to me.   ...

Well that worked out pretty well: I have a 3D environment on Android programmed in a simple but powerful declarative language which I've called "Cyrus".

Cyrus basically uses JSON all the way through: from user interface and scene graph to rewrite rules, on the wire and on disk. The Cyrus programming language is essentially JSON itself, as JSON rewrite rules. I've reduced the noise of JSON in Cyrus by taking out redundant double-quotes, square brackets and commas. It looks very nice to me.

The Name Cyrus

Now, probably to everyone's confusion and annoyance, I'm always thinking of multiple names for the many things I create around the core principles I'm evangelising. And then changing them all the time!

So I decided to choose a single new name, "Cyrus", for everything, and will endeavour to stick with it this time... I got the name from playing around with the letters of 'cyberspace rules', but will probably claim it stands for "cyberspace rules updating state" or something, because that sounds more impressive.

One advantage of this name is that both academics and regular folk should be able to spell it!

So now NetMash and Fjord are the "Cyrus app" and the "Cyrus programming language" respectively; the Object Network is now just the Cyrus network - a Web of JSON.

Once I have rough consensus and running code, it'll all be exchanging data via the Cyrus Media Type - probably "text/cyrus" for the simplified form and "application/cyrus+json" for the noisy one.

The basic underlying model and architecture implemented in Cyrus are still called "Functional Observer" and FOREST, however.

The Future of Programming

Edd Dumbill has recently described how he sees the Future of Programming.

In that article, Edd offers five categories that he sees as forces driving this, which I'd paraphrase as: concurrency within and between machines; embedded and mobile hardware; data-oriented programming; end-user programming; simplifying the software stack.

I was pretty excited to read this, because it accurately describes the drivers behind Cyrus.

Cyrus in 2013

So I'm now going to spend 2013 explaining to everyone why Cyrus is the next programming language they should try out. And, like I said before, I mean everyone - from kids to grannies, via Business Analysts.

Cyrus is, of course, very new, but even while it's maturing this year, it will still be good for non-critical uses, such as prototyping - especially mobile or distributed apps and sketching out business rules - and for making little fun apps, maybe while learning to program.

Do join the Cyrus Google Group if you want to get involved in any way, or just post a comment below.

http://duncan-cragg.org/blog/post/empowering-the-world/ Empowering the World | NetMash 2012-08-17T11:11:00Z 2012-08-17T11:11:00Z

If you also think that hacking up 3D worlds on Android could be fun, then join me! Stuff you should expect to play with if you want to get involved includes Java, Android, OpenGL ES 2.0, 3D model creation, hyperlinked JSON and JSON rewrite rules. Creatives, evangelists and inspirers are also very welcome to get involved!

The idea is to make an app (NetMash) that lets people build, mash up, animate and program 3D worlds, shared online and all linked-up, Web-like.

Like creative-mode Minecraft, but adding easy in-world programming and shared online by default. Or maybe a bit like an open, distributed, generic, mobile Kodu (or here), for adults as well as children.

NetMash is intended to deliver creative empowerment to ordinary people. We professional software folk often get stereotyped as geeks, and the creative fun we often have dismissed as in some way unusual. That's a real shame, because such prejudice means that the other 99.9% of the world are simply missing out on the joy of experiencing the most creative and empowering activities humankind has yet invented.   ...

If you also think that hacking up 3D worlds on Android could be fun, then join me! Stuff you should expect to play with if you want to get involved includes Java, Android, OpenGL ES 2.0, 3D model creation, hyperlinked JSON and JSON rewrite rules. Creatives, evangelists and inspirers are also very welcome to get involved!

The idea is to make an app (NetMash) that lets people build, mash up, animate and program 3D worlds, shared online and all linked-up, Web-like.

Like creative-mode Minecraft, but adding easy in-world programming and shared online by default. Or maybe a bit like an open, distributed, generic, mobile Kodu (or here), for adults as well as children.

NetMash is intended to deliver creative empowerment to ordinary people. We professional software folk often get stereotyped as geeks, and the creative fun we often have dismissed as in some way unusual. That's a real shame, because such prejudice means that the other 99.9% of the world are simply missing out on the joy of experiencing the most creative and empowering activities humankind has yet invented.

Empowering Families

So, success for NetMash will be measured not just by the fun we're having building it, but more strictly by its first users: which will include my 10-year old daughter, my 13-year old daughter who has Williams Syndrome, their granny and their mum! My wife runs Relax Kids classes in primary schools, so maybe there's an opportunity there to introduce the creative joys of programming to a wider group.

That's my own little world, but I'd also like NetMash to reach people globally that would not normally get access to the creative empowerment of programming.

Empowering the Disenfranchised

Maybe Thoughtworks would be interested in using NetMash in schools that we have contacts with, maybe in a non-Western country where technology and education are often less freely available.

Mobile is already changing the lives of the hitherto disenfranchised, through greater access to communications, finance and healthcare. Before long, the inevitable arrival of super-cheap Android devices means fully global access to advanced, connected technology, and a global demand for all the opportunity that this brings.

I'd like NetMash to be a part of all that, whether it's for a boy in a one-room wooden school, or a girl in the school down the road. Or her granny.

picture

http://duncan-cragg.org/blog/post/fun-virtual-worlds-netmash/ Fun and Virtual Worlds | NetMash 2012-08-15T11:37:00Z 2012-08-15T11:37:00Z

I just re-read my article on the Universe Web. I think it's pretty good. Indeed, to be honest, "programming as Cyberspace building" is where my heart has always been, and I'm all about following my heart this year. Especially if it's more fun, for both myself and others! Or if it opens up new worlds to new people.

In contrast, I don't see "fun" in W3C or IETF activities. Indeed, there's recently been a number of examples of tension in that world, between stabilisation and innovation, idealism and pragmatism, Enterprisey and Webby. Interestingly, all those examples have a "2.0" flavour: HTML5 (Web 2.0), HTTP 2.0 and OAuth 2.0.

My own interests are rough consensus and running code; innovation and pragmatism. Webbiness not in the W3C sense - "Web" Services, Semantic "Web", "Web" Sockets, etc. - but in the sense of "the simplest thing that works". Which is the Web of HTTP (1.1), URLs, JSON and REST, or specifically my FOREST interpretation.

I crave the simple and powerful, the cool and the fun. Which ultimately leads to the kind of thing I was describing as the Universe Web. And to be honest, I'd like to write and code for me, not for my peers and colleagues or for my career.

So, to the pursuit of pure joy in place of compromise, I'll now be focusing my energies on the journey of evolving the NetMash Java server and Android app towards an online, open, hyperlinked virtual world that is programmable in-world by users using simple rules.

Stay tuned!

picture   ...

I just re-read my article on the Universe Web. I think it's pretty good. Indeed, to be honest, "programming as Cyberspace building" is where my heart has always been, and I'm all about following my heart this year. Especially if it's more fun, for both myself and others! Or if it opens up new worlds to new people.

In contrast, I don't see "fun" in W3C or IETF activities. Indeed, there's recently been a number of examples of tension in that world, between stabilisation and innovation, idealism and pragmatism, Enterprisey and Webby. Interestingly, all those examples have a "2.0" flavour: HTML5 (Web 2.0), HTTP 2.0 and OAuth 2.0.

My own interests are rough consensus and running code; innovation and pragmatism. Webbiness not in the W3C sense - "Web" Services, Semantic "Web", "Web" Sockets, etc. - but in the sense of "the simplest thing that works". Which is the Web of HTTP (1.1), URLs, JSON and REST, or specifically my FOREST interpretation.

I crave the simple and powerful, the cool and the fun. Which ultimately leads to the kind of thing I was describing as the Universe Web. And to be honest, I'd like to write and code for me, not for my peers and colleagues or for my career.

So, to the pursuit of pure joy in place of compromise, I'll now be focusing my energies on the journey of evolving the NetMash Java server and Android app towards an online, open, hyperlinked virtual world that is programmable in-world by users using simple rules.

Stay tuned!

picture

http://duncan-cragg.org/blog/post/benefits-native-web-mobile-apps-with-ots-netmash/ OTS: The Benefits of both Native and Web Mobile 2011-05-10T11:11:00Z 2011-05-10T11:11:00Z

The Web, in its purest form - declarative HTML and CSS documents, XML feeds - is mashable, linkable, sharable. It's easy to create documents that slot into the global Web and can be accessed on any device; accessed by just a simple link. Servers can easily scale through statelessness and cacheing.

Native Mobile Apps are fast and slick. They are intimate with the dynamic, interactive, tactile mobile user interface, intimate with the capabilities of the device and intimate with the domain of mobile: photos, locations, contacts, messages.

OTS is a simple, clean, powerful approach to delivering Mobile functionality and content that is designed to realise these benefits of both Native Apps and the Web.   ...

The Web, in its purest form - declarative HTML and CSS documents, XML feeds - is mashable, linkable, sharable. It's easy to create documents that slot into the global Web and can be accessed on any device; accessed by just a simple link. Servers can easily scale through statelessness and cacheing.

Native Mobile Apps are fast and slick. They are intimate with the dynamic, interactive, tactile mobile user interface, intimate with the capabilities of the device and intimate with the domain of mobile: photos, locations, contacts, messages.

OTS is a simple, clean, powerful approach to delivering Mobile functionality and content that is designed to realise these benefits of both Native Apps and the Web.

How OTS Works

OTS - Object Type Specifications - achieves this by defining open JSON object types for people, places, dates, photos, messages, feeds, lists, galleries, user interfaces, forms, maps, calendars, etc., all linked together into the Web.

These dynamic OTS objects are published or shared instead of native apps and instead of Web documents.

A native OTS mobile client for Android, iOS, etc. can then render those objects and allow the user to interact with them, using its understanding of what they mean to deliver a slick user experience.

The user will start with the link of an object to look at, then may see immediately-linked objects nested into the same view, perhaps summarised and/or with open/close sliders. Any linked object can be jumped to as the new top view. If an object being viewed updates, the view, or the corresponding part of the view, updates.

 

Your Journey

Indeed, you are an OTS object, that others can see, and that gives access to stuff you want to make public from your device, such as photos you've only just snapped, your current location if enabled, status and text messages, selected contacts, links of interest, etc. SMS and MMS will be mapped to OTS photo and message objects on your device.

Your user object and your shared stuff are automatically pushed to shared servers when you make them public or when they update. All of this could use contacts, photos, reviews, messages, etc., from your and others' Twitter, Facebook, Google, etc. accounts, adapted to OTS objects server-side.

Many applications can be built through simply wiring up some OTS objects. Indeed, you can do this yourself through the mobile client, including creating and publishing new objects and lists of existing objects. You can plot on a shared map any OTS object that has a location field, or lists of such objects all at once.

Such as lists of your contacts or friends - to watch your party on the map as it converges on the restaurant, perhaps. That restaurant may be publishing an OTS object describing its outdoor Jazz schedule this week, which can be plotted on a shared calendar along with the weather report objects, retrieved from another server. If you discover a list of review objects about the Jazz via an OTS search form, you can save the link and then instantly share it with your party.

If your friend takes a photo, you can instantly 'join them on the map' where they stand and chat about it - and the weather conditions they're experiencing. No need for them to upload to a photo-sharing site, with login and file finder dialogues, or for you to download and launch separate, unrelated chat, photo-sharing, map and weather apps.

 

Programming OTS in Fjord

None of the above would need any code to be downloaded and run on the device. It's interesting to notice just how much can be achieved simply by leveraging the client's understanding of the object semantics, and through generic declarative interactions with points in the dynamic Web of OTS objects. With object cacheing, once the objects needed have been seen once, the user can still use them when the network breaks, alongside the on-board objects.

Obviously, being able to run programs on the device would open up an even wider range of applications, including giving greater tolerance of network outages for object behaviours that would otherwise be run on remote servers. But so far, everything has been declarative; how do we avoid having to go back to writing code in imperative Java or Javascript?

Well, being based on the FOREST architecture, OTS would use Fjord as its declarative programming language. And Fjord is just another OTS JSON object type, that can be fetched along with the objects it animates, for on-device program execution.

Server-side, again, so much can be achieved simply by publishing OTS objects, and adapting existing services. For more interactive applications, behaviour could be programmed in Java, etc., against a FOREST declarative API, or again in Fjord.

 

NetMash and Fjord Development

NetMash, as well as being the Java reference implementation for FOREST - networking, persistence, declarative API and Fjord implementation - is also an Android app that forms the reference implementation for OTS.

Fjord is very much in flux and hasn't been updated to the latest way FOREST works, but a version of it I built on Node.js has worked as expected. Based on that work, NetMash should have a Fjord implementation this year, which, being in Java, will thereby be available on both the Android client and the server side.

NetMash and OTS supercede all the other variants of these ideas I've been dabbling with before, including the Node.js implementations.

So, as always, it's all coming along slowly, and I can always use help with all this. Ping me via email (see left bar) if you want to be involved in the OTS Mobile Revolution!

 

Conclusion

Applications and content built with OTS don't need to be downloaded or updated via app-stores, and have no app boundaries - all applications can build on one another. They share one user, one map, one calendar, one combined view of the on-device and on-line world of interlinked, dynamic mobile objects from multiple sources. Your, and your friends', location, message, photo, list, contact and date objects are pushed and pulled automatically when made public or when they change.

As Martin Fowler points out, there is a gulf between native and Web applications on mobile that seems like an "uncanny valley" when you attempt to work within it by patching up the differences with hybrid technologies that pull too hard away from the respective comfort zones of pure native or pure Web.

Even so, there is a great deal of activity here, with multiple, evolving technology specifications to choose from. Into this discomfort zone I place technologies such as the HTML5 and related Javascript APIs, WAC, PhoneGap and Javascript toolkits that emulate native look and feel.

OTS is a clean alternative that effectively brings native and Web closer together, thus squeezing out this "uncanny valley" discomfort zone. Being both a native mobile app and a first-class player in the Web, OTS brings out the best of both, then goes beyond either.

http://duncan-cragg.org/blog/post/json-mash/ JSON-Mash 2010-03-18T16:58:00Z 2010-03-18T16:58:00Z

Around the middle of February I completed a basic persistence and networking implementation for Fjord, then had to do other things for a month. Just recently I fixed Fjord to work with the latest version of the Node.js APIs.

Next project: I'm going to use Fjord in a Web Framework to be called "JSON-Mash".

I intend to show that JSON-Mash will be a great framework for rapidly building truly interoperable and truly scalable online and distributed functionality.

Here's how JSON-Mash will work.   ...

Around the middle of February I completed a basic persistence and networking implementation for Fjord, then had to do other things for a month. Just recently I fixed Fjord to work with the latest version of the Node.js APIs.

Next project: I'm going to use Fjord in a Web Framework to be called "JSON-Mash".

I intend to show that JSON-Mash will be a great framework for rapidly building truly interoperable and truly scalable online and distributed functionality.

Here's how JSON-Mash will work.

Juggling Data Formats

In traditional Web Frameworks, the developer has to juggle up to five different data formats.

At the front end, you may be working in HTML or HTML chunks sent via Ajax. Then your domain logic may use object classes. You'll no doubt map those objects to relations in your database layer. That's three data representations (also known as Circles, Triangles and Rectangles).

But there may be even more: if you call out to integration points such as a search service or other API, you'll probably be using XML. And if you did application-level cacheing, you would probably consider casting your data into key-value form.

This is not unrealistic - at a current ThoughtWorks client, I was faced with exactly these five data formats - in an extremely simple application.

 

JSON Everywhere

JSON-Mash will do away with all that. It uses JSON objects everywhere.

JSON-Mash sends JSON data to a script in the browser that builds the page declaratively from its understanding of a number of stable, generic JSON types. It uses Ajax and Comet to pull JSON chunks in, to composite into the page.

JSON-Mash uses Fjord to process its JSON: transforms, map-reduce, etc. It uses Fjord to persist objects in a JSON NoSQL database, and Fjord to provide shared JSON cacheing functionality with cache updating via Fjord's FOREST integration style.

Finally, if there's any external system to be integrated, that too will be accessed via an adaptor that converts its API, etc., into JSON-Mash stabilised JSON. There will be Twitter and Flickr adaptors at first, I should imagine.

 

JSON-Mash and Fjord

Using Fjord means that JSON-Mash treats its JSON as a first-class hyperdata type: lots of little JSON chunks all with URLs and all linked up. I suggested that one day it may have the media type of "application/fjord+json". JSON-Mash Nodes communicate in the FOREST style.

Of course, the main benefit of using Fjord is that you get a great, declarative mashup language to describe your logic in.

Fjord is still very new, of course, so some goodness is yet to be rounded out. For example, it comes with a very basic, but highly improvable, NoSQL JSON datastore and already allows some powerful map-reduce and other query and transformation modes, with more to come.

Finally, Fjord gives a dynamic view of JSON data: caches get updates pushed into them and Comet pull will also come as part of the package.

 

CSI and SSI

Now, one of the great things about Node.js is that you can run the same code on the server as you run in the browser.

My previous attempts at doing things the JSON-Mash way have met with some resistance when I suggested building duplicate logic server-side to render pages statically, for accessibility and search engines.

But with Node, this problem goes away: you can use the exact same Javascript to convert JSON to HTML on the server side as you do on the browser.

I use the phrases 'Client-Side Include' and 'Server-Side Include' or CSI and SSI as easily-understood shorthand for this kind of page assembly from JSON elements.

Settling on a number of stable JSON types means that - once the types and their rendering are stable and coded - you never need to write any Javascript yourself in JSON-Mash. It's all done declaratively, and looks the same whether generated by an SSI Node or the CSI in the browser. For example, you can trigger calendars and maps in the browser view, with just small JSON declarations.

This approach differs from "progressive enhancement" as long as you have both full CSI and full SSI to render your site. But you could also have a 'CSI-SSI slider', where an initial page is generated by SSI, then CSI takes over to fill in the funky stuff: the dynamic widgets and Comet-driven elements.

 

Users Exploring a Dynamic Web of JSON

The way JSON-Mash works is that you get a view into a hyperlinked Web of JSON data, and can explore it from any point outwards. In the CSI version, each JSON chunk is loaded lazily as it is encountered, then reloaded when it changes. Even the SSI version of the site would allow this form of exploration, although in a less efficient and dynamic way, of course.

In JSON-Mash, the user is also a first-class object; the stable JSON types also include a type representing the user. This user is driving their browser, subscribing to events on visible JSON page components via Comet, and POSTing their own user state to a server-side cache copy.

Hence, if that user state contains a message, you can get simple chat functionality, without any code, just by linking to a user and viewing them.

 

Conclusion

JSON-Mash is a Web Framework that will use, re-use, assemble, mash, transform, store, share, push, pull and render JSON from end to end and top to bottom; from Ajax to NoSQL.

Most domain-logic programming will be done in simple, powerful declarative functions, with adaptors, drivers or renderers written in Javascript for Node.js or the browser. Cross-host exchange is done in the FOREST style.

SSI or CSI page assembly are very flexible ways of mashing up new functionality from multiple back-end sources of RESTfully-sourced, interlinked JSON data. And with cache updates telling SSI and CSI when the back-end data has changed, you get a very dynamic yet scalable system.

JSON-Mash will be a framework for rapidly building truly interoperable and truly scalable online and distributed functionality.

I'll write more on the benefits once I've got some code to prove it! Follow me on Twitter and I'll let you know when I've got something up on GitHub.

http://duncan-cragg.org/blog/post/fjord-in-memory/ Fjord in Memory 2010-01-26T13:46:00Z 2010-01-26T13:46:00Z

Right, I'm pleased to say that I've now implemented enough of the Fjord language on Node.js to be able to run the Instrument example that I introduced it with. As yet, this runs in memory only - i.e., no disk, no network.

Here's the code on GitHub with tests that show how it works. The language has changed a little so I'll show the example here again, copied over from the test code, in order to explain the differences.   ...

Right, I'm pleased to say that I've now implemented enough of the Fjord language on Node.js to be able to run the Instrument example that I introduced it with. As yet, this runs in memory only - i.e., no disk, no network.

Here's the code on GitHub with tests that show how it works. The language has changed a little so I'll show the example here again, copied over from the test code, in order to explain the differences.

Starting with the instrument rules:

inrl1=WebObject.create('{ "tags": [ "equity", "instrument" ],'+
                       '  "%owid": "/$this/",'+
                       '  "%refs": { "tags": [ "equity", "bid" ],'+
                       '             "%owid": "/$bid/",'+
                       '             "on": "/$this/" },'+
                       '  "buyers": "/array/has($bid)/" }');
// -------------------------------------------------------------------
inrl2=WebObject.create('{ "tags": [ "equity", "instrument" ],'+
                       '  "%owid": "/$this/",'+
                       '  "%refs": { "tags": [ "equity", "ask" ],'+
                       '             "%owid": "/$ask/",'+
                       '             "on": "/$this/" },'+
                       '  "sellers": "/array/has($ask)/" }');

These are the rules that add - or, rather, ensure the presence of - referring bids and asks in the instrument's buyers and sellers lists. The big difference here is that referrers are now accessed through the '%refs' tag. Both '%refs' and '%owid' are available on all Fjord objects: %owid is the Object Web ID of the object, and %refs has a list of the OWIDs of all currently referring objects.

But, of course, you can't see the list or the OWIDs under %refs! This rule shows how Fjord can match single items to lists of items, and how it transparently jumps any OWIDs it comes across, to continue matching. In this case there is a pattern for a bid or ask object that refers to the instrument - notice the "on": "/$this/" match.

Every object in %refs must have some such link to the referred-to object that triggered the referral in the first place. This referrer becomes an observer: its rules are run again if any object it refers to changes.

More instrument rules:

inrl3=WebObject.create('{ "tags": [ "equity", "instrument" ],'+
                       '  "buyers":  { "price": "/$bids;number/" },'+
                       '  "bid-ask-spread": { "high-bid": "/number/max($bids)/" } }');
// -------------------------------------------------------------------
inrl4=WebObject.create('{ "tags": [ "equity", "instrument" ],'+
                       '  "sellers": { "price": "/$asks;number/" },'+
                       '  "bid-ask-spread": { "low-ask":  "/number/min($asks)/" } }');

These are the rules that set the bid-ask-spread of the instrument from the prices of the bids or asks in each list. It shows how, when a single match instance binds to a list, it can give a match set in any bound variables - here, '$bids' and '$asks' - which can then be reduced - here, using 'max()' and 'min()'.

The rules are now separated into two, as there was a historic first ever bug in public Fjord code: the original rule wouldn't match unless at least one buyer and one seller were present, and we're adding them one by one from scratch this time!

Here is the actual instrument object:

inst=WebObject.create('{ "tags": [ "equity", "instrument" ],'+
                      '  "long-name": "Acme Co., Inc",'+
                      '  "buyers": [ ],'+
                      '  "sellers": [ ],'+
                      '  "bid-ask-spread": { "high-bid": "10.0", "low-ask":  "20.0" } }',
                      [ inrl1, inrl2, inrl3, inrl4 ] );

Notice the list of rules that the object will be animated by: inrl1, etc., which are the rule object OWIDs, not the actual rule objects. The bid-ask-spread is set to some seed values.

On to bid and ask rules:

bidrule=WebObject.create('{ "tags": [ "equity", "bid" ],'+
                         '  "on": { "tags": [ "equity", "instrument" ],'+
                         '          "bid-ask-spread": { "high-bid": "/$hibid;number/" } },'+
                         '  "price": "/null/fix(2, $hibid * 1.10 )/" }');
// -------------------------------------------------------------------
askrule=WebObject.create('{ "tags": [ "equity", "ask" ],'+
                         '  "on": { "tags": [ "equity", "instrument" ],'+
                         '          "bid-ask-spread": { "low-ask": "/$loask;number/" } },'+
                         '  "price": "/null/fix(2, $loask * 0.90 )/" }');

Here we have rules for setting the price of a bid or an ask as a ratio of the instrument's bid-ask-spread numbers. These are not meant to be realistic business rules of course - they're for illustration purposes. The only real difference here is fixing the result to 2 decimal places, since Javascript was adding ugly rounding errors.

Now we go ahead and create two bids and two asks, pointing at the instrument by simply including its OWID:

bid1=WebObject.create('{ "tags": [ "equity", "bid" ], "on": "'+inst+'", "price": "" }', [ bidrule ]);
bid2=WebObject.create('{ "tags": [ "equity", "bid" ], "on": "'+inst+'", "price": "" }', [ bidrule ]);
ask1=WebObject.create('{ "tags": [ "equity", "ask" ], "on": "'+inst+'", "price": "" }', [ askrule ]);
ask2=WebObject.create('{ "tags": [ "equity", "ask" ], "on": "'+inst+'", "price": "" }', [ askrule ]);

This fires off all the rules and notifications .. and rules and notifications .. giving the final result:

exp=new WebObject('{ "tags": [ "equity", "instrument" ],'+
                  '  "long-name": "Acme Co., Inc",'+
                  '  "buyers":  [ "'+bid1+'", "'+bid2+'" ],'+
                  '  "sellers": [ "'+ask1+'", "'+ask2+'" ],'+
                  '  "bid-ask-spread": { "high-bid": "12.1", "low-ask":  "16.2" } }')
// -------------------------------------------------------------------
test.objectsEqual("Instrument example works", Cache[inst], exp);

Here the buyers and sellers correctly list the referring bids and asks, and the bid-ask-spread has been set to the values you get after two ratios are applied to the original seed numbers.

Rewrite rules are run on object construction, they're run whenever an object has a new referrer in its 'refs' list, and also whenever another object that's being referred to changes. The latter isn't exercised in this example, as all events are propagated by referral alone. The tests of Fjord have examples of the full Observer Pattern in operation.

 

Next Up

Now, this is living code, so it will no doubt be different again, soon. Watch this space, and follow me on Twitter, to keep up to date with developments.

Next, I'll be working on simple disk persistence of Fjord JSON objects and rules, followed by distribution in the FOREST style...

http://duncan-cragg.org/blog/post/fjord-node/ Fjord in Node 2010-01-06T17:03:00Z 2010-01-06T17:03:00Z

Well, I've put together the first few lines of Fjord, implemented on Node.js.

Here's the description on GitHub: Fjord is a language for expressing domain logic as match-rewrite functions over mashable JSON Web objects.

I'm developing Fjord very openly, in the hope someone out there will be interested in getting involved in helping guide its design and implementation. I suppose code speaks louder than blog posts.   ...

Well, I've put together the first few lines of Fjord, implemented on Node.js.

Here's the description on GitHub: Fjord is a language for expressing domain logic as match-rewrite functions over mashable JSON Web objects.

I'm developing Fjord very openly, in the hope someone out there will be interested in getting involved in helping guide its design and implementation. I suppose code speaks louder than blog posts.

It's going to be slow progress, with a wife, two kids, and Thoughtworks all together getting 99% of my life, but at least people will be able to keep up with what I'm trying to do... I only got the project started at all because I'm off sick right now!

Here's the GitHub link: http://github.com/DuncanCragg/Fjord.

Follow me on Twitter if you want all the latest news .. http://twitter.com/duncan__cragg

Oh - I was lying about FOREST being GET-only, that was just to engage the REST community, but since I got zero reaction from anyone I may as well admit that I intended FOREST to use POST all along - to push updated resources into subscriber caches as I have always done. Or to use long-GETs to pull them in. Both are tunnelling cache refreshes over HTTP. Neither are Official REST.

Cheers!