opencog-dev team mailing list archive
-
opencog-dev team
-
Mailing list archive
-
Message #00163
Re: OpenCog Shell
2008/5/25 Moshe Looks <madscience@xxxxxxxxxx>:
> Sorry to hear that swig didn't live up to expectations. How long ago
> was this? Its possible that things have improved since, as development
> seems fairly active...
Yes, my comments are indeed rather dated. I guess the thing
to do would be to go ahead and try it. I look forward to
status reports!
>> Myself, I'm partial to scheme+guile.
Being impatient, and also having a real need, I took a
couple of days, and whipped together a very simplistic
interface. It allows me to create new nodes, and delete them.
(I needed a shell for debugging, since some of my code
takes so long to run, that I'd rather hand-edit any mistakes,
than restart the code.)
README below ...
If anyone plans to use this besides me, let me know.
Scheme Scripting
----------------
Linas Vepstas, May 2008
This directory contains an implementation of the a Scheme shell for the
OpenCog server. Scheme is a dialect of Lisp; the shell allows scheme
code to manipulate the contents of an OpenCog AtomSpace. The shell
may be invoked by typing "scm" at the opencog prompt. Currently, only a
small number of primitives have been implemented.
This binding is intended to be used for day-to-day maintenance
activities, and for experimentation. it is not meant to be used for any
sort of serious calculation, simply because it is not (and cannot be) a
high-performance interface. The shell is implemented in guile; guile is
an interpreter, not a compiler. There is no bytecode or virtual machine.
Functions:
cog-new-node node-type node-name
Create a new node of the given type and name
Throws errors if node-type is not a valide atom type for a node,
and if node-name is not a string.
Example:
(cog-new-node 'ConceptNode "some node name")
creates a new node, and prints its value:
#<node[3:some node name] sti:(0,0) tv:(0.000000,0.000000)>
cog-new-link link-type atom-list
Create a new link, with the given atoms in the link.
Throws errors if the link type is not a valid opencog link type,
or if the list contains items other than atoms.
Example:
(define x (cog-new-node 'ConceptNode "abc"))
(define y (cog-new-node 'ConceptNode "def"))
(cog-new-link 'Link (list x y))
creates a new link, and prints it:
#<link[2 sti:(0,0) tv:(0.000000,0.000000) <[3 abc],[3 def]>]>
cog-atom handle
Reference the atom identified by the numeric handle
cog-handle atom
Return the handle of the atom
Example:
(define x (cog-new-node 'ConceptNode "abc"))
(define y (cog-new-node 'ConceptNode "def"))
(cog-handle x)
113
(cog-handle y)
114
(cog-atom 114)
#<node[3:def] sti:(0,0) tv:(0.000000,0.000000)>
cog-incoming-set atom
cog-outgoing-set atom
Return the incoming and outgoing sets, respectively, of the atom.
Example:
(define x (cog-new-node 'ConceptNode "abc"))
(define y (cog-new-node 'ConceptNode "def"))
(define l (cog-new-link 'Link (list x y)))
(cog-incoming-set x)
(#<link[2 sti:(0,0) tv:(0.000000,0.000000) <[3 abc],[3 def]>]>)
(cog-incoming-set y)
(#<link[2 sti:(0,0) tv:(0.000000,0.000000) <[3 abc],[3 def]>]>)
(equal? (cog-incoming-set x) (cog-incoming-set y))
#t
cog-delete atom
Delete the indicated atom, but only if it has no incoming links.
cog-delete-recursive atom
Delete the incoming atom, and all atoms that point at it.
Example:
(define x (cog-new-node 'ConceptNode "abc"))
(define y (cog-new-node 'ConceptNode "def"))
(define l (cog-new-link 'Link (list x y)))
(cog-delete x)
ERROR: In procedure cog-delete:
ERROR: Wrong type argument in position 1 (expecting atom with
empty incoming set): #<atom>
(cog-delete-recursive x)
nil
l
Invalid handle
x
Invalid handle
y
#<node[3:def] sti:(0,0) tv:(0.000000,0.000000)>
Note that x and the link l point to have been deleted,
but not the link y.
Follow ups
References