| … | … | @@ -135,53 +135,6 @@ Example: |
| 135 | 135 | (ConceptNode "def") |
| 136 | 136 | ) |
| 137 | 137 | |
| 138 | === cog-extract atom === | |
| 139 | Delete the indicated atom, but only if it has no incoming links. | |
| 140 | ||
| 141 | Returns #t if the atom was deleted, else returns #f if not deleted. | |
| 142 | ||
| 143 | === cog-extract-recursive atom === | |
| 144 | Delete the indicated atom, and all atoms that point at it. | |
| 145 | ||
| 146 | Both functions return #t on success, else they return #f. | |
| 147 | If #f is returned, then the delete failed. | |
| 148 | ||
| 149 | Example: | |
| 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 | ||
| 185 | 138 | === cog-atom? exp === |
| 186 | 139 | Return #t if exp is an atom, else return #f |
| 187 | 140 |
| … | … | @@ -286,8 +286,6 @@ void SchemeSmob::register_procs() |
| 286 | 286 | register_proc("cog-atom", 1, 0, 1, C(ss_atom)); |
| 287 | 287 | register_proc("cog-node", 2, 0, 1, C(ss_node)); |
| 288 | 288 | 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)); | |
| 291 | 289 | |
| 292 | 290 | // hash-value of the atom |
| 293 | 291 | register_proc("cog-handle", 1, 0, 0, C(ss_handle)); |
| … | … | @@ -100,8 +100,6 @@ private: |
| 100 | 100 | static SCM ss_node(SCM, SCM, SCM); |
| 101 | 101 | static SCM ss_new_link(SCM, SCM); |
| 102 | 102 | static SCM ss_link(SCM, SCM); |
| 103 | static SCM ss_extract(SCM, SCM); | |
| 104 | static SCM ss_extract_recursive(SCM, SCM); | |
| 105 | 103 | |
| 106 | 104 | // Return the hash value of the atom. |
| 107 | 105 | static SCM ss_handle(SCM); |
| … | … | @@ -695,67 +695,4 @@ SCM SchemeSmob::ss_link (SCM stype, SCM satom_list) |
| 695 | 695 | return handle_to_scm (h); |
| 696 | 696 | } |
| 697 | 697 | |
| 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 | */ | |
| 706 | SCM 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 | */ | |
| 743 | SCM 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 | ||
| 761 | 698 | /* ===================== END OF FILE ============================ */ |
| … | … | @@ -52,8 +52,6 @@ cog-atomspace-ro! |
| 52 | 52 | cog-atomspace-rw! |
| 53 | 53 | cog-count-atoms |
| 54 | 54 | cog-equal? |
| 55 | cog-extract! | |
| 56 | cog-extract-recursive! | |
| 57 | 55 | cog-get-subtypes |
| 58 | 56 | cog-get-types |
| 59 | 57 | cog-handle |
| … | … | @@ -122,6 +120,8 @@ cog-update-value! |
| 122 | 120 | |
| 123 | 121 | ; Perform execution by triggering |
| 124 | 122 | (define-public cog-execute! TriggerLink) |
| 123 | (define-public cog-extract! DeleteLink) | |
| 124 | (define-public cog-extract-recursive! DeleteRecursiveLink) | |
| 125 | 125 | |
| 126 | 126 | ; Misc old grunge. |
| 127 | 127 | (include-from-path "opencog/base/core-docs.scm") |