-
Notifications
You must be signed in to change notification settings - Fork 3
/
aliases.lisp
52 lines (46 loc) · 2.33 KB
/
aliases.lisp
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
;;;; SPDX-FileCopyrightText: Atlas Engineer LLC
;;;; SPDX-License-Identifier: BSD-3-Clause
(uiop:define-package #:njson/aliases
(:use #:common-lisp)
(:export
#:decode #:encode
#:get #:get* #:copy #:true #:truep #:true?
#:keys #:ensure-array #:ensure-object
#:if #:when #:or #:and #:not
#:bind #:match
#:@)
(:shadow #:get #:rem #:if #:when #:or #:and #:not)
(:documentation "Short aliases for the regular njson functions.
Perfect with j: package-local-nickname, disastrous when :use-d."))
(in-package #:njson/aliases)
(loop for (alias original) in '((njson/aliases:decode njson:decode)
(njson/aliases:encode njson:encode)
(njson/aliases:get njson:jget)
(njson/aliases:get* njson:jget*)
((setf njson/aliases:get) (setf njson:jget))
(njson/aliases:copy njson:jcopy)
(njson/aliases:true njson:jtruep)
(njson/aliases:truep njson:jtruep)
(njson/aliases:true? njson:jtruep)
(njson/aliases:keys njson:jkeys)
(njson/aliases:not njson:jnot)
(njson/aliases:ensure-array njson:ensure-array)
(njson/aliases:ensure-object njson:ensure-object))
do (setf (fdefinition alias) (fdefinition original))
unless (listp alias)
do (setf (documentation alias 'function) (documentation original 'function)))
(loop for (alias original) in '((njson/aliases:if njson:jif)
(njson/aliases:when njson:jwhen)
(njson/aliases:or njson:jor)
(njson/aliases:and njson:jand)
(njson/aliases:bind njson:jbind)
(njson/aliases:match njson:jmatch))
do (setf (macro-function alias) (macro-function original))
unless (listp alias)
do (setf (documentation alias 'function) (documentation original 'function)))
(defun @ (object &rest keys)
"Alias for `jget' that indexes OBJECT with KEYS.
Setf-able."
(njson:jget keys object))
(defun (setf @) (value object &rest keys)
(setf (njson:jget keys object) value))