1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
; ʞ / struct.scm
;
; generates immutable, relatively efficient structs. declare
; a struct type x with
; (define x (struct 'field1 'field2)
; create a record y of that type with
; (define y (x 123 456))
; access field1 of record y with
; (y 'field1)
; update field2 of record y with
; (y 'field2 123) → new record (field1 = 123; field2 = 123)
;
; this unit also includes a few utility function that chicken
; scheme conveniently "forgot." i apologize for the implementation
; of (list-head). i was very tired.
; return a sub-list of lst up to ct (inverse of list-tail)
(define (list-head lst ct)
(let* ([reverse-lst (reverse lst)]
[idx (- (length lst) (+ 1 ct))])
(reverse (list-tail reverse-lst idx))))
; i'm not proud of this
|
|
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
|
; [ʞ] struct.scm
; ~ lexi hale <lexi@hale.su>
; © affero general public license
; > (load "lib/struct.scm")
;
; generates immutable, relatively efficient structs. declare
; a struct type x with
; (define x (struct 'field1 'field2)
; create a record y of that type with
; (define y (x 123 456))
; access field1 of record y with
; (y 'field1)
; update field2 of record y with
; (y 'field2 123) → new record (field1 = 123; field2 = 123)
;
; this unit also includes a few utility function that
; chicken scheme conveniently "forgot." i apologize for
; the implementation of (list-head). i was very tired.
; return a sub-list of lst up to ct (inverse of list-tail)
(define (list-head lst ct)
(let* ([reverse-lst (reverse lst)]
[idx (- (length lst) (+ 1 ct))])
(reverse (list-tail reverse-lst idx))))
; i'm not proud of this
|