2018-04-03 23:02:56 +02:00
|
|
|
LISP provides a function, `defstruct`, which creates a data
|
|
|
|
structure and functions for accessing various fields in it.
|
|
|
|
This can be useful, so I'm doing something similar here.
|
|
|
|
|
|
|
|
(defstruct book title author subject book-id )
|
|
|
|
|
|
|
|
~~~
|
|
|
|
{{
|
|
|
|
:make-helper (nsq-) [ d:create , ] dip does ;
|
|
|
|
:make-struct (ns-) d:create , [ here swap fetch allot ] does ;
|
|
|
|
---reveal---
|
2019-01-03 22:49:43 +01:00
|
|
|
:defstruct (sa-)
|
2019-04-24 16:02:15 +02:00
|
|
|
dup a:length
|
2018-04-03 23:02:56 +02:00
|
|
|
[ n:dec swap
|
|
|
|
[ 'ab 'aabab reorder
|
|
|
|
'@ s:append [ fetch + fetch ] make-helper
|
|
|
|
'! s:append [ fetch + store ] make-helper
|
|
|
|
n:dec
|
2019-04-24 16:02:15 +02:00
|
|
|
] a:for-each drop
|
2018-04-03 23:02:56 +02:00
|
|
|
] sip swap make-struct ;
|
|
|
|
}}
|
|
|
|
~~~
|
|
|
|
|
2019-02-13 20:26:45 +01:00
|
|
|
```
|
2019-01-03 22:49:43 +01:00
|
|
|
'book { 'title 'author 'subject 'book-id } defstruct
|
2018-04-03 23:02:56 +02:00
|
|
|
|
|
|
|
book 'A const
|
2019-01-03 22:49:43 +01:00
|
|
|
"The_Hobbit &A title!
|
|
|
|
"J.R.R._Tolkien &A author!
|
|
|
|
"Fantasy &A subject!
|
2018-04-03 23:02:56 +02:00
|
|
|
|
|
|
|
:info (a-)
|
|
|
|
[ subject@ ] [ author@ ] [ title@ ] tri
|
2018-05-07 18:36:37 +02:00
|
|
|
'%s_by_%s_is_a_%s_book. s:format s:put nl ;
|
2018-04-03 23:02:56 +02:00
|
|
|
|
|
|
|
&A info
|
2019-02-13 20:26:45 +01:00
|
|
|
```
|