Compare commits
2 Enmetoj
ddc3add769
...
fdbda3672f
Author | SHA1 | Date | |
---|---|---|---|
Jaidyn Ann | fdbda3672f | ||
Jaidyn Ann | 8e58c7b1a4 |
|
@ -128,7 +128,7 @@ CLASS’es slots with JSON keys based on the camel-cased slot name."
|
||||||
This returns a function to create a quoted function that should be called for each slot,
|
This returns a function to create a quoted function that should be called for each slot,
|
||||||
again and again, by YASON:ENCODE-SLOTS."
|
again and again, by YASON:ENCODE-SLOTS."
|
||||||
(lambda (slot-key-pair)
|
(lambda (slot-key-pair)
|
||||||
`(let ((key ',(car slot-key-pair))
|
`(let ((key ',(car slot-key-pair))
|
||||||
(value (slot-value obj ',(car slot-key-pair))))
|
(value (slot-value obj ',(car slot-key-pair))))
|
||||||
(cond ((eq key '@context) ; Encoded in YASON:ENCODE-OBJECT using *@context*
|
(cond ((eq key '@context) ; Encoded in YASON:ENCODE-OBJECT using *@context*
|
||||||
(setq *@context* (merge-@contexts *@context* value)))
|
(setq *@context* (merge-@contexts *@context* value)))
|
||||||
|
@ -280,19 +280,20 @@ into one. Otherwise, parse it into an associative list."
|
||||||
;;; ————————————————————————————————————————
|
;;; ————————————————————————————————————————
|
||||||
;; Note-worthy: See the above-defined DEFINE-YASON-ENCODE-SLOTS.
|
;; Note-worthy: See the above-defined DEFINE-YASON-ENCODE-SLOTS.
|
||||||
(defmethod yason:encode ((obj object) &optional (stream *standard-output*))
|
(defmethod yason:encode ((obj object) &optional (stream *standard-output*))
|
||||||
(yason:encode-object obj))
|
(yason:with-output (stream)
|
||||||
|
(yason:encode-object obj)))
|
||||||
|
|
||||||
(defmethod yason:encode-object ((obj object))
|
(defmethod yason:encode-object ((obj object))
|
||||||
(typecase *@context*
|
(typecase *@context*
|
||||||
(null ; If this is the top-level (non-nested) object, establish a @context.
|
(null ; If this is the top-level (non-nested) object, establish a @context.
|
||||||
(let ((*@context* 'top-level))
|
(let ((*@context* 'top-level))
|
||||||
(yason:encode-object obj)))
|
(yason:encode-object obj)))
|
||||||
(symbol ; In the top-level, encode slots and then @context.
|
(symbol ; In the top-level, encode slots and then @context.
|
||||||
(setq *@context* (slot-value obj '@context))
|
(setq *@context* (slot-value obj '@context))
|
||||||
(yason:with-object ()
|
(yason:with-object ()
|
||||||
(yason:encode-slots obj)
|
(yason:encode-slots obj)
|
||||||
(yason:encode-object-element "@context" *@context*)))
|
(yason:encode-object-element "@context" *@context*)))
|
||||||
(T ; In nested objects, only encode slots — not *@context*.
|
(T ; In nested objects, only encode slots — not *@context*.
|
||||||
(yason:with-object ()
|
(yason:with-object ()
|
||||||
(yason:encode-slots obj)))))
|
(yason:encode-slots obj)))))
|
||||||
|
|
||||||
|
@ -301,10 +302,8 @@ into one. Otherwise, parse it into an associative list."
|
||||||
their sanitized string keys appropriate for ActivityVocabular custom.
|
their sanitized string keys appropriate for ActivityVocabular custom.
|
||||||
A class with slots MAP-AWAY and COLLECTION-AGAIN would return
|
A class with slots MAP-AWAY and COLLECTION-AGAIN would return
|
||||||
((MAP-AWAY . “mapAway”)(COLLECTION-AGAIN . “collectionAgain”))"
|
((MAP-AWAY . “mapAway”)(COLLECTION-AGAIN . “collectionAgain”))"
|
||||||
;; (alist-remove-keys
|
(alist-mapcdr #'camel-case
|
||||||
;; 'type
|
(class-slots-alist class)))
|
||||||
(alist-mapcdr #'camel-case
|
|
||||||
(class-slots-alist class)))
|
|
||||||
|
|
||||||
(defun merge-@contexts (a b)
|
(defun merge-@contexts (a b)
|
||||||
"Given two @context lists, A and B, merge them into one JSON-LD @context list
|
"Given two @context lists, A and B, merge them into one JSON-LD @context list
|
||||||
|
@ -356,12 +355,6 @@ items in each will be contained in the resultant list."
|
||||||
(mapcar (lambda (sym) (find-class sym))
|
(mapcar (lambda (sym) (find-class sym))
|
||||||
(find-registered-symbols str)))
|
(find-registered-symbols str)))
|
||||||
|
|
||||||
(defun alist-remove-keys (item alist &optional (test #'equal))
|
|
||||||
"Remove cells from an associative list whose key TESTs as ITEM."
|
|
||||||
(cl:remove item alist
|
|
||||||
:test (lambda (a cell)
|
|
||||||
(funcall test a (car cell)))))
|
|
||||||
|
|
||||||
(defun alist-mapcdr (function alist)
|
(defun alist-mapcdr (function alist)
|
||||||
"Apply a FUNCTION to all values (cdrs) of an ALIST’s pairs. Returns a new ALIST
|
"Apply a FUNCTION to all values (cdrs) of an ALIST’s pairs. Returns a new ALIST
|
||||||
of the same keys, whose values are the results of FUNCTION."
|
of the same keys, whose values are the results of FUNCTION."
|
||||||
|
|
Ŝarĝante…
Reference in New Issue