procgen  Check-in [294d779091]

Overview
Comment:tidy up headers
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 294d779091b20c3249b5c507e1ba139551d1b29b2a186e76e85a1a5731f88475
User & Date: lexi on 2019-04-17 23:45:48
Other Links: manifest | tags
Context
2019-05-02
07:54
ipdates check-in: 588ff265a6 user: lexi tags: trunk
2019-04-17
23:45
tidy up headers check-in: 294d779091 user: lexi tags: trunk
22:45
remove outdated readme check-in: 6e90584b3f user: lexi tags: trunk
Changes

Modified lib/bot.scm from [851e9817dd] to [d5281d581a].







1
2
3
4
5
6
7






; prep the random number generator
(import (chicken random))
(set-pseudo-random-seed! (random-bytes))

; generates a (case) structure that randomly returns
; one of its branches at equal probability
(define-for-syntax (@one-of case-fn strs)
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
; [ʞ] bot.scm
;  ~ lexi hale <lexi@hale.su>
;  © affero general public license
;  > (load "lib/lisp-macro.scm")
;    (load "lib/bot.scm")

; prep the random number generator
(import (chicken random))
(set-pseudo-random-seed! (random-bytes))

; generates a (case) structure that randomly returns
; one of its branches at equal probability
(define-for-syntax (@one-of case-fn strs)

Added lib/fail.scm version [112daec7b2].



















>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
; [ʞ] fail.scm
; generates pretty error messages

(define (fail . msg)
	(display (string-append "\x1b[1;31m - err.\x1b[0m " 
							(apply string-append msg)))
	(exit 1))
(define (fail:sym s)
  (fail "bad form \x1b[3;36m'" (symbol->string s) "\x1b[0m"))

Modified lib/interlace.scm from [fd266dcc3b] to [a82d9652e8].

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
26
27
28
29
30


31
32
33
34
35
36
37
38
39
; ʞ / interlace.scm
;   a scheme library by lexi hale



;
; (interlace) solves an age-old problem. what kind of data structure
; do you use when you need both an aggregate (a list, a vector) of
; items but also to be able to individually refer to those items by




; name? this problem is effectively unsolvable in C and C++ without
; inordinate runtime overhead, and there's no native syntax for it

; in Scheme. however, by rewriting the AST, we can implement a clean,
; performant, low-cost solution ourselves, thanks to the fact that

; (let*) bindings are expressions.
;
; interlace takes a constructor function, e.g. (vector) or (list),


; a list of items, and returns an expression calling that constructor
; on a list of all items defined in it. if an item is proceded by
; an atom that ends in a period (e.g. “name.”), it is defined within
; a (let*) expression, and its name is then included among the


; arguments passed to the constructor function.
;
; the upshot of this is that items can reference other items by name


; *as they are being defined*. for instance:
;
;	(define verbs (interlace vector
;	                         talk. (verb "talk" "talking" "talked")
;		                         (phrasal-verb talk "to")
;		                         (phrasal-verb talk "about")
;		                     (verb "say" "saying" "said)))
;
; here, the function to generate a phrasal verb exhibits backreference
; to an existing verb contained alongside it in the vector. note that 


; the name bindings are ephemeral; they do not survive the immediate
; context of the constructor.

(define-macro (interlace . body)
  ; given a list with both named and nameless members, identify
  ; which is which and instate the vector.
  (define (name? term)
	; given a symbol, determine wheter it is a name, and if so return
	; that name as a string and without the name-marking suffix ‹.›
|
|
>
>
>
|
<
<
<
>
>
>
>
|
<
>
|
|
>
|

<
>
>
|
|
<
<
>
>


<
>
>
|

|
|
|
|
|

|
<
>
>
|
|







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

26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
; [ʞ] interlace.scm
;  ~ lexi hale <lexi@hale.su>
;  © affero general public license
;  > (load "lib/lisp-macro.scm")
;    (load "lib/interlace.scm")




; (interlace) solves  an old  problem. what kind  of data
; structure do  you use when  you need both  an aggregate
; (a  list,  a vector)  of  items  but  also to  be  able
; to  individually refer  to  those items  by name?  this
; problem is effectively unsolvable  in C and C++ without

; inordinate  runtime  overhead,  and there's  no  native
; syntax for it in Scheme. however, by rewriting the AST,
; we can implement a clean, performant, low-cost solution
; ourselves, thanks to the  fact that (let*) bindings are
; expressions.
;

; interlace takes  a constructor function,  e.g. (vector)
; or (list), a  list of items, and  returns an expression
; calling that constructor on a list of all items defined
; in it. if an item is proceded by an atom that ends in a


; period (e.g.  “name.”), it  is defined within  a (let*)
; expression,  and its  name is  then included  among the
; arguments passed to the constructor function.
;

; the upshot  of this is  that items can  reference other
; items  by  name  *as   they  are  being  defined*.  for
; instance:
;
; ex:	(define verbs (interlace vector
;			talk. (verb "talk" "talking" "talked")
;				(phrasal-verb talk "to")
;				(phrasal-verb talk "about")
;			(verb "say" "saying" "said)))
;
; here, the function to  generate a phrasal verb exhibits

; backreference to  an existing verb  contained alongside
; it  in the  vector.  note that  the  name bindings  are
; ephemeral; they do not survive the immediate context of
; the constructor.

(define-macro (interlace . body)
  ; given a list with both named and nameless members, identify
  ; which is which and instate the vector.
  (define (name? term)
	; given a symbol, determine wheter it is a name, and if so return
	; that name as a string and without the name-marking suffix ‹.›

Modified lib/lisp-macro.scm from [abec99f409] to [ad02b3f2ba].

1




2
3
4
5
6
7
8
9
10
11
12
13
; [ʞ] lisp-macro




; enable use of the define-macro syntax
; - example -
; 		(define-macro (if-or-f . body)
;			`(if ,(car body) ,(cadr body) #f))

(define-syntax define-macro
	(er-macro-transformer (lambda (exp r c)
		`(define-syntax ,(caadr exp)
			(er-macro-transformer
				(lambda (,(cdadr exp) id-rename id-compare)
					(let ((,(cdadr exp) (cdr ,(cdadr exp))))
			 			,@(cddr exp))))))))

>
>
>
>
|
<
|









1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
; [ʞ] lisp-macro
;  ~ lexi hale <lexi@hale.su>
;  © affero general public license
;  > (load "lib/lisp-macro.scm")

; enable use of the define-macro syntax in chicken scheme

; ex:	(define-macro (if-or-f . body)
;			`(if ,(car body) ,(cadr body) #f))

(define-syntax define-macro
	(er-macro-transformer (lambda (exp r c)
		`(define-syntax ,(caadr exp)
			(er-macro-transformer
				(lambda (,(cdadr exp) id-rename id-compare)
					(let ((,(cdadr exp) (cdr ,(cdadr exp))))
			 			,@(cddr exp))))))))

Modified lib/struct.scm from [833aa00a5f] to [06f94eb978].

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

Modified lib/verb.scm from [98598e4655] to [fa196ac94e].

1


2
3


4
5
6
7
8

9
10

11
12
13
14
15
16
17
..
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
..
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
; ʞ / verb.scm


;	(depends lisp-macro.scm struct.scm)
;	a library by lexi hale


;
; macros, functions, and rules for conjugating verbs and 
; generating verb phrases. this library rules was written 
; specifically for english verbs and cannot be used as a
; "drop-in" library for other languages; however, the

; structured and functions used are sufficiently generic
; that it should be portable to other languages with

; minimal effort.

;;;; section i. generic functions & structures

; struct verb
;  fields contain conjugation functions for the specified
;  tense. ((v 'inf) object) will generate a verb phrase string
................................................................................
;   'ger: gerund (-ing form)
;   'pst: past (-ed form)
;   'ppl: past participle (often -ed or -en)
; * l10n note: the fields mentioned in the last line of the
;   (verb-form) macro must always match the fields listed in
(define verb (struct 'inf 'prs 'ger 'adj 'pst 'ppl))

; takes a list of individual strings and joins them with
; spaces. occurrences of "a" are automatically replace by
; "an" if the word following them appears to start with a
; vowel. this can be forcibly induced by preceeding that
; word with the symbol 'vowel in the list
; TODO: make it handle initialisms. yes, everything about
; this is horrible. yes, this *is* the wrong way to do it.
; yes, i *am* ashamed. why do you ask
(define (word-append . body)
  (define (vowel? c) (member c '("a" "e" "i" "o" "u")))
  (define (vowel-onset? w)
................................................................................

; create a compound form a verb that already exists
; - prefix: prefix to append (e.g. up, out, over, un)
; - vb: final, "stem" verb
(define (compound prefix vb) (lambda (form) (lambda (*o*)
	  (word-append (string-append prefix ((vb form) *o*))))))

; create a verb where another string interposes between the
; root verb and the object. this can be used to implement
; object incorporation or prepositional verbs such as "get
; off on" (not to be confused with phrasal verbs)
; a phrasal verb.
; - vb: the root (leftmost) verb
; - pps: the preposition complex immediately following the
;   verb.
(define (postpositive vb post) (lambda (form) (lambda (*o*)
	(if (or (equal? form 'ppl) (equal? form 'adj))
		(word-append
		  (string-append ((vb form) '()) "-" post)
		  *o*)
		(word-append ((vb form) '()) post *o*)))))

|
>
>
|
<
>
>
|
|
|
|
<
>
|
<
>







 







|


|







 







|
|
|
|
|

|
|







1
2
3
4

5
6
7
8
9
10

11
12

13
14
15
16
17
18
19
20
..
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
; [ʞ] verb.scm
;  ~ lexi hale <lexi@hale.su>
;  © affero general public license
;  > (load "lib/lisp-macro.scm")

;    (load "lib/struct.scm")
;    (load "lib/verb.scm")

; macros, functions, and rules  for conjugating verbs and
; generating verb phrases. this library rules was written
; specifically for english verbs and  cannot be used as a

; "drop-in"  library for  other  languages; however,  the
; structured and functions  used are sufficiently generic

; that  it should  be  portable to  other languages  with
; minimal effort.

;;;; section i. generic functions & structures

; struct verb
;  fields contain conjugation functions for the specified
;  tense. ((v 'inf) object) will generate a verb phrase string
................................................................................
;   'ger: gerund (-ing form)
;   'pst: past (-ed form)
;   'ppl: past participle (often -ed or -en)
; * l10n note: the fields mentioned in the last line of the
;   (verb-form) macro must always match the fields listed in
(define verb (struct 'inf 'prs 'ger 'adj 'pst 'ppl))

; takes a list of individual  strings and joins them with
; spaces. occurrences of "a" are automatically replace by
; "an" if the word following them appears to start with a
; vowel. this can be  forcibly induced by preceeding that
; word with the symbol 'vowel in the list
; TODO: make it handle initialisms. yes, everything about
; this is horrible. yes, this *is* the wrong way to do it.
; yes, i *am* ashamed. why do you ask
(define (word-append . body)
  (define (vowel? c) (member c '("a" "e" "i" "o" "u")))
  (define (vowel-onset? w)
................................................................................

; create a compound form a verb that already exists
; - prefix: prefix to append (e.g. up, out, over, un)
; - vb: final, "stem" verb
(define (compound prefix vb) (lambda (form) (lambda (*o*)
	  (word-append (string-append prefix ((vb form) *o*))))))

; create a  verb where another string  interposes between
; the  root verb  and the  object.  this can  be used  to
; implement object  incorporation or  prepositional verbs
; such as "get  off on" (not to be  confused with phrasal
; verbs) a phrasal verb.
; - vb: the root (leftmost) verb
; - pps: the preposition complex immediately following
;   the verb.
(define (postpositive vb post) (lambda (form) (lambda (*o*)
	(if (or (equal? form 'ppl) (equal? form 'adj))
		(word-append
		  (string-append ((vb form) '()) "-" post)
		  *o*)
		(word-append ((vb form) '()) post *o*)))))