-
Notifications
You must be signed in to change notification settings - Fork 225
/
opencog.scm
170 lines (155 loc) · 4.83 KB
/
opencog.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
;
; Main Atomese guile module
;
; When this module is loaded from the guile prompt, it sets up all of
; the Atomese infrastructure, including a default AtomSpace.
;
; To use, say this from the guile prompt:
; (use-modules (opencog))
;
;
; This should result in a utf8 locale being used!
; See https://github.com/opencog/opencog/issues/937
(setlocale LC_CTYPE "")
(setlocale LC_NUMERIC "C")
(define-module (opencog))
; When compiling this file, before any install has been made, a call to
; (use-modules (opencog as-config))
; will fail because (duh) it's not installed. So, instead, we manually
; hunt for it, and use the local build version. This is yet another
; hairy hack needed to be able to run unit tests without installing.
(if (resolve-module (list 'opencog 'as-config) #:ensure #f)
(use-modules (opencog as-config))
(load-from-path "opencog/as-config.scm"))
(load-extension (string-append opencog-ext-path-smob "libsmob") "opencog_guile_init")
; List everything to be exported from the C++ code i.e. from libsmob,
; as otherwise guile generates warnings about "possibly unbound variable"
; when these are touched in the various scm files.
(export
cog-add-atomspace
cog-arity
cog-atom
cog-atom?
cog-atom-less?
cog-atomspace
cog-atomspace?
cog-atomspace-clear
cog-atomspace-cow!
cog-atomspace-cow?
cog-atomspace-env
cog-atomspace-readonly?
cog-atomspace-ro!
cog-atomspace-rw!
cog-atomspace-uuid
cog-confidence
cog-count
cog-count-atoms
cog-equal?
cog-extract!
cog-extract-recursive!
cog-get-subtypes
cog-get-types
cog-handle
cog-inc-count!
cog-incoming-by-type
cog-incoming-set
cog-incoming-size
cog-incoming-size-by-type
cog-inc-value!
cog-keys
cog-keys->alist
cog-link
cog-link?
cog-map-type
cog-mean
cog-name
cog-new-ast
cog-new-atom
cog-new-atomspace
cog-new-link
cog-new-node
cog-new-value
cog-node
cog-node?
cog-number
cog-outgoing-atom
cog-outgoing-by-type
cog-outgoing-set
cog-set-atomspace!
cog-set-server-mode!
cog-set-tv!
cog-set-value!
cog-set-value-ref!
cog-set-values!
cog-subtype?
cog-tv
cog-tv-confidence
cog-tv-count
cog-tv-mean
cog-tv-merge
cog-tv-merge-hi-conf
cog-type
cog-type->int
cog-update-value!
cog-value
cog-value?
cog-value->list
cog-value-ref
cog-value-type
)
; Print C++ exceptions so that they are readable.
(define (cpp-exception-printer port key args default-printer)
(format port "Atomspace C++ exception:\n~A\n" args))
; set-exception-printer! is exposed by ice-9/boot-9
(set-exception-printer! 'C++-EXCEPTION cpp-exception-printer)
; Create a global to hold the atomspace ... to (try to) prevent guile
; GC from collecting it. Unfortunately, there appears to be a GC bug
; in guile-2.1 that causes this to be collected, anyway. Its as if
; guile forgets about this ... how? why? I don't get it.
;
; In various bad scenarios, the cogserver creates it's own atomspace,
; before the code here runs. We want to avoid creating a second
; atomspace as a result. The below tries to avoid problems by simply
; grabbing the existing atomspace, if there already is one.
;
; FIXME: Both of the above-described problems might no longer exist.
; I'm not sure. The below is simple and painless, I'm leaving it for
; now.
(define-public cog-initial-as (cog-atomspace))
(define-public my-as (cog-atomspace))
(if (nil? cog-initial-as)
(begin
(set! cog-initial-as (cog-new-atomspace))
; Initialize a default atomspace, just to keep things sane...
(cog-set-atomspace! cog-initial-as)))
; Renamed functions
(define-public (cog-as ATOM) "See cog-atomspace" (cog-atomspace ATOM))
(define-public (cog-extract ATOM) "See cog-extract!" (cog-extract! ATOM))
(define-public (cog-extract-recursive ATOM)
"See cog-extract-recursive!" (cog-extract-recursive! ATOM))
(define-public (cog-remove ATOM) "See cog-extract!" (cog-extract! ATOM))
; A very special association-list ctor.
(define-public (alist . x) (list 'alist x))
; Load core atom types.
(include-from-path "opencog/base/core_types.scm")
; Backwards-compat defines. I wish these were autogenerated,
; but they are not.
(define-public (TypeSet . x)
(apply cog-new-link (cons TypeIntersectionLinkType x)))
(define-public (TypeSetLink . x)
(apply cog-new-link (cons TypeIntersectionLinkType x)))
; Load other grunge too.
; Some of these things could possibly be turned into modules ...?
; ATTENTION: if you add a file here, then be sure to ALSO add it to
; ../opencog/guile/SchemeSmob.cc SchemeSmob::module_init() circa line 260
(include-from-path "opencog/base/core-docs.scm")
(include-from-path "opencog/base/atom-docs.scm")
(include-from-path "opencog/base/utilities.scm")
(include-from-path "opencog/base/atom-cache.scm")
(include-from-path "opencog/base/apply.scm")
(include-from-path "opencog/base/tv.scm")
(include-from-path "opencog/base/types.scm")
(include-from-path "opencog/base/file-utils.scm")
(include-from-path "opencog/base/debug-trace.scm")
; Obsolete functions
(define-public (cog-undefined-handle) "obsolete function" '())