~williewillus/r16

r16/common.rkt -rw-r--r-- 610 bytes
d426a80dVincent Lee Expose replied-to message contents 7 days ago
                                                                                
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
#lang racket/base

(provide (struct-out trick) json->trick trick->json)

(struct trick
  (author
   body
   created
   [storage #:mutable]
   [invocations #:mutable]))

(define (trick->json trick)
  (hasheq 'author (trick-author trick)
          'body (trick-body trick)
          'created (trick-created trick)
          'data (trick-storage trick)
          'invocations (trick-invocations trick)))

(define (json->trick json)
  (trick
   (hash-ref json 'author)
   (hash-ref json 'body)
   (hash-ref json 'created)
   (make-hash (hash->list (hash-ref json 'data #hash())))
   (hash-ref json 'invocations)))