OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace commits / 7f4bf52

Get rid of scheme cog-extract! function
7f4bf523c605daa184e05073bc081a6232c37074
by Linas Vepštas <linasvepstas@gmail.com> · 2026-01-20T04:12:34.000Z

Changed files (5) +2 -116

opencog/guile/README.md +0 -47
……@@ -135,53 +135,6 @@ Example:
135135 (ConceptNode "def")
136136 )
137137
138=== cog-extract atom ===
139Delete the indicated atom, but only if it has no incoming links.
140
141Returns #t if the atom was deleted, else returns #f if not deleted.
142
143=== cog-extract-recursive atom ===
144Delete the indicated atom, and all atoms that point at it.
145
146Both functions return #t on success, else they return #f.
147If #f is returned, then the delete failed.
148
149Example:
150 ; Define two nodes and a link between them:
151 guile> (define x (ConceptNode "abc"))
152 guile> (define y (ConceptNode "def"))
153 guile> (define l (Link x y))
154
155 ; Verify that there's an atom called x:
156 guile> x
157 (Link
158 (ConceptNode "abc")
159 (ConceptNode "def")
160 )
161
162 ; Try to delete x. This should fail, since there's a link
163 ; containing x.
164 guile> (cog-extract x)
165 #f
166
167 ; Delete x, and everything pointing to it. This should delete
168 ; both x, and the link l.
169 guile> (cog-extract-recursive x)
170 #t
171
172 ; Verify that the link l is gone:
173 guile> l
174 Invalid handle
175
176 ; Verify that the node x is gone:
177 guile> x
178 Invalid handle
179
180 ; Verify that the node y still exists:
181 guile> y
182 (ConceptNode "def")
183
184
185138=== cog-atom? exp ===
186139Return #t if exp is an atom, else return #f
187140
opencog/guile/SchemeSmob.cc +0 -2
……@@ -286,8 +286,6 @@ void SchemeSmob::register_procs()
286286 register_proc("cog-atom", 1, 0, 1, C(ss_atom));
287287 register_proc("cog-node", 2, 0, 1, C(ss_node));
288288 register_proc("cog-link", 1, 0, 1, C(ss_link));
289 register_proc("cog-extract!", 1, 0, 1, C(ss_extract));
290 register_proc("cog-extract-recursive!",1, 0, 1, C(ss_extract_recursive));
291289
292290 // hash-value of the atom
293291 register_proc("cog-handle", 1, 0, 0, C(ss_handle));
opencog/guile/SchemeSmob.h +0 -2
……@@ -100,8 +100,6 @@ private:
100100 static SCM ss_node(SCM, SCM, SCM);
101101 static SCM ss_new_link(SCM, SCM);
102102 static SCM ss_link(SCM, SCM);
103 static SCM ss_extract(SCM, SCM);
104 static SCM ss_extract_recursive(SCM, SCM);
105103
106104 // Return the hash value of the atom.
107105 static SCM ss_handle(SCM);
opencog/guile/SchemeSmobNew.cc +0 -63
……@@ -695,67 +695,4 @@ SCM SchemeSmob::ss_link (SCM stype, SCM satom_list)
695695 return handle_to_scm (h);
696696}
697697
698/* ============================================================== */
699/**
700 * Extract the atom from the atomspace, but only if it has no incoming
701 * links. Return `SCM_BOOL_T` if the atom was successfully extracted,
702 * else return `SCM_BOOL_F`. This does NOT remove the atom from any
703 * attached backing store/persistent storage, only from the (local,
704 * in-RAM) atomspace.
705 */
706SCM SchemeSmob::ss_extract (SCM satom, SCM opt_as)
707{
708 // Don't use scm_to_handle here, because it clobbers handles
709 // that point at atoms that are in no space at all. Such a
710 // clobber prevents issuing the correct error message.
711 ValuePtr pa(scm_to_protom(satom));
712 if (nullptr == pa)
713 scm_wrong_type_arg_msg("cog-extract!", 1, satom, "opencog atom");
714
715 Handle h(HandleCast(pa));
716 if (nullptr == h)
717 scm_wrong_type_arg_msg("cog-extract!", 1, satom, "opencog atom");
718
719 const AtomSpacePtr& asg = get_as_from_list(opt_as);
720 const AtomSpacePtr& asp = asg ? asg :
721 ss_get_env_as("cog-extract!");
722
723 // AtomSpace::extract_atom() returns true if atom was extracted,
724 // else returns false.
725 bool rc = asp->extract_atom(h, false);
726 if (rc)
727 {
728 // Clobber the handle, too.
729 SCM_SMOB_VALUE_PTR_LOC(satom)->reset(); // std::shared_ptr<>::reset()
730 scm_remember_upto_here_1(satom);
731 return SCM_BOOL_T;
732 }
733
734 return SCM_BOOL_F;
735}
736
737/* ============================================================== */
738/**
739 * Extract the atom, and everything pointing to it.
740 * This does NOT remove the atom from any attached backing store, only
741 * from the atomspace.
742 */
743SCM SchemeSmob::ss_extract_recursive (SCM satom, SCM opt_as)
744{
745 Handle h = verify_handle(satom, "cog-extract-recursive!");
746
747 const AtomSpacePtr& asg = get_as_from_list(opt_as);
748 const AtomSpacePtr& asp = asg ? asg :
749 ss_get_env_as("cog-extract-recursive!");
750
751 bool rc = asp->extract_atom(h, true);
752
753 // Clobber the handle, too.
754 SCM_SMOB_VALUE_PTR_LOC(satom)->reset(); // std::shared_ptr<>::reset()
755 scm_remember_upto_here_1(satom);
756
757 if (rc) return SCM_BOOL_T;
758 return SCM_BOOL_F;
759}
760
761698/* ===================== END OF FILE ============================ */
opencog/scm/opencog.scm +2 -2
……@@ -52,8 +52,6 @@ cog-atomspace-ro!
5252cog-atomspace-rw!
5353cog-count-atoms
5454cog-equal?
55cog-extract!
56cog-extract-recursive!
5755cog-get-subtypes
5856cog-get-types
5957cog-handle
……@@ -122,6 +120,8 @@ cog-update-value!
122120
123121; Perform execution by triggering
124122(define-public cog-execute! TriggerLink)
123(define-public cog-extract! DeleteLink)
124(define-public cog-extract-recursive! DeleteRecursiveLink)
125125
126126; Misc old grunge.
127127(include-from-path "opencog/base/core-docs.scm")