Skip to content

Commit

Permalink
Remove undefined from all the code.
Browse files Browse the repository at this point in the history
There's no undefined in JSON. There shouldn't be any in the library
either.
  • Loading branch information
aartaka committed Oct 6, 2023
1 parent 286ff68 commit 1a8ef49
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 14 deletions.
3 changes: 1 addition & 2 deletions backend/cl-json.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ such tokens is :SYMBOL)."
`(let ((json::+json-lisp-symbol-tokens+
'(("true" . t)
("false" . nil)
("null" . :null)
("undefined" . :undefined)))
("null" . :null)))
(json:*object-scope-variables* '(json:*internal-decoder* *json-object-accumulator* *json-last-object-key*))
(json:*beginning-of-object-handler* #'json-object-init)
(json:*object-key-handler* #'json-object-add-key)
Expand Down
9 changes: 4 additions & 5 deletions functions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ OBJECT can be JSON array or object, which in Lisp translates to
(defgeneric jcopy (object)
(:method ((object real)) object)
(:method ((object (eql :null))) object)
(:method ((object (eql :undefined))) object)
(:method ((object (eql t))) object)
(:method ((object null)) object)
(:method ((object string)) object)
Expand Down Expand Up @@ -268,12 +267,12 @@ If the OBJECT is not a JSON array/object, throws `non-indexable'."))
(declare (ignore object))
t)
(:method ((object symbol))
(not (member object (list nil :null :undefined))))
(not (member object (list nil :null))))
(:documentation "Test OBJECT for truthiness in JSON terms.
Recognize all the values true, except for null, undefined, and
false. This is to make the transition from JSON to Lisp (3+ false
values -> 1 false value) smoother.
Recognize all the values true, except for null and false. This is to
make the transition from JSON to Lisp (2 false values -> 1 false
value) smoother.
Unlike JavaScript, empty strings and zero are not false (because this
behavior is confusing)."))
Expand Down
4 changes: 2 additions & 2 deletions macros.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ See more examples in njson tests."
(bindings (list)))
(labels ((parse-pattern (pattern &optional (current-path (list)))
(etypecase pattern
((or (member :true :false :null :undefined) string real)
((or (member :true :false :null) string real)
(push (cons pattern (copy-list current-path))
bindings))
((cons symbol *)
Expand Down Expand Up @@ -152,7 +152,7 @@ See more examples in njson tests."
(cons symbol (or (cons symbol null)
null))))
if (typep binding '(or array real null
(member :true :false :null :undefined)))
(member :true :false :null)))
collect `(,(gensym) (check-value ,binding (vector ,@key) ,form-sym))
else if (and (symbolp binding)
(uiop:emptyp key))
Expand Down
2 changes: 0 additions & 2 deletions njson.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ FROM can be a string, stream, pathname, or byte array.
Distinguishes between null/false and arrays/objects.
Decodes:
- null as :NULL,
- undefined as :UNDEFINED,
- false as nil,
- true as t,
- arrays as vectors,
Expand Down Expand Up @@ -88,5 +87,4 @@ TO can be:
Distinguishes between null and false.
Encodes:
- :NULL as null,
- :UNDEFINED as undefined,
- nil as false."))
3 changes: 0 additions & 3 deletions tests/tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
(assert-eql 8 (jcopy 8))
(assert-float-equal 1.3 (jcopy 1.3))
(assert-eq :null (jcopy :null))
(assert-eq :undefined (jcopy :undefined))
(assert-error 'error (jcopy :whatever))
(assert-eq t (jcopy t))
(assert-false (jcopy nil))
Expand Down Expand Up @@ -98,7 +97,6 @@
(assert-error 'non-indexable (jget 20 nil))
(assert-error 'non-indexable (jget 20 t))
(assert-error 'non-indexable (jget 20 :null))
(assert-error 'non-indexable (jget 20 :undefined))
(assert-error 'non-indexable (jget 20 200))
(assert-error 'non-indexable (jget 20 200.3))
(assert-error 'non-indexable (jget 20 "foo"))
Expand Down Expand Up @@ -129,7 +127,6 @@
(assert-equalp #(t) (ensure-array t))
(assert-equalp #(nil) (ensure-array nil))
(assert-equalp #(:null) (ensure-array :null))
(assert-equalp #(:undefined) (ensure-array :undefined))
(assert-equalp #(8) (ensure-array 8))
(assert-equalp #(1.3) (ensure-array 1.3))
(assert-equalp #(1.3 "foo") (ensure-array #(1.3 "foo")))
Expand Down

0 comments on commit 1a8ef49

Please sign in to comment.