Index: lib/bot.scm ================================================================== --- lib/bot.scm +++ lib/bot.scm @@ -1,5 +1,11 @@ +; [ʞ] bot.scm +; ~ lexi hale +; © 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 ADDED lib/fail.scm Index: lib/fail.scm ================================================================== --- lib/fail.scm +++ lib/fail.scm @@ -0,0 +1,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")) Index: lib/interlace.scm ================================================================== --- lib/interlace.scm +++ lib/interlace.scm @@ -1,37 +1,45 @@ -; ʞ / 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.scm +; ~ lexi hale +; © 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 +; 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: +; 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))) +; 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. +; 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) Index: lib/lisp-macro.scm ================================================================== --- lib/lisp-macro.scm +++ lib/lisp-macro.scm @@ -1,13 +1,16 @@ ; [ʞ] lisp-macro -; enable use of the define-macro syntax -; - example - -; (define-macro (if-or-f . body) +; ~ lexi hale +; © 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)))))))) Index: lib/struct.scm ================================================================== --- lib/struct.scm +++ lib/struct.scm @@ -1,6 +1,9 @@ -; ʞ / struct.scm +; [ʞ] struct.scm +; ~ lexi hale +; © 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 @@ -8,13 +11,13 @@ ; 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. +; 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))]) Index: lib/verb.scm ================================================================== --- lib/verb.scm +++ lib/verb.scm @@ -1,15 +1,18 @@ -; ʞ / 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 +; [ʞ] verb.scm +; ~ lexi hale +; © 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 @@ -23,14 +26,14 @@ ; '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 +; 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 +; 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) @@ -85,18 +88,18 @@ ; - 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. +; 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. +; - 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*)