Update to guile-json-4

Julien LepillerTue Oct 06 04:27:51+0200 2020

176e8d7

Update to guile-json-4

guix.scm

4848
  (inputs
4949
   `(("guile" ,guile-3.0)
5050
     ("guile-gnutls" ,gnutls)
51-
     ("guile-json" ,guile-json-3)
51+
     ("guile-json" ,guile-json-4)
5252
     ("guile-rdf" ,guile-rdf)))
5353
  (native-inputs
5454
   `(("automake" ,automake)

jsonld.scm

5353
      ;; 4
5454
      (when (json-has-key? context "@context")
5555
        (set! context (assoc-ref context "@context")))
56+
      (pk expanded-input)
57+
      (pk context)
5658
      (let* ((base-iri (or (jsonld-options-base options)
5759
                           (and (jsonld-options-compact-to-relative? options)
5860
                                (string? input)

6466
             (inverse-context (inverse-context-creation active-context))
6567
             (compacted-output
6668
               (compaction active-context inverse-context
67-
                           #nil ;; active-property
69+
                           json-null ;; active-property
6870
                           expanded-input ;; element
6971
                           #:compact-arrays? (jsonld-options-compact-arrays? options)
7072
                           #:ordered? (jsonld-options-ordered? options)
7173
                           #:processing-mode
7274
                           (jsonld-options-processing-mode options))))
75+
        (pk 'compacted-output compacted-output)
7376
        (if (equal? compacted-output #())
7477
            (set! compacted-output '())
7578
            (when (json-array? compacted-output)

135138
          (context-processing active-context context-url context-url))))
136139
137140
    ;; 7
138-
    (let ((expanded-output (expansion active-context #nil document
141+
    (let ((expanded-output (expansion active-context json-null document
139142
                                      (if remote-document
140143
                                          (or (json-document-document-url remote-document)
141144
                                              (jsonld-options-base options))

149152
                         (not (equal? (car kv) "@graph")))
150153
                       expanded-output)))
151154
        (set! expanded-output (assoc-ref expanded-output "@graph")))
152-
      (when (equal? expanded-output #nil)
155+
      (when (json-null? expanded-output)
153156
        (set! expanded-output #()))
154157
      (unless (json-array? expanded-output)
155158
        (set! expanded-output `#(,expanded-output)))

jsonld/compaction.scm

5252
5353
(define* (compaction active-context inverse-context active-property element
5454
                     #:key (compact-arrays? #f) (ordered? #f) processing-mode)
55+
  (pk 'compaction element)
5556
  ;; 1
5657
  (let ((type-scoped-context active-context)
5758
        (def (term-definition-ref active-context active-property)))

7374
                                               #:ordered? ordered?
7475
                                               #:processing-mode processing-mode)))
7576
               ;; 3.2.2
76-
               (unless (equal? compacted-item #nil)
77+
               (unless (json-null? compacted-item)
7778
                 (set! result (cons compacted-item result)))))
7879
           (array->list element))
7980
         (set! result (reverse result))

9293
      ;; 4
9394
      (else
9495
        ;; 5
95-
        (when (active-context-previous active-context)
96+
        (when (not-null-or-false (active-context-previous active-context))
9697
          (unless (or (json-has-key? element "@value")
9798
                      (and (json-has-key? element "@id")
9899
                           (null? (filter (lambda (kp) (not (equal? (car kp) "@id")))

100101
            (set! active-context (active-context-previous active-context))
101102
            (set! inverse-context (inverse-context-creation active-context))))
102103
        ;; 6
103-
        (when (and def (term-definition-context def))
104+
        (when (and (term-definition? def)
105+
                   (not-null-or-false (term-definition-context def)))
104106
          ;; 6.1
105107
          (set! active-context
106108
            (context-processing active-context (term-definition-context def)

116118
                      (value-compaction active-context inverse-context
117119
                                        active-property element processing-mode)))
118120
                  (or (scalar? compact)
119-
                      (and def (equal? (term-definition-type def) "@json")))))
121+
                      (and (term-definition? def)
122+
                           (equal? (term-definition-type def) "@json")))))
120123
           (value-compaction active-context inverse-context active-property
121124
                             element processing-mode))
122125
          ;; 8

142145
                             (iri-compaction active-context inverse-context type
143146
                                             #:vocab? #t #:processing-mode processing-mode))
144147
                           types)))
148+
                  (pk 'compacted-types compacted-types)
145149
                  (for-each
146150
                    (lambda (term)
147151
                      ;; 11.1
148152
                      (when (and
149-
                              (term-definition-ref type-scoped-context term)
153+
                              (term-definition? (term-definition-ref type-scoped-context term))
150154
                              (term-definition-context
151155
                                (term-definition-ref type-scoped-context term)))
152156
                        ;; 11.1.1

182186
  (cond
183187
    ;; 12.1
184188
    ((equal? expanded-property "@id")
189+
     (pk 'expanded-value expanded-value)
185190
     ;; XXX: not clear what to do if expanded-value is not a
186191
     ;; string, make sure there is a test
187192
     (let ((compacted-value

191196
                 expanded-value))
192197
           (alias (iri-compaction active-context inverse-context expanded-property
193198
                                  #:vocab? #t #:processing-mode processing-mode)))
199+
       (pk 'compacted-value compacted-value)
200+
       (pk 'alias alias)
194201
       (set! result
195202
         (alist-set result alias compacted-value))))
196203
    ;; 12.2

206213
                (not compact-arrays?)))
207214
            (type-scoped-inverse-context
208215
              (inverse-context-creation type-scoped-context)))
216+
       (pk 'alias alias)
209217
       (if (string? expanded-value)
210218
           (set! compacted-value
211219
             (iri-compaction type-scoped-context type-scoped-inverse-context

217225
               (list->array 1
218226
                 (map
219227
                   (lambda (v)
220-
                     (iri-compaction type-scoped-context type-scoped-inverse-context
228+
                     (pk 'v (iri-compaction type-scoped-context type-scoped-inverse-context
221229
                                     v
222-
                                     #:vocab? #t #:processing-mode processing-mode))
230+
                                     #:vocab? #t #:processing-mode processing-mode)))
223231
                   expanded-value)))))
232+
       (pk 'compacted-value compacted-value)
224233
       (when (and (json-array? compacted-value) (= (array-length compacted-value) 1))
225234
         (set! compacted-value (car (array->list compacted-value))))
226235
       (set! result

234243
       (for-each-pair
235244
         (lambda (property value)
236245
           (let ((def (term-definition-ref active-context property)))
237-
             (when (and def (term-definition-reverse? def))
246+
             (when (and (term-definition? def) (term-definition-reverse? def))
238247
               (let ((as-array? (or
239248
                                  (member "@set"
240249
                                          (container-mapping active-context property))

248257
       (unless (null? compacted-value)
249258
         (let ((alias (iri-compaction active-context inverse-context "@reverse"
250259
                                      #:vocab? #t #:processing-mode processing-mode)))
260+
           (pk 'alias alias)
251261
           (set! result (alist-set result alias compacted-value))))))
252262
    ;; 12.4
253263
    ((equal? expanded-property "@preserve")

269279
         (equal? expanded-property "@value"))
270280
      (let ((alias (iri-compaction active-context inverse-context expanded-property
271281
                                   #:vocab? #t #:processing-mode processing-mode)))
282+
        (pk 'alias alias)
272283
        (set! result
273284
          (alist-set result alias expanded-value))))
274285
    (else

282293
                                 #:processing-mode processing-mode))
283294
               (def (term-definition-ref active-context
284295
                                         item-active-property))
285-
               (nest-term (if def (term-definition-nest def) #f))
296+
               (nest-term (if (term-definition? def) (term-definition-nest def) #f))
286297
               ;; 12.7.4
287298
               (nest-result result))
299+
          (pk 'item-active-property item-active-property)
288300
          ;; 12.7.2
289301
          (when nest-term
290302
            (unless (or (equal? nest-term "@nest")

310322
                     #:reverse? inside-reverse?
311323
                     #:processing-mode processing-mode))
312324
                 (def (term-definition-ref active-context item-active-property))
313-
                 (nest-term (if def (term-definition-nest def) #f))
325+
                 (nest-term (if (term-definition? def) (term-definition-nest def) #f))
314326
                 ;; 12.8.3
315327
                 (nest-result result)
316328
                 ;; 12.8.4

323335
                 ;; 12.8.6
324336
                 (compacted-item
325337
                   (compaction active-context inverse-context item-active-property
326-
                               (if (json-has-key? expanded-item 
327-
                                                  "@list")
338+
                               (if (json-has-key? expanded-item  "@list")
328339
                                   (assoc-ref expanded-item "@list")
329340
                                   (if (graph-object? expanded-item)
330341
                                       (assoc-ref expanded-item "@graph")
331342
                                       expanded-item))
332343
                               #:compact-arrays? compact-arrays?
333344
                               #:ordered? ordered?)))
345+
            (pk 'item-active-property item-active-property)
334346
            ;; 12.8.2
335-
            (when nest-term
347+
            (when (not-null-or-false nest-term)
336348
              (unless (or (equal? nest-term "@nest")
337349
                          (equal? (expand-key active-context nest-term) "@nest"))
338350
                (throw 'invalid-@nest-value))

376388
                 ((and (member "@id" container)
377389
                       (member "@graph" container))
378390
                  (let* ((map-object
379-
                           (or (assoc-ref nest-result item-active-property) '()))
391+
                           (or (not-null-or-false (assoc-ref nest-result item-active-property)) '()))
380392
                         (map-key
381393
                           (if (json-has-key? expanded-item "@id")
382394
                               (assoc-ref expanded-item "@id")

397409
                       (member "@index" container)
398410
                       (simple-graph-object? expanded-item))
399411
                  (let ((map-object
400-
                          (or (assoc-ref nest-result item-active-property) '()))
412+
                          (or (not-null-or-false (assoc-ref nest-result item-active-property)) '()))
401413
                        (map-key
402414
                          (if (json-has-key? expanded-item "@index")
403415
                              (assoc-ref expanded-item "@index")

471483
                                                       ((member "@id" container) "@id")
472484
                                                       (else "@type"))
473485
                                                     #:vocab? #t))
474-
                      (map-key #nil)
486+
                      (map-key json-null)
475487
                      ;; 12.8.9.3
476488
                      (def (term-definition-ref active-context item-active-property))
477-
                      (index-key (or (and def (term-definition-index def)) "@index")))
489+
                      (index-key (or (and (term-definition? def)
490+
                                          (term-definition-index def))
491+
                                     "@index")))
478492
                 (cond
479493
                   ;; 12.8.9.4
480494
                   ((and (member "@language" container)
481-
                             (json-has-key? expanded-item "@value"))
495+
                         (json-has-key? expanded-item "@value"))
482496
                    (set! compacted-item (assoc-ref expanded-item "@value"))
483497
                    (when (json-has-key? expanded-item "@language")
484498
                      (set! map-key (assoc-ref expanded-item "@language"))))

498512
                           (keys (if (json-array? keys)
499513
                                     (array->list keys)
500514
                                     (list keys)))
501-
                           (key (and (not (null? keys)) (car keys)))
515+
                           (key (and (not (null? keys)) (not-null-or-false (car keys))))
502516
                           (remaining (if key (cdr keys) '())))
503517
                      (when key
504518
                        (unless (string? key)

527541
                           (keys (if (json-array? keys)
528542
                                     (array->list keys)
529543
                                     (list keys)))
530-
                           (key (and (not (null? keys)) (car keys)))
544+
                           (key (and (not (null? keys)) (not-null-or-false (car keys))))
531545
                           (remaining (if key (cdr keys) '())))
532546
                      ;; 12.8.9.8.1
533-
                      (when key
547+
                      (when (not-null-or-false key)
534548
                        (set! map-key key))
535549
                      ;; 12.8.9.8.2
536550
                      (if (null? remaining)

550564
                            active-context inverse-context item-active-property
551565
                            `(("@id" . ,(assoc-ref expanded-item "@id")))))))))
552566
                 ;; 12.8.9.9
553-
                 (when (equal? map-key #nil)
567+
                 (when (json-null? map-key)
554568
                   (set! map-key (iri-compaction active-context inverse-context
555569
                                                 "@none" #:vocab? #t)))
556570
                 ;; 12.8.9.10

jsonld/context-processing.scm

4545
  (when (json-has-key? local-context "@propagate")
4646
    (set! propagate? (assoc-ref local-context "@propagate")))
4747
  ;; 3
48-
  (unless (or propagate? (active-context-previous active-context))
48+
  (unless (or propagate? (not-null-or-false (active-context-previous active-context)))
4949
    (set! result (update-active-context result #:previous active-context)))
5050
  ;; 4
5151
  (if (json-array? local-context)

5656
    (lambda (context)
5757
      (match context
5858
        ;; 5.1
59-
        (#nil
59+
        ((? json-null? null)
6060
         (unless (or override-protected?
6161
                     (null? (filter
6262
                              term-definition-protected?

155155
           (let ((value (assoc-ref context "@base")))
156156
             (cond
157157
               ;; 5.7.2
158-
               ((equal? value #nil)
159-
                (set! result (update-active-context result #:base #nil)))
158+
               ((json-null? value)
159+
                (set! result (update-active-context result #:base json-null)))
160160
               ;; 5.7.3
161161
               ((absolute-iri? value)
162162
                (set! result (update-active-context result #:base value)))
163163
               (else
164164
                 (let ((iri (resolve-iri (active-context-base result) value)))
165165
                   (if (and (absolute-iri? iri)
166-
                            (active-context-base result))
166+
                            (not-null-or-false (active-context-base result)))
167167
                     ;; 5.7.4
168168
                     (set! result (update-active-context result #:base iri))
169169
                     ;; 5.7.5

173173
         (when (json-has-key? context "@vocab")
174174
           ;; 5.8.1
175175
           (let ((value (assoc-ref context "@vocab")))
176-
             (if (equal? value #nil)
176+
             (if (json-null? value)
177177
               ;; 5.8.2
178178
               (set! result (update-active-context result #:vocab #f))
179179
               ;; 5.8.3

191191
         (when (json-has-key? context "@language")
192192
           ;; 5.9.1
193193
           (let ((value (assoc-ref context "@language")))
194-
             (if (equal? value #nil)
194+
             (if (json-null? value)
195195
               ;; 5.9.2
196196
               (set! result (update-active-context result #:language #f))
197197
               ;; 5.9.3

205205
           (when (processing-mode-1.0? (jsonld-options-processing-mode options))
206206
             (throw 'invalid-context-entry))
207207
           (let ((value (assoc-ref context "@direction")))
208-
             (if (equal? value #nil)
208+
             (if (json-null? value)
209209
               ;; 5.10.2
210210
               (set! result (update-active-context result #:direction #f))
211211
               ;; 5.10.3

jsonld/context.scm

1717
1818
(define-module (jsonld context)
1919
  #:use-module (ice-9 match)
20+
  #:use-module (jsonld json)
2021
  #:use-module (srfi srfi-9)
2122
  #:export (make-active-context
2223
            active-context?

8283
                 (vocab         #f)
8384
                 (language      #f)
8485
                 (direction     #f)
85-
                 (previous      #nil))
86+
                 (previous      json-null))
8687
  (make-active-context definitions base original-base vocab language direction
8788
                       previous))
8889

jsonld/create-term-definition.scm

7878
                 (definition (new-term-definition #:protected? protected?)))
7979
             (cond
8080
               ;; 7
81-
               ((equal? value #nil)
82-
                (set! value `(("@id" . #nil))))
81+
               ((json-null? value)
82+
                (set! value `(("@id" . ,json-null))))
8383
               ;; 8
8484
               ((string? value)
8585
                (set! value `(("@id" . ,value))))

150150
                         ;; 13.5
151151
                         (when (json-has-key? value "@container")
152152
                           (let ((container (assoc-ref value "@container")))
153-
                             (unless (member container '("@set" "@index" #nil))
153+
                             (unless (member container `("@set" "@index" ,json-null))
154154
                               (throw 'invalid-reverse-property))
155155
                             (set! definition (update-term-definition definition
156156
                                                #:container container))))

174174
                     ((and (json-has-key? value "@id")
175175
                           (not (equal? (assoc-ref value "@id") term)))
176176
                      ;; 14.1
177-
                      (if (equal? (assoc-ref value "@id") #nil)
177+
                      (if (json-null? (assoc-ref value "@id"))
178178
                        (set! definition (update-term-definition definition
179-
                                                                 #:iri #nil))
179+
                                                                 #:iri json-null))
180180
                        ;; 14.2
181181
                        (begin
182182
                          ;; 14.2.1

247247
                                          active-context local-context prefix defined)))
248248
                            (set! defined (assoc-ref result "defined"))
249249
                            (set! active-context (assoc-ref result "active-context"))))
250-
                        (if (term-definition-ref active-context prefix)
250+
                        (if (not-null-or-false (term-definition-ref active-context prefix))
251251
                          ;; 15.2
252252
                          (set! definition (update-term-definition definition
253253
                                             #:iri (string-append

274274
                      (set! definition (update-term-definition
275275
                                         definition #:iri "@type")))
276276
                     ;; 18
277-
                     ((active-context-vocab active-context)
277+
                     ((not-null-or-false (active-context-vocab active-context))
278278
                      (set! definition (update-term-definition definition
279279
                                         #:iri (string-append
280280
                                                 (active-context-vocab active-context)

399399
                                (not (json-has-key? value "@type")))
400400
                       ;; 22.1
401401
                       (let ((language (assoc-ref value "@language")))
402-
                         (unless (or (string? language) (equal? language #nil))
402+
                         (unless (or (string? language) (json-null? language))
403403
                           (throw 'invalid-language-mapping))
404404
                         ;; a warning should be thrown if not bcp-47 compliant
405405
                         ;; 22.2

412412
                                (not (json-has-key? value "@type")))
413413
                       ;; 23.1
414414
                       (let ((direction (assoc-ref value "@direction")))
415-
                         (unless (member direction '("ltr" "rtl" #nil))
415+
                         (unless (member direction `("ltr" "rtl" ,json-null))
416416
                           (throw 'invalid-base-direction))
417417
                         ;; 23.2
418418
                         (set! definition (update-term-definition definition

460460
                                      value))
461461
                       (throw 'invalid-term-definition))
462462
                     ;; 27
463-
                     (unless (or override-protected? (not previous-definition)
463+
                     (unless (or override-protected?
464+
                                 (not (not-null-or-false previous-definition))
464465
                                 (not (term-definition-protected? previous-definition)))
465466
                       ;; 27.1
466467
                       (unless (term-definition-equal?

jsonld/deserialize-jsonld.scm

5454
(define* (deserialize-jsonld generate-blank-node node-map dataset
5555
                             #:key produce-generalized-rdf? rdf-direction)
5656
  ;; 1
57+
  (pk 'node-map node-map)
5758
  (for-each-pair
5859
    (lambda (graph-name graph)
5960
      ;; 1.1

101102
                                                    rdf-direction item '()))
102103
                                   (list-triples (assoc-ref res "list-triples"))
103104
                                   (res (assoc-ref res "result")))
104-
                              (unless (equal? res #nil)
105+
                              (unless (json-null? res)
105106
                                (set! triples
106107
                                  (cons
107108
                                    (make-rdf-triple subject property res)

jsonld/download.scm

2424
  #:use-module (web response)
2525
  #:use-module (web uri)
2626
  #:use-module (rnrs bytevectors)
27-
  #:use-module (ice-9 match)
2827
  #:use-module (srfi srfi-1)
2928
  #:use-module (srfi srfi-9)
3029
  #:use-module (sxml simple)

jsonld/expansion.scm

3535
    ;; 13.7.1
3636
    (set! expanded-value '())
3737
    ;; 13.7.3
38-
    (when (and (term-definition-ref active-context key))
38+
    (when (term-definition? (term-definition-ref active-context key))
3939
      (set! direction (term-definition-direction
4040
                        (term-definition-ref active-context key)))
4141
      (when (equal? direction #f)

5151
        (for-each
5252
          (lambda (item)
5353
            ;; 13.7.4.2.1
54-
            (unless (equal? item #nil)
54+
            (unless (json-null? item)
5555
              ;; 13.7.4.2.2
5656
              (unless (string? item)
5757
                (throw 'invalid-language-map-value))

6161
                ;; TODO: if @language is not a bcp-47 one, we should issue a warning
6262
                (when (equal? (expand-key active-context language) "@none")
6363
                  (set! v (alist-remove v "@language")))
64-
                (when direction
64+
                (when (not-null-or-false direction)
6565
                  (set! v (alist-set v "@direction" direction)))
6666
                (set! expanded-value
6767
                  (append expanded-value (list v))))))

8080
  (set! expanded-value '())
8181
  ;; 13.8.2
8282
  (let ((index-key
83-
          (if (term-definition-ref active-context key)
83+
          (if (term-definition? (term-definition-ref active-context key))
8484
              (or (term-definition-index
8585
                    (term-definition-ref active-context key))
8686
                  "@index")
8787
              "@index"))
88-
        ;; Should not be #nil, if it fails because of that, there's a weird corner case
89-
        (map-context #nil)
90-
        (expanded-index #nil))
88+
        ;; Should not be null, if it fails because of that, there's a weird corner case
89+
        (map-context json-null)
90+
        (expanded-index json-null))
9191
    ;; 13.8.3
9292
    (for-each-pair
9393
      (lambda (index index-value)
9494
        ;; 13.8.3.1
9595
        (when (or (member "@id" container-mapping)
9696
                  (member "@type" container-mapping))
97-
          (set! map-context (or (active-context-previous active-context)
98-
                                active-context)))
97+
          (let ((previous (active-context-previous active-context)))
98+
            (set! map-context (or (if (not-null-or-false previous) previous #f)
99+
                                  active-context))))
99100
        ;; 13.8.3.2
100101
        (when (and (member "@type" container-mapping)
101-
                   (term-definition-ref map-context index)
102+
                   (term-definition? (term-definition-ref map-context index))
102103
                   (not (equal? (term-definition-context
103104
                                  (term-definition-ref map-context index))
104105
                                #f)))

110111
                                  (term-definition-ref map-context index))
111112
                                #:options options)))
112113
        ;; 13.8.3.3
113-
        (when (equal? map-context #nil)
114+
        (when (json-null? map-context)
114115
          (set! map-context active-context))
115116
        ;; 13.8.3.4
116117
        (set! expanded-index (assoc-ref

350351
         ;; 13.4.7.2
351352
         (begin
352353
           (unless (or (scalar? value)
353-
                       (equal? value #nil)
354+
                       (json-null? value)
354355
                       (and (jsonld-options-frame-expansion? options)
355356
                            (or (equal? value '())
356357
                                (scalar-array? value))))

363364
       (when (scalar? expanded-value)
364365
         (set! expanded-value #(,expanded-value))))
365366
     ;; 13.4.7.4
366-
     (when (equal? expanded-value #nil)
367+
     (when (json-null? expanded-value)
367368
       (set! continue? #f)
368-
       (set! result (alist-set result "@value" #nil))))
369+
       (set! result (alist-set result "@value" json-null))))
369370
    ;; 13.4.8
370371
    ((equal? expanded-property "@language")
371372
     (unless (or (string? value)

409410
       (throw 'invalid-@index-value)))
410411
    ;; 13.4.11
411412
    ((equal? expanded-property "@list")
412-
     (if (or (equal? active-property "@graph") (equal? active-property #nil))
413+
     (if (or (equal? active-property "@graph") (json-null? active-property))
413414
       ;; 13.4.11.1
414415
       (set! continue? #f)
415416
       (begin

496497
                                     #:options options))))
497498
  ;; 13.4.16
498499
  (unless (or (not continue?)
499-
              (and (equal? expanded-value #nil)
500+
              (and (json-null? expanded-value)
500501
                   (equal? expanded-property "@value")
501502
                   (equal? input-type "@json")))
502503
    (set! result (alist-set result expanded-property expanded-value)))

514515
                                          #:vocab? #t
515516
                                          #:options options)
516517
                           "iri"))
517-
              (expanded-value #nil)
518+
              (expanded-value json-null)
518519
              ;; whether we continue evaluating this key or not.  #f means go
519520
              ;; immediately to processing the next key-value pair.
520521
              (continue? #t)
521522
              (container-mapping #f))
522523
          (cond
523524
            ;; 13.3
524-
            ((or (equal? expanded-property #nil)
525+
            ((or (json-null? expanded-property)
525526
                 (not (or (json-keyword? expanded-property)
526527
                          (string-index expanded-property #\:))))
527528
             (set! continue? #f))

541542
                (let* ((def (term-definition-ref active-context key))
542543
                       (container (and (term-definition? def)
543544
                                       (term-definition-container def))))
544-
                  (and def
545+
                  (and (term-definition? def)
545546
                       (if (json-array? container)
546547
                           (array->list container)
547548
                           (if container (list container) '())))))
548549
              (cond
549550
                ;; 13.6
550551
                ((and
551-
                   (term-definition-ref active-context key)
552+
                   (term-definition? (term-definition-ref active-context key))
552553
                   (equal?
553554
                     (term-definition-type
554555
                       (term-definition-ref active-context key))

582583
                               #:options options))))))
583584
          ;; 13.10 and previous (via continue?): do we process further, or
584585
          ;; go to the next key immediately?
585-
          (when (and continue? (not (equal? expanded-value #nil)))
586+
          (when (and continue? (not (json-null? expanded-value)))
586587
            ;; 13.11
587588
            (when (and container-mapping
588589
                       (member "@list" container-mapping)

606607
                  expanded-value))
607608
              (set! expanded-value (list->array 1 expanded-value)))
608609
            ;; 13.13
609-
            (if (and (term-definition-ref active-context key)
610+
            (if (and (term-definition?
611+
                       (term-definition-ref active-context key))
610612
                     (term-definition-reverse?
611613
                       (term-definition-ref active-context key)))
612614
              ;; 13.13.1 and 13.13.2

705707
See @url{https://www.w3.org/TR/2014/REC-json-ld-api-20140116}."
706708
  ;; 3
707709
  (define property-scoped-context
708-
    (if (term-definition-ref active-context active-property)
709-
        ;; can be #nil, so we cannot use `or` here
710+
    (if (term-definition? (term-definition-ref active-context active-property))
711+
        ;; can be null, so we cannot use `or` here
710712
        (term-definition-context (term-definition-ref
711713
                                   active-context active-property))
712714
        #f))

715717
    (set! options (update-jsonld-options options #:frame-expansion? #f)))
716718
  (cond
717719
    ;; 1
718-
    ((equal? element #nil) #nil)
720+
    ((json-null? element) json-null)
719721
    ;; 4
720722
    ((scalar? element)
721-
     (if (member active-property '(#nil "@graph"))
723+
     (if (member active-property `(,json-null "@graph"))
722724
       ;; 4.1
723-
       #nil
725+
       json-null
724726
       (begin
725727
         ;; 4.2
726728
         (unless (equal? property-scoped-context #f)

741743
                                           #:options options)))
742744
             ;; 5.2.2
743745
             (when (and
744-
                     (term-definition-ref active-context active-property)
746+
                     (term-definition? (term-definition-ref active-context active-property))
745747
                     (term-definition-container (term-definition-ref active-context active-property))
746748
                     (member "@list" (array->list (term-definition-container (term-definition-ref active-context active-property))))
747749
                     (json-array? expanded-item))

749751
             ;; 5.2.3
750752
             (if (json-array? expanded-item)
751753
               (set! result (append result (array->list expanded-item)))
752-
               (unless (equal? expanded-item #nil)
754+
               (unless (json-null? expanded-item)
753755
                 (set! result (append result (list expanded-item)))))))
754756
         (array->list element))
755757
       ;; 5.3

757759
    ;; 6
758760
    (else
759761
      ;; 7
760-
      (when (active-context-previous active-context)
762+
      (unless (json-null? (active-context-previous active-context))
761763
        (let ((previous (active-context-previous active-context)))
762764
          (unless (or from-map? (json-key-expanded-to? active-context element "@value")
763765
                      (and

784786
      (let ((type-scoped-context active-context)
785787
            (result '())
786788
            (nests '())
787-
            (input-type #nil)
789+
            (input-type json-null)
788790
            (found-first-entry? #f))
789791
        ;; 11
790792
        (for-each-pair

793795
              ;; 12
794796
              (unless found-first-entry?
795797
                (match value
796-
                  ((json-array? value)
798+
                  ((? json-array? value)
797799
                   (set! input-type (car (reverse (array->list value)))))
798800
                  (_ (set! input-type value)))
799801
                (set! input-type

807809
              ;; 11.2
808810
              (for-each
809811
                (lambda (term)
810-
                  (when (and (term-definition-ref type-scoped-context term)
812+
                  (when (and (term-definition? (term-definition-ref type-scoped-context term))
811813
                             (not (equal?
812814
                                    (term-definition-context
813815
                                      (term-definition-ref type-scoped-context term))

859861
             ;; 15.2
860862
             (unless (equal? (assoc-ref result "@type") "@json")
861863
               ;; 15.3
862-
               (when (equal? (assoc-ref result "@value") #nil)
863-
                 (set! result #nil))
864+
               (when (json-null? (assoc-ref result "@value"))
865+
                 (set! result json-null))
864866
               ;; 15.4
865867
               (unless (or
866868
                         (string? (assoc-ref result "@value"))

903905
          ((and (json-has-key? result "@language")
904906
                (null? (filter (lambda (p) (not (equal? (car p) "@language")))
905907
                               result)))
906-
           (set! result #nil))
908+
           (set! result json-null))
907909
          ;; 19
908-
          ((or (equal? active-property #nil) (equal? active-property "@graph"))
910+
          ((or (json-null? active-property) (equal? active-property "@graph"))
909911
           (if (or (equal? result '())
910912
                   (json-has-key? result "@value")
911913
                   (json-has-key? result "@list"))
912-
               (set! result #nil)
914+
               (set! result json-null)
913915
               (when (and
914916
                       (not (jsonld-options-frame-expansion? options))
915917
                       (json-has-key? result "@id")
916918
                       (null? (filter (lambda (p) (not (equal? (car p) "@id")))
917919
                                      result)))
918-
                 (set! result #nil))))
920+
                 (set! result json-null))))
919921
          ;; 20
920922
          (else #t))
921923
        result))))

jsonld/generate-blank-node-identifier.scm

2525
2626
  (define* (generate-blank-node-identifier identifier)
2727
      ;; 1
28-
      (if (and (not (equal? identifier #nil))
28+
      (if (and (not (json-null? identifier))
2929
               (json-has-key? identifier-map identifier))
3030
       (assoc-ref identifier-map identifier)
3131
       (let ((blank-node-identifier
3232
               (string-append "_:b" (number->string counter))))
3333
         (set! counter (+ counter 1))
34-
         (unless (equal? identifier #nil)
34+
         (unless (json-null? identifier)
3535
           (set! identifier-map
3636
             (alist-set identifier-map identifier blank-node-identifier)))
3737
         blank-node-identifier)))

jsonld/inverse-context-creation.scm

3636
  (let ((result '())
3737
        (default-language "@none"))
3838
    ;; 2
39-
    (when (active-context-language active-context)
39+
    (when (not-null-or-false (active-context-language active-context))
4040
      (set! default-language (string-downcase (active-context-language
4141
                                                active-context))))
4242
    ;; 3
4343
    (for-each-pair
4444
      (lambda (term term-definition)
4545
        ;; 3.1
46-
        (unless (equal? term-definition #nil)
46+
        (unless (json-null? term-definition)
4747
          ;; 3.2
4848
          (let ((container "@none")
4949
                ;; 3.3

134134
              ;; 3.14
135135
              ((not (equal? (term-definition-language term-definition) #f))
136136
               (let ((language
137-
                       (if (term-definition-language term-definition)
137+
                       (if (not-null-or-false (term-definition-language term-definition))
138138
                           (string-downcase
139139
                             (term-definition-language term-definition))
140140
                           "@null")))

144144
              ;; 3.15
145145
              ((not (equal? (term-definition-direction term-definition) #f))
146146
               (let ((direction
147-
                       (if (term-definition-direction term-definition)
147+
                       (if (not-null-or-false (term-definition-direction term-definition))
148148
                           (string-append
149149
                             "_"
150150
                             (string-downcase

159159
                       (string-downcase
160160
                         (string-append
161161
                           default-language "_"
162-
                           (or (active-context-direction active-context)
162+
                           (or (not-null-or-false (active-context-direction active-context))
163163
                               "")))))
164164
                 (unless (json-has-key? language-map lang-dir)
165165
                   (set! language-map

jsonld/iri-compaction.scm

3434
  ;; in that case we iri-compact each part of it and return an array.
3535
  (cond
3636
    ;; 2
37-
    ((equal? var #nil)
38-
      #nil)
37+
    ((json-null? var) json-null)
3938
    ((json-array? var)
4039
     (list->array 1
4140
       (map

4948
    (else
5049
     (begin
5150
       (let ((result #f))
51+
         (pk 'inverse (assoc-ref inverse-context var))
5252
         ;; 2
5353
         (when (and vocab? (json-has-key? inverse-context var))
5454
           (let ((default-language
5555
                   ;; 2.1
56-
                   (if (or (active-context-direction active-context)
57-
                           (active-context-language active-context))
56+
                   (if (or (not-null-or-false (active-context-direction active-context))
57+
                           (not-null-or-false (active-context-language active-context)))
5858
                       (string-append
59-
                         (or (active-context-language active-context) "")
59+
                         (or (not-null-or-false (active-context-language active-context))
60+
                             "")
6061
                         "_"
61-
                         (or (active-context-direction active-context) ""))
62+
                         (or (not-null-or-false (active-context-direction active-context))
63+
                             ""))
6264
                       "@none"))
6365
                 ;; 2.3
6466
                 (containers '())

8991
                ;; 2.7.2
9092
                (let ((lst (array->list (assoc-ref value "@list")))
9193
                      ;; 2.7.3
92-
                      (common-type #nil)
93-
                      (common-language #nil))
94+
                      (common-type json-null)
95+
                      (common-language json-null))
9496
                  (when (null? lst)
9597
                    (set! common-language default-language))
9698
                  ;; 2.7.4

117119
                            ;; 2.7.4.3
118120
                            (set! item-type "@id"))
119121
                        ;; 2.7.4.4
120-
                        (if (equal? common-language #nil)
122+
                        (if (json-null? common-language)
121123
                            (set! common-language item-language)
122124
                            (unless (or (equal? common-language item-language)
123125
                                        (not (json-has-key? item "@value")))
124126
                              (set! common-language "@none")))
125127
                        ;; 2.7.4.6
126-
                        (if (equal? common-type #nil)
128+
                        (if (json-null? common-type)
127129
                            (set! common-type item-type)
128130
                            (unless (equal? common-type item-type)
129131
                              (set! common-type "@none")))))
130132
                    lst)
131133
                  ;; 2.7.5
132-
                  (when (equal? common-language #nil)
134+
                  (when (json-null? common-language)
133135
                    (set! common-language "@none"))
134-
                  (when (equal? common-type #nil)
136+
                  (when (json-null? common-type)
135137
                    (set! common-type "@none"))
136138
                  (if (not (equal? common-type "@none"))
137139
                      (begin

204206
                                         value)))
205207
                 (set! containers (append containers '("@language" "@language@set")))))
206208
             ;; 2.13
207-
             (when (equal? type/language-value #nil)
209+
             (when (equal? type/language-value json-null)
208210
               (set! type/language-value "@null"))
209211
             ;; 2.15
210212
             (when (equal? type/language-value "@reverse")

218220
                                                     #:vocab? #t
219221
                                                     #:processing-mode processing-mode))
220222
                      (def (term-definition-ref active-context compacted-iri))
221-
                      (iri (if def (term-definition-iri def) #f)))
223+
                      (iri (if (term-definition? def)
224+
                               (term-definition-iri def)
225+
                               #f)))
222226
                 (if (equal? iri (assoc-ref value "@id"))
223227
                     (set! preferred-values
224228
                       (append preferred-values '("@vocab" "@id" "@none")))

238242
                                         (string-index s #\_))
239243
                                       preferred-values))
240244
                    (underscore (if (null? underscore-vals) #f (car underscore-vals))))
241-
               (when underscore
245+
               (when (not-null-or-false underscore)
242246
                 (set! preferred-values
243247
                   (append
244248
                     preferred-values

247251
                         (cons "" (cdr (string-split underscore #\_))) "_"))))))
248252
             ;; 2.20
249253
             (let ((term (term-selection inverse-context var containers type/language preferred-values)))
250-
               (when term
254+
               (when (not-null-or-false term)
251255
                 (set-cond! result term)))))
252256
         ;; 3
253-
         (when (and vocab? (active-context-vocab active-context))
257+
         (when (and vocab? (not-null-or-false (active-context-vocab active-context)))
254258
           (let ((vocab (active-context-vocab active-context)))
259+
             (pk 'vocab vocab var)
255260
             (when (and (>= (string-length var) (string-length vocab))
256261
                        (equal? (substring var 0 (string-length vocab)) vocab))
257262
               (let ((suffix (substring var (string-length vocab))))
258-
                 (unless (term-definition-ref active-context suffix)
263+
                 (when (not (not-null-or-false (term-definition-ref active-context suffix)))
259264
                   (set-cond! result suffix))))))
260265
         ;; 4
261-
         (let ((compact-iri #nil))
266+
         (let ((compact-iri json-null))
262267
           ;; 5
263268
           (for-each-pair
264269
             (lambda (term def)
265270
               ;; 5.1
266-
               (unless (or (equal? (term-definition-iri def) #nil)
271+
               (unless (or (json-null? (term-definition-iri def))
267272
                           (equal? (term-definition-iri def) var)
268273
                           (not (string? var))
269274
                           (< (string-length var) (string-length (term-definition-iri def)))

280285
                                                   (string-length
281286
                                                     (term-definition-iri def))))))
282287
                   ;; 5.3
283-
                   (when (or (equal? compact-iri #nil)
288+
                   (when (or (json-null? compact-iri)
284289
                             (< (string-length candidate) (string-length compact-iri))
285290
                             (and (= (string-length candidate)
286291
                                     (string-length compact-iri))
287292
                                  (string<=? candidate compact-iri)))
288293
                     (let ((def (term-definition-ref active-context candidate)))
289-
                       (when (or (not def)
290-
                                 (and (not value)
294+
                       (when (or (not (term-definition? def))
295+
                                 (and (not (not-null-or-false value))
291296
                                      (equal? (term-definition-iri def) var)))
292297
                         (set! compact-iri candidate)))))))
293298
             (active-context-definitions active-context))
294299
           ;; 6
295-
           (when compact-iri
300+
           (when (not-null-or-false compact-iri)
296301
             (set-cond! result compact-iri)))
297302
         ;; 7
298303
         (unless result

310315
                 (throw 'iri-confused-with-prefix)))))
311316
         ;; 8
312317
         (unless vocab?
313-
           (when (and (active-context-base active-context) (absolute-iri? var))
318+
           (when (and (not-null-or-false (active-context-base active-context))
319+
                      (absolute-iri? var))
314320
             (set-cond! result
315321
               (make-relative-iri var (active-context-base active-context)))))
316322
         ;; 9

jsonld/iri-expansion.scm

5555
  ;; 2
5656
  (when (and (keyword-form? iri) (not (json-keyword? iri)))
5757
    ;; Should give a warning and return null, we only return null without warning
58-
    (set! iri #nil))
58+
    (set! iri json-null))
5959
  ;; if not 1 or 2
60-
  (unless (or (json-keyword? iri) (equal? iri #nil))
60+
  (unless (or (json-keyword? iri) (json-null? iri))
6161
    ;; 3
6262
    (when (and local-context (json-has-key? local-context iri))
6363
      (let ((def (assoc-ref defined iri)))

101101
             ;; 6.4
102102
             (if (and
103103
                   (term-definition? (term-definition-ref active-context prefix))
104-
                   (term-definition-iri (term-definition-ref active-context prefix))
104+
                   (not-null-or-false (term-definition-iri (term-definition-ref active-context prefix)))
105105
                   (term-definition-prefix? (term-definition-ref active-context prefix)))
106106
               (set! iri
107107
                 (string-append (term-definition-iri

112112
                 ((absolute-iri? iri)
113113
                  (set! iri iri))
114114
                 ;; 7
115-
                 ((and vocab? (active-context-vocab active-context))
116-
                  (set! iri (string-append (active-context-vocab active-context)
115+
                 ((and vocab? (not-null-or-false (active-context-vocab active-context)))
116+
                  (set! iri (string-append (not-null-or-false (active-context-vocab active-context))
117117
                                           iri)))
118118
                 (else
119-
                   (if (and document-relative? (not (equal? (active-context-base active-context) #nil)))
119+
                   (if (and document-relative? (not-null-or-false (active-context-base active-context)))
120120
                       ;; 8
121121
                       (set! iri (resolve-iri (or
122122
                                                (active-context-base active-context)

125125
                       ;; 9
126126
                       (set! iri iri)))))))))
127127
      ;; 7
128-
      ((and vocab? (active-context-vocab active-context))
128+
      ((and vocab? (not-null-or-false (active-context-vocab active-context)))
129129
       (set! iri (string-append (active-context-vocab active-context)
130130
                                iri)))
131131
      (else
132-
        (if (and document-relative? (not (equal? (active-context-base active-context) #nil)))
132+
        (if (and document-relative? (not-null-or-false (active-context-base active-context)))
133133
          ;; 8
134134
          (set! iri (resolve-iri (or
135135
                                   (active-context-base active-context)

jsonld/json.scm

3939
            json-array?
4040
            json-has-key?
4141
            json-keyword?
42+
            json-null
43+
            json-null?
4244
            json-object?
4345
            jsonld-error->string
4446
            keyword-form?

4648
            make-jsonld-options
4749
            merge-json
4850
            node-object?
51+
            not-null-or-false
4952
            processing-mode-1.0?
5053
            relative-iri?
5154
            same-json?

120123
  "Whether a value is a Json array."
121124
  (and (array? v) (not (string? v))))
122125
126+
(define (json-null? v)
127+
  (equal? v 'null))
128+
129+
(define json-null 'null)
130+
123131
(define (json-object? v)
124132
  "Whether a value is a Json object."
125-
  (and (list? v) (not (equal? v #nil))))
133+
  (and (list? v) (not (json-null? v))))
134+
135+
(define (not-null-or-false v)
136+
  (and (not (json-null? v)) v))
126137
127138
(define (json-has-key? obj key)
128139
  "Whether a Json object @var{obj} has a @var{key}."

jsonld/list-to-rdf.scm

2424
  #:export (list-to-rdf))
2525
2626
(define* (list-to-rdf generate-blank-node rdf-direction lst list-triples)
27-
  (let ((result #nil))
27+
  (let ((result json-null))
2828
    (if (null? lst)
2929
        ;; 1
3030
        (set! result (rdf-iri "nil"))
3131
        ;; 2
3232
        (let ((bnodes (map
3333
                        (lambda _
34-
                          (blank-node->rdf-blank-node (generate-blank-node #nil)))
34+
                          (blank-node->rdf-blank-node (generate-blank-node json-null)))
3535
                        lst)))
3636
          ;; 3
3737
          (let loop ((bnodes bnodes) (lst lst))

4646
                     (object (assoc-ref res "result"))
4747
                     (embedded-triples (assoc-ref res "list-triples")))
4848
                ;; 3.3
49-
                (unless (equal? object #nil)
49+
                (unless (json-null? object)
5050
                  (set! list-triples
5151
                    (cons (make-rdf-triple subject (rdf-iri "first") object)
5252
                          list-triples)))

jsonld/node-map-generation.scm

6868
(define (get-node-map-generation generate-blank-node)
6969
  (define* (node-map-generation element node-map
7070
                                #:key (active-graph "@default")
71-
                                (active-subject #nil)
72-
                                (active-property #nil)
73-
                                (lst #nil))
71+
                                (active-subject json-null)
72+
                                (active-property json-null)
73+
                                (lst json-null))
7474
    ;; 1
7575
    (if (json-array? element)
7676
      (for-each

8484
            (set! lst (assoc-ref res "list"))))
8585
        (array->list element))
8686
      ;; 2: otherwise
87-
      (let* ((graph (or (assoc-ref node-map active-graph) '()))
88-
             (subject-node (if (equal? active-subject #nil)
87+
      (let* ((graph (or (not-null-or-false (assoc-ref node-map active-graph))
88+
                        '()))
89+
             (subject-node (if (json-null? active-subject)
8990
                               '()
90-
                               (or (assoc-ref graph active-subject) '())))
91+
                               (or (not-null-or-false (assoc-ref graph active-subject))
92+
                                   '())))
9193
             (types (assoc-ref element "@type"))
9294
             (types (if (json-array? types)
9395
                        (array->list types)
94-
                        (if types (list types) '())))
96+
                        (if (not-null-or-false types) (list types) '())))
9597
             ;; 3
9698
             (types
9799
               (map

106108
            (set! element (alist-set element "@type" (car types)))))
107109
        ;; 4
108110
        (when (json-has-key? element "@value")
109-
          (if (equal? lst #nil)
111+
          (if (json-null? lst)
110112
              (begin
111113
                ;; 4.1.1
112114
                (unless (json-has-key? subject-node active-property)

132134
              (set! result (assoc-ref res "list"))
133135
              (set! node-map (assoc-ref res "node-map"))
134136
              (set! graph (assoc-ref node-map active-graph))
135-
              (set! subject-node (or (assoc-ref graph active-subject) '()))
136-
              (if (equal? lst #nil)
137+
              (set! subject-node (or (not-null-or-false (assoc-ref graph active-subject))
138+
                                     '()))
139+
              (if (json-null? lst)
137140
                ;; 5.3
138141
                (begin
139142
                  (set! subject-node

155158
                        (if (blank-node? (assoc-ref element "@id"))
156159
                            (generate-blank-node (assoc-ref element "@id"))
157160
                            (assoc-ref element "@id"))
158-
                        (generate-blank-node #nil))))
161+
                        (generate-blank-node json-null))))
159162
            ;; 6.3
160-
            (unless (or (json-has-key? graph id) (not id))
163+
            (unless (or (json-has-key? graph id) (not (not-null-or-false id)))
161164
              (set! graph
162165
                (alist-set graph id `(("@id" . ,id))))
163166
              (set! node-map (alist-set node-map active-graph graph)))
164167
            ;; 6.4
165-
            (let ((node (or (assoc-ref graph id) '())))
168+
            (let ((node (or (not-null-or-false (assoc-ref graph id)) '())))
166169
              (cond
167170
                ;; 6.5
168171
                ((json-object? active-subject)

173176
                     ;; 6.5.1
174177
                     (set! node
175178
                       (alist-set node active-property `#(,active-subject))))
176-
                 (when id
179+
                 (when (not-null-or-false id)
177180
                   (set! graph (alist-set graph id node)))
178181
                 (set! node-map (alist-set node-map active-graph graph)))
179182
                ;; 6.6
180-
                ((not (equal? active-property #nil))
183+
                ((not (json-null? active-property))
181184
                 ;; 6.6.1
182185
                 (let ((reference `(("@id" . ,id))))
183-
                   (if (equal? lst #nil)
186+
                   (if (json-null? lst)
184187
                       ;; 6.6.2
185188
                       (begin
186189
                         (if (json-has-key? subject-node active-property)

201204
              (when (json-has-key? element "@type")
202205
                (set! node
203206
                  (append-if-not-in node "@type" (assoc-ref element "@type")))
204-
                (when id
207+
                (when (not-null-or-false id)
205208
                  (set! graph (alist-set graph id node)))
206209
                (set! node-map (alist-set node-map active-graph graph)))
207210
              ;; 6.8

233236
                                       #:active-property property)))
234237
                            (set! node-map (assoc-ref res "node-map"))
235238
                            (set! graph (assoc-ref node-map active-graph))
236-
                            (set! subject-node (or (assoc-ref graph active-subject)
239+
                            (set! subject-node (or (not-null-or-false
240+
                                                     (assoc-ref graph active-subject))
237241
                                                   '()))
238-
                            (when id
242+
                            (when (not-null-or-false id)
239243
                              (set! node (assoc-ref graph id)))))
240244
                        (array->list values)))
241245
                    reverse-map)

249253
                             #:active-graph id)))
250254
                  (set! node-map (assoc-ref res "node-map"))
251255
                  (set! graph (assoc-ref node-map active-graph))
252-
                  (set! subject-node (or (assoc-ref graph active-subject) '()))
253-
                  (when id
256+
                  (set! subject-node (or (not-null-or-false
257+
                                           (assoc-ref graph active-subject))
258+
                                         '()))
259+
                  (when (not-null-or-false id)
254260
                    (set! node (assoc-ref graph id))))
255261
                (set! element (alist-remove element "@graph")))
256262
              ;; 6.11

261267
                             #:active-graph active-graph)))
262268
                  (set! node-map (assoc-ref res "node-map"))
263269
                  (set! graph (assoc-ref node-map active-graph))
264-
                  (set! subject-node (or (assoc-ref graph active-subject) '()))
265-
                  (when id
270+
                  (set! subject-node (or (not-null-or-false
271+
                                           (assoc-ref graph active-subject))
272+
                                         '()))
273+
                  (when (not-null-or-false id)
266274
                    (set! node (assoc-ref graph id))))
267275
                (set! element (alist-remove element "@included")))
268276
              ;; 6.12

274282
                  ;; 6.12.2
275283
                  (unless (json-has-key? node property)
276284
                    (set! node (alist-set node property #()))
277-
                    (when id
285+
                    (when (not-null-or-false id)
278286
                      (set! graph (alist-set graph id node)))
279287
                    (set! node-map (alist-set node-map active-graph graph)))
280288
                  ;; 6.12.3

284292
                               #:active-property property)))
285293
                    (set! node-map (assoc-ref res "node-map"))
286294
                    (set! graph (assoc-ref node-map active-graph))
287-
                    (set! subject-node (or (assoc-ref graph active-subject) '()))
288-
                    (when id
295+
                    (set! subject-node (or (not-null-or-false
296+
                                             (assoc-ref graph active-subject))
297+
                                           '()))
298+
                    (when (not-null-or-false id)
289299
                      (set! node (assoc-ref graph id)))))
290300
                (alist-sort-by-key element))
291-
              (when id
301+
              (when (not-null-or-false id)
292302
                (set! graph (alist-set graph id node))))))
293303
        (when (string? active-subject)
294304
          (set! graph (alist-set graph active-subject subject-node)))

jsonld/object-to-rdf.scm

3737
3838
(define (canonical-json value)
3939
  (cond
40-
    ((member value '(#t #f #nil))
40+
    ((member value `(#t #f ,json-null))
4141
     value)
4242
    ((string? value) value)
4343
    ((number? value)

7070
        #f)))
7171
7272
(define* (object-to-rdf generate-blank-node rdf-direction item list-triples)
73-
  (let ((result #nil))
73+
  (let ((result json-null))
7474
    (cond
7575
      ;; 1
7676
      ((and (node-object? item) (not (well-formed? (assoc-ref item "@id"))))
77-
       (set! result #nil))
77+
       (set! result json-null))
7878
      ;; 2
7979
      ((node-object? item)
8080
       (set! result (assoc-ref item "@id")))

9090
      (else
9191
        ;; 4
9292
        (let ((value (assoc-ref item "@value"))
93-
              (datatype (or (assoc-ref item "@type") #nil)))
93+
              (datatype (or (assoc-ref item "@type") json-null)))
9494
          (cond
9595
            ;; 6
96-
            ((and (not (equal? datatype #nil)) (not (equal? datatype "@json"))
96+
            ((and (not (json-null? datatype)) (not (equal? datatype "@json"))
9797
                    (not (well-formed? datatype)))
98-
             (set! result #nil))
98+
             (set! result json-null))
9999
            ;; 7
100100
            ((and
101101
               (json-has-key? item "@language")
102102
               (not (well-formed-language-tag? (assoc-ref item "@language"))))
103-
              (set! result #nil))
103+
              (set! result json-null))
104104
            (else
105105
              ;; 8
106106
              (when (equal? datatype "@json")

109109
              (cond
110110
                ;; 9
111111
                ((boolean? value)
112-
                 (when (equal? datatype #nil)
112+
                 (when (json-null? datatype)
113113
                   (set! datatype (xsd-iri "boolean")))
114114
                 (set! value (if value "true" "false")))
115115
                ;; 10

117117
                      (or (not (integer? (inexact->exact value)))
118118
                          (>= (abs value) (expt 10 21))
119119
                          (equal? datatype (xsd-iri "double"))))
120-
                 (when (equal? datatype #nil)
120+
                 (when (json-null? datatype)
121121
                   (set! datatype (xsd-iri "double")))
122122
                 (set! value (canonical-double value)))
123123
                ;; 11
124124
                ((number? value)
125125
                 (set! value (number->string (inexact->exact value)))
126-
                 (when (equal? datatype #nil)
126+
                 (when (json-null? datatype)
127127
                   (set! datatype (xsd-iri "integer"))))
128128
                ;; 12
129-
                ((equal? datatype #nil)
129+
                ((json-null? datatype)
130130
                 (set! datatype
131131
                   (if (json-has-key? item "@language")
132132
                       (rdf-iri "langString")
133133
                       (xsd-iri "string")))))
134134
              (if (and (json-has-key? item "@direction") (not (equal? rdf-direction #f)))
135135
                  ;; 13
136-
                  (let* ((language (or (assoc-ref item "@language") ""))
136+
                  (let* ((language (or (not-null-or-false (assoc-ref item "@language")) ""))
137137
                         (language (string-downcase language)))
138138
                    (if (equal? rdf-direction "i18n-datatype")
139139
                        ;; 13.2

146146
                        ;; 13.3
147147
                        (when (equal? rdf-direction "compound-literal")
148148
                          (let ((literal (blank-node->rdf-blank-node
149-
                                           (generate-blank-node #nil))))
149+
                                           (generate-blank-node json-null))))
150150
                            ;; 13.3.2
151151
                            (set! list-triples
152152
                              (cons

jsonld/rdf-to-object.scm

3333
      (let ((result '())
3434
            (converted-value (rdf-literal-lexical-form value))
3535
            (datatype (rdf-literal-type value))
36-
            (type #nil))
36+
            (type json-null))
3737
        (cond
3838
          ;; 2.4
3939
          (use-native-types?

9898
        ;; 2.9
9999
        (set! result (alist-set result "@value" converted-value))
100100
        ;; 2.10
101-
        (when type
101+
        (when (not-null-or-false type)
102102
          (set! result (alist-set result "@type" type)))
103103
        ;; 2.11
104104
        result)))

jsonld/term-selection.scm

2222
(define* (term-selection inverse-context var containers type/language
2323
                         preferred-values)
2424
  (let ((container-map (assoc-ref inverse-context var))
25-
        (result #nil))
25+
        (result json-null))
2626
    ;; 2
2727
    (for-each
2828
      (lambda (container)

3535
            (for-each
3636
              (lambda (item)
3737
                (when (json-has-key? value-map item)
38-
                  (unless result
38+
                  (unless (not-null-or-false result)
3939
                    (set! result (assoc-ref value-map item)))))
4040
              preferred-values))))
4141
      containers)

jsonld/value-compaction.scm

2525
(define (container-mapping active-context active-property)
2626
  (let* ((def (term-definition-ref active-context active-property))
2727
         (container-mapping
28-
           (if def (or (term-definition-container def) #()) #())))
28+
           (if (term-definition? def)
29+
               (or (not-null-or-false (term-definition-container def)) #())
30+
               #())))
2931
    (if (json-array? container-mapping)
3032
        (array->list container-mapping)
3133
        (list container-mapping))))

3537
  (let* ((result value)
3638
         (active-def (term-definition-ref active-context active-property))
3739
         ;; 2
38-
         (language (if active-def (term-definition-language active-def) #f))
40+
         (language (if (term-definition? active-def)
41+
                       (term-definition-language active-def)
42+
                       #f))
3943
         ;; 3
40-
         (direction (if active-def (term-definition-direction active-def) #f)))
44+
         (direction (if (term-definition? active-def)
45+
                        (term-definition-direction active-def)
46+
                        #f)))
4147
    (when (equal? language #f)
4248
      (set! language (active-context-language active-context)))
4349
    (when (equal? direction #f)

5056
                       (not (member (car kv) '("@id" "@index"))))
5157
                     value)))
5258
       (cond
53-
         ((and active-def (equal? (term-definition-type active-def) "@id"))
59+
         ((and (term-definition? active-def)
60+
               (equal? (term-definition-type active-def) "@id"))
5461
          (set! result (iri-compaction active-context inverse-context
5562
                                       (assoc-ref value "@id") #:vocab? #f
5663
                                       #:processing-mode processing-mode)))
57-
         ((and active-def (equal? (term-definition-type active-def) "@vocab"))
64+
         ((and (term-definition? active-def)
65+
               (equal? (term-definition-type active-def) "@vocab"))
5866
          (set! result (iri-compaction active-context inverse-context
5967
                                       (assoc-ref value "@id") #:vocab? #t
6068
                                       #:processing-mode processing-mode)))))
6169
      ;; 5
6270
      ((and (json-has-key? value "@type")
63-
            active-def
71+
            (term-definition? active-def)
6472
            (equal? (assoc-ref value "@type")
6573
                    (term-definition-type active-def)))
6674
       (set! result (assoc-ref value "@value")))
6775
      ;; 6
68-
      ((or (and active-def (equal? (term-definition-type active-def) "@none"))
76+
      ((or (and (term-definition? active-def)
77+
                (equal? (term-definition-type active-def) "@none"))
6978
           (json-has-key? value "@type"))
7079
       (when (json-has-key? result "@type")
7180
         (let ((type (iri-compaction active-context inverse-context

8594
         (json-has-key? value "@value")
8695
         (not (string? (assoc-ref value "@value"))))
8796
       (when (or (and (json-has-key? value "@index")
88-
                      active-def
97+
                      (term-definition? active-def)
8998
                      (member "@index" (container-mapping active-context
9099
                                                          active-property)))
91100
                 (not (json-has-key? value "@index")))
92101
         (set! result (assoc-ref value "@value"))))
93102
      ;; 8
94-
      ((and (or (and language (equal? language (assoc-ref value "@language")))
95-
                (and (not language)
103+
      ((and (or (and (not-null-or-false language)
104+
                     (equal? language (assoc-ref value "@language")))
105+
                (and (not (not-null-or-false language))
96106
                     (not (json-has-key? value "@language"))))
97-
            (or (and direction (equal? direction (assoc-ref value "@direction")))
98-
                (and (not direction)
107+
            (or (and (not-null-or-false direction)
108+
                     (equal? direction (assoc-ref value "@direction")))
109+
                (and (not (not-null-or-false direction))
99110
                     (not (json-has-key? value "@direction")))))
100111
       (when (or (and (json-has-key? value "@index")
101-
                      active-def
112+
                      (term-definition? active-def)
102113
                      (member "@index" (container-mapping
103114
                                         active-context active-property)))
104115
                 (not (json-has-key? value "@index")))

jsonld/value-expansion.scm

6868
            (set! result (alist-set result "@type" type-mapping)))
6969
          ;; 5
7070
          (when (string? value)
71-
            (let* ((language (or language-mapping (active-context-language active-context)))
72-
                   (direction (or direction-mapping (active-context-direction active-context))))
73-
              (when (equal? language-mapping #nil)
74-
                (set! language #nil))
75-
              (when (equal? direction-mapping #nil)
76-
                (set! direction #nil))
77-
              (when language
71+
            (let* ((language (or (not-null-or-false language-mapping)
72+
                                 (active-context-language active-context)))
73+
                   (direction (or (not-null-or-false direction-mapping)
74+
                                  (active-context-direction active-context))))
75+
              (when (json-null? language-mapping)
76+
                (set! language json-null))
77+
              (when (json-null? direction-mapping)
78+
                (set! direction json-null))
79+
              (when (not-null-or-false language)
7880
                (set! result (alist-set result "@language" language)))
79-
              (when direction
81+
              (when (not-null-or-false direction)
8082
                (set! result (alist-set result "@direction" direction)))))
8183
          ;; 6
8284
          result)))))