diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-05-05 20:43:59 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-05-05 20:43:59 +0200 |
commit | 6409c5eff5b02f0aae7c1e5b96f07debc8d62b07 (patch) | |
tree | 633c557a310471e30b2a05ec84d7b166c1cf4ca9 | |
download | mew-6409c5eff5b02f0aae7c1e5b96f07debc8d62b07.tar.gz mew-6409c5eff5b02f0aae7c1e5b96f07debc8d62b07.tar.xz mew-6409c5eff5b02f0aae7c1e5b96f07debc8d62b07.zip |
initial import
-rw-r--r-- | mew.el | 11 | ||||
-rw-r--r-- | mew.import.scm | 88 | ||||
-rw-r--r-- | mew.svnwiki | 114 |
3 files changed, 213 insertions, 0 deletions
diff --git a/mew.el b/mew.el new file mode 100644 index 0000000..ab9c986 --- /dev/null +++ b/mew.el @@ -0,0 +1,11 @@ +(put 'def 'scheme-indent-function 'defun) +(put 'esc 'scheme-indent-function 1) +(put 'fin 'scheme-indent-function 0) +(put 'fun 'scheme-indent-function 1) +(put 'loc 'scheme-indent-function 1) +(put 'rec 'scheme-indent-function 1) +(put 'rep 'scheme-indent-function 'scheme-let-indent) +(put 'seq 'scheme-indent-function 0) + +(put 'if 'scheme-indent-function 1) +(put 'match 'scheme-indent-function 1) diff --git a/mew.import.scm b/mew.import.scm new file mode 100644 index 0000000..176c070 --- /dev/null +++ b/mew.import.scm @@ -0,0 +1,88 @@ +(module mew (dec def div esc fin inc loc mod op prn puts rep str) + (import scheme + (rename (chicken base) + (print puts)) + (chicken module) + (chicken port)) + + (reexport + (only (chicken base) + unless + when + rec)) + + (import + (rename (r7rs) + (floor-quotient div) + (floor-remainder mod))) + + (reexport + (rename (scheme) +; (define def) + (set! set) + (begin seq) ; XXX return #f for (seq) + (lambda fun) + (apply app) + )) + + (define (inc i) + (+ i 1)) + + (define (dec i) + (- i 1)) + + (define (str . args) + (with-output-to-string + (lambda () + (for-each display args)))) + + (define (prn . args) + (if (null? args) + (newline) + (begin + (write (car args)) + (unless (null? (cdr args)) + (display " ")) + (apply prn (cdr args))))) + + (define-syntax def + (syntax-rules () + ((_ . rest) + (define . rest)))) + + (define-syntax esc + (syntax-rules () + ((_ return body ...) + (call-with-current-continuation + (lambda (return) + body ...))))) + + (define-syntax fin + (syntax-rules () + ((_ form rest ...) + (dynamic-wind + (lambda () (begin)) + (lambda () form) + (lambda () rest ...))))) + + (define-syntax loc + (syntax-rules () + ((_ () . rest) + (let () . rest)) + ((_ (x y . brest) . rest) + (let ((x y)) (loc brest . rest))))) + + ;; possible additions: multiple _, allow ... for rest + (define-syntax op + (er-macro-transformer + (lambda (expr rename compare) + `(lambda (_) + ,@(cond ((= 1 (length expr)) '(_)) + ((= 2 (length expr)) (cdr expr)) + (#t (list (cdr expr)))))))) + + (define-syntax rep + (syntax-rules () + ((_ name ((var val) ...) body ...) + (let name ((var val) ...) body ...)))) +) diff --git a/mew.svnwiki b/mew.svnwiki new file mode 100644 index 0000000..88fcdee --- /dev/null +++ b/mew.svnwiki @@ -0,0 +1,114 @@ +Mew is a library targetting R5RS/R7RS scheme, which provides some +conveniences inspired from Goo, Clojure and Arc to allow writing more +compact code. + + +== Definitions, bindings and assignments + +<syntax>(def <variable> <expression>)</syntax> +<syntax>(def (<variable> <formals>) <expression>)</syntax> + +Alias for {{define}}. + +<syntax>(fun <formals> <body>)</syntax> + +Alias for {{lambda}}. + +<syntax>(loc (<var1> <val1> ... <varN> <valN>) <body>)</syntax> + +Binds local variable {{var1}} to the result of evaluating {{val1}}, +then {{var2}} to {{val2}}, etc., then evaluates {{body}}. + +Assignments can refer to previously assigned values of the {{loc}}. + +<syntax>(rec <name> <expression>)</syntax> +<syntax>(rec (<name> <formals>) <expression>)</syntax> + +See Module%20(chicken%20base)#rec or SRFI-31. + +Often, using {{def}} in an inner scope is preferable to using {{rec}}. + +<syntax>(set <variable> <expression>)</syntax> + +Alias for {{set!}}. + + +== Control flow + +<syntax>(esc <escape> <body>)</syntax> + +Bind {{<escape>}} to the current continuation, then run {{<body>}}. +Code should not pass {{<escape>}} outside the lexical scope +and only call it once---use {{call/cc}} else. + +<syntax>(fin <body> . <cleanup>)</syntax> + +Evaluate {{<body>}}, then evaluate {{<cleanup>}}, even if {{<body>}} +used a non-local exit (as from {{esc}}). + +Returns value of {{<body>}}, so can also be used as a replacment +for Common Lisp PROG1. + +<syntax>(rep <name> ((<var> <init>) ...) <body>)</syntax> + +Explicit form of named let. + +<syntax>(seq . <body>)</syntax> + +Alias for {{begin}}. + +<syntax>(unless <cond> <expr>...)</syntax> +<syntax>(when <cond> <expr>...)</syntax> + +As in R7RS-small. + + +== Numeric helpers + +<procedure>(inc <num>)<procedure> +<procedure>(dec <num>)<procedure> + +Increment or decrement the argument by 1. + +<procedure>(div . <num>)</procedure> + +Alias for {{floor-quotient}}. + +<procedure>(mod . <num>)</procedure> + +Alias for {{floor-remainder}}. + + +== General helpers + +<procedure>(app <proc> . <args>)</procedure> + +Alias for {{apply}}. + +<syntax>(op <form>)</syntax> + +Returns a procedure that evaluates {{<form>}} with {{_}} bound to its +only argument. + +If {{<form>>} is empty, behaves as {{(op _)}}, i.e. the identity function. + +{{(op 5)}} is the function that always returns 5. + +{{(op + 2 _)}} is the function that adds 2 to its argument. + +<procedure>(str . <args>)</procedure> + +Returns a new string composed by concatenating the strings given by +applying {{display}} to all {{<args>}}. + + +== Output helpers + +<procedure>(prn . <args>)<procedure> + +{{write}} all {{args}} separated by spaces and terminated by a newline +to the current output stream. + +<procedure>(puts . <args>)<procedure> + +{{display}} all {{args}} terminated by a newline to the current output stream. |