String representation of records Jakub T. Jankiewicz 02 Apr 2021 08:26 UTC

I have another idea that I've implemented in my Scheme based lisp interpreter.

It's a way of adding string representation of records. In my interpreter it's
for all JavaScript objects and records just create a class.

So this looks like this (based on SRFI-111 example):

(define-record-type box-type
   (box value)
   box?
   (value unbox set-box!))

(set-repr! box-type (lambda (x) (string-append "#&" (repr x.value))))
(box 10)
#&10

repr can be a function that prints to string port and return string.

this is companion to the set-special! syntax that extend the parser. So with
both of those extensions you can have:

#&10

that will print as:

#&10

In REPL

You only need to call box with given argument in syntax extension.

(set-special! "#&" 'box)

Nice thing with those two extensions is that if you will want to implement
#u16() you can use syntax extension to add it and it ca be represented as
#u16() when printed.

Those APIs are not orthogonal, first accept function and send symbol but this
can be unified.

--
Jakub T. Jankiewicz, Web Developer
https://jcubic.pl/me