scheme shell

I needed the ability to hand-edit opencog data while other processes were running. And so I hacked with guile for a while, and now there’s a scheme shell for opencog.
So far it’s very simple: just say ‘scm’ at the opencog prompt; this puts you into the shell. Then you can scheme away.

So, fore example:

  (cog-new-node 'ConceptNode "some node name")

creates a new node:

  #<node[3:some node name] sti:(0,0) tv:(0.000000,0.000000)>

Well… I suppose the above looks like goobldy-gook. But it just says that its a new node with zero “short-term importance” (sti) and zero “truth value” (tv). It would be slicker if all this could be viewed visually, as a graph… the above would be just a single point, with a label.

Creating links is easy:

  (define x (cog-new-node 'ConceptNode "abc"))
(define y (cog-new-node 'ConceptNode "def"))
(cog-new-link 'Link x y)

which creates two new nodes (called ‘x’ and ‘y’) and a link connecting the two. Here’s the result:

  #<link[2 sti:(0,0) tv:(0.000000,0.000000) <[3 abc],[3 def]>]>

What’s slick about scheme is that it’s easy to add a bit of syntactic sugar to make link and node creation even easier. So, for example, we can define some new functions:

  (define (concept x) (cog-new-node 'ConceptNode x))
(define (pred x) (cog-new-node 'PredicateNode x))
(define (listyl x) (cog-new-link 'ListLink x)) ; list is a reserved word in scheme
(define (evely x) (cog-new-link 'EvaluationLink x)) ; eval is a reserved word in scheme

and with this syntactic sugar:

  (evely (pred "eats") (listyl (concept "cat") (concept "fish")))

which creates the opencog graph:

  #<link[53 sti:(0,0) tv:(0.000000,0.000000) <[47 eats],link[13 sti:(0,0) tv:(0.000000,0.000000) <[3 cat],[3 fish]>]>]>

So I’m thrilled. I can finally create, edit and delete nodes on the fly, without having to write C++ code, compile it, etc. etc. Woo hoo!

About Linas Vepstas

Computer Science Researcher - Hanson Robotics
This entry was posted in Development and tagged , , , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.