Add as-document manipulation routines
activitystreams/ontology.scm
66 | 66 | subproperty? | |
67 | 67 | subtype? | |
68 | 68 | as-ref | |
69 | + | as-document-set | |
70 | + | as-document-delete | |
71 | + | as-document-delete* | |
72 | + | ||
69 | 73 | json->as-document | |
70 | 74 | uri->as-document | |
71 | 75 | as-document->json | |
… | |||
144 | 148 | (cons (cons key value) lst) | |
145 | 149 | (cons (cons k v) (alist-set lst key value)))))) | |
146 | 150 | ||
151 | + | (define (as-alist-set lst key value) | |
152 | + | (match lst | |
153 | + | (() `((,key . ,value))) | |
154 | + | (((k . v) lst ...) | |
155 | + | (if (equal? (as-property-uri k) (as-property-uri key)) | |
156 | + | (cons (cons key value) lst) | |
157 | + | (cons (cons k v) (as-alist-set lst key value)))))) | |
158 | + | ||
159 | + | (define (as-alist-delete lst key) | |
160 | + | (match lst | |
161 | + | (() '()) | |
162 | + | (((k . v) lst ...) | |
163 | + | (if (equal? (as-property-uri k) (as-property-uri key)) | |
164 | + | lst | |
165 | + | (cons (cons k v) (as-alist-delete lst key)))))) | |
166 | + | ||
167 | + | (define (as-alist-delete* lst key) | |
168 | + | (match lst | |
169 | + | (() '()) | |
170 | + | (((k . v) lst ...) | |
171 | + | (if (subproperty? k key) | |
172 | + | (as-alist-delete* lst key) | |
173 | + | (cons (cons k v) (as-alist-delete lst key)))))) | |
174 | + | ||
147 | 175 | (define (merge-domains d1 d2) | |
148 | 176 | (uniq | |
149 | 177 | (if (list? d1) | |
… | |||
328 | 356 | document)))) | |
329 | 357 | (map cdr candidates))) | |
330 | 358 | ||
359 | + | (define (as-document-set document key value) | |
360 | + | (make-as-document | |
361 | + | (as-document-types document) | |
362 | + | (as-alist-set (as-document-properties document) key value))) | |
363 | + | ||
364 | + | (define (as-document-delete document key) | |
365 | + | (make-as-document | |
366 | + | (as-document-types document) | |
367 | + | (as-alist-delete (as-document-properties document) key))) | |
368 | + | ||
369 | + | (define (as-document-delete* document key) | |
370 | + | (make-as-document | |
371 | + | (as-document-types document) | |
372 | + | (as-alist-delete* (as-document-properties document) key))) | |
373 | + | ||
331 | 374 | (define (json->as-document ontology document) | |
332 | 375 | (define (uri->datatype type) | |
333 | 376 | (let ((candidates (filter (lambda (t) (equal? (as-type-uri t) type)) |