Skip to content
timrdf edited this page Mar 10, 2012 · 16 revisions

What is first

  • Running Ripple to get and run Ripple, so you can try out the commands on this page.

Let's get to it

Ripple's commands are procedural hooks which provide high-level access to the scripting environment. They allow you to get information about namespaces and graph contexts, to manipulate namespaces and to define new programs.

All commands have a name beginning with @. At the command line, you can obtain a list of the available commands by typing a '@' followed by a tab character:

1)  @

@help       @list       @prefix     @quit       @relist     @show
@unlist     @unprefix

Specific commands will be described in the following.

Managing namespaces

A namespace, in the sense of a QName or a CURIE, is a base URI for any number of other URIs. A namespace prefix stands in for a namespace, allowing you to use an abbreviated form of a URI like foaf:name instead of a full URI like <http://xmlns.com/foaf/0.1/name>.

The default namespace has an empty prefix and is defined in every environment. URIs abbreviated using the default namespace look like :this or :that. The programs which you define at the command line (see below) always go into the current default namespace, so you will see names like these very often.

An easy way to look up a single namespace is to specify the prefix, followed by a colon, and convert the URI thus indicated to a string, as in

1)  foaf: to-string.

  [1]  "http://xmlns.com/foaf/0.1/"^^xsd:string

2)  : to-string.

  [1]  "http://ripple.fortytwo.net/code/examples#"^^xsd:string

Also see the @show command (below), which will give you a complete list of prefix/namespace pairs.

@prefix

To define or redefine your own namespace prefixes, type @prefix followed by an abbreviated name and the full URI, e.g.

1)  foo: to-string.

Warning: prefix 'foo' does not identify a namespace

2)  @prefix foo: <http://example.org/foo/>
3)  foo: to-string.

  [1]  "http://example.org/foo/"^^xsd:string

4)  foo:bar to-string.

  [2]  "http://example.org/foo/bar"^^xsd:string

If you intend to deploy your programs on the Web of Data, you should redefine the default namespace, e.g.

1) @prefix : <http://example.org/myPrograms#>

@unprefix

You can use this command to undefine a previously-defined namespace prefix, e.g.

1)  @prefix foo: <http://example.org/foo/>
2)  @unprefix foo 
3)  foo: to-string.

Warning: prefix 'foo' does not identify a namespace

Defining lists and programs

In Ripple, as in many other functional programming languages, the most important data structure is the list. Anything you type in at the command line, which is not a command (i.e. doesn't begin with an @) is interpreted as a list. Everything you get back out of Ripple, which is not the output of a command, is also a list. Most of these lists serve a momentary purpose and then are never needed or seen again. However, some lists are special enough to be given a name and then re-used at some point in the future. This is the purpose of the following commands.

@list

The @list command allows you to define a list, give it a name, and store it away in RDF space (as an rdf:List) for future retrieval.

Some lists are simply used as data containers, e.g.

1)  @list days: "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"

You can dequote a list (appending it to the top of the program stack) with an application operator like the . operator:

2)  1 2 3 :days.

  [1]  1 2 3 "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"

...or you can manipulate it with list primitives, e.g.

3)  :days each. " morning" concat.

  [1]  "Sunday morning"
  [2]  "Monday morning"
  [3]  "Tuesday morning"
  [4]  "Wednesday morning"
  [5]  "Thursday morning"
  [6]  "Friday morning"
  [7]  "Saturday morning"

Other lists are full-fledged programs which transform the program stack by applying the mappings contained in the list. When you dequote the list, you execute the program. For instance,

1)  @list add-one: 1 add.
2)  100 :add-one.

  [1]  101

You can usually tell an active "program" from an ordinary list on account of the application operators (dots, question marks, and so on) in the list definition. However, there's no difference at the data level; programs are just lists of items, some of which are special and "do" things when they end up at the top of the program stack.

A list defined with @list (or @relist) is bound to a URI in the default namespace, where the defined name of the list is the local part of the URI. E.g.

1)  @prefix : <http://example.org/myPrograms#>
2)  @list hello: "Hello, World!"
3)  1 2 3 :hello.

  [1]  1 2 3 "Hello, World!"

4)  1 2 3 <http://example.org/myPrograms#hello>.

  [1]  1 2 3 "Hello, World!"

Parameterized lists

Although Ripple is a point-free language (i.e. uses no actual variables), it provides syntactic sugar for named parameters, which serve a similar purpose: they allow you write a program definition more concisely.

To define a parameterized list, include one or more parameter names before the local name of the list you're defining. For example,

1)  @list n triangle: n 1 add. n mul. 2 div.
2)  4 :triangle.

  [1]  10

That's ((n+1)*n)/2 in Ripple's postfix notation. The n parameter represents the topmost item on the program stack, which is popped off when the list is dequoted and then used twice in the body of the program.

Parameterized lists are translated into ordinary, point-free lists under the hood, so if you examine them with list primitives, you may find some unexpected items.

@unlist

If you no longer need a list (and you would like to get it out of your way), you can delete it using @unlist:

1)  @list tmp: 1 2 3
2)  :tmp rdf:first.

  [1]  1

3)  @unlist tmp
4)  :tmp rdf:first.

5)  

This has the effect of removing the RDF statements at the head of the list (i.e. rdf:type, rdf:first, and rdf:rest statements) so that the list is no longer accessible by its URI. The tail of the list (if any) remains intact, so this command might as well be called @behead.

@relist

This command is simply an @unlist followed by a @list. It allows you to over-write a previously defined list with a new definition (without thereby creating overlapping lists at the RDF level).

Other commands

@show prefixes

The @show command shows you detailed information about the environment. It takes one argument. When the argument is prefixes, it gives you a complete list of namespace prefixes defined in the scripting environment. By default, a large number of common prefixes are already defined (thanks to prefix.cc), for the sake of convenience:

1)  @show prefixes

[0] :              http://ripple.fortytwo.net/code/examples#
[1] abc:           http://www.metadata.net/harmony/ABCSchemaV5Commented.rdf#
[2] ac:            http://umbel.org/umbel/ac/
[...]
[546] zoology:     http://purl.org/NET/biol/zoology#

@show contexts

If you pass the contexts argument to the @show command, it will give you a complete list of Named Graph contexts in the scripting environment. If you have been crawling linked data, then this list could be very long. E.g.

42)  @show contexts.

[0] http://fortytwo.net/2008/01/webclosure#context
[1] http://www.w3.org/1999/02/22-rdf-syntax-ns
[2] http://ripple.fortytwo.net/code/examples
[3] http://www.w3.org/People/Berners-Lee/card

@help

The current implementation of @help is actually not very helpful. This wiki is more so.

Quitting Ripple

The proper way to exit the interactive environment is with the @quit command, i.e.

42) @quit

In many cases, it is OK to simply terminate the Ripple process (with Control+C or such) when you are done with it. However, if Ripple is connected to a triple store or other stateful resources which you would like to keep intact for a future session, then it is best to use @quit.

What is next