Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. An editor
  2. Github account
  3. A pico engine

Install and run the

...

pico-engine

Prerequisite: you will need to install node (also known as Node.js) on your machine. Be sure that you are installing at least version 4. The installation includes npm, the node package manager, which you will use to install the pico engine. (Node.js is a trademark of Joyent, Inc. and is used with its permission. Picolabs is not endorsed by or affiliated with Joyent.)

...

Note that the web server displays the URL of its document root, ex. "http://localhost:8080" and then continues to run. As we will see later, messages will be logged to this console, so it is best not to close this command line window.

...

The Primary, or

...

Owner, Pico

During the pico engine initialization, it creates a primary pico, naming it "Owner Pico" and then registers three rulesets and installs two of them in the owner pico. These are the minimum required for running the pico and the developer UI. You can visit the developer UI, "My Picos", at the address on which the pico engine is listening.

...

Code Block
linenumberstrue
ruleset hello_world {
  meta {
    name "Hello World"
    description <<
A first ruleset for the Quickstart
>>
    author "Phil Windley"
    logging on
    shares hello
  }
 
  global {
    hello = function(obj) {
      msg = "Hello " + obj;
      msg
    }
  }
 
  rule hello_world {
    select when echo hello
    send_directive("say") with
      something = "Hello World"
  }
 
}

Overall Structure of a KRL Ruleset

A ruleset is enclosed by the "ruleset" The following describes parts of the ruleset shown above:

Line 1: A ruleset starts with the ruleset keyword, the ruleset identifier or RID, and curly braces, as shown above in lines 1 and 25a curly brace. In this case, the RID is "hello_world".

Lines 2-10: A ruleset usually contains a "meta" block giving information about the ruleset. This information includes information like the ruleset and any names which it "shares" name and author, as well as pragmas that affect the ruleset's behavior. For example, this ruleset has a shares pragma saying which global functions are shared with the outside world (including other rulesets). 

Lines 2-10.12-17: A ruleset usually contains a "global" block which globally binds values to names, some of which may be shared. Lines 12-17.In this case, the name "hello" is bound to a function value and is shared.

Lines 19-23: A ruleset usually contains one or more rules. Lines 19-23. In this case there is one rule named "hello_world" which will be watching for events with domain "echo" and type "hello".

Registering and Installing Your Ruleset

Registering a ruleset means to make it available to the pico engine, which compiles the KRL source code into JavaScript and caches this as a node module.

...