From 76b11b0cf5b73ad1d0a25f2d91e8717b8d7237a3 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Wed, 23 Oct 2024 09:02:27 -0500 Subject: [PATCH] init commit --- .gitignore | 3 +++ Makefile.in | 15 +++++++++++++++ configure | 8 ++++++++ d-.scm | 20 ++++++++++++++++++++ test.scm | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile.in create mode 100755 configure create mode 100644 d-.scm create mode 100644 test.scm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d727743 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +*.go +Makefile \ No newline at end of file diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..edba529 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,15 @@ +.PHONY: all clean test install todo + +all: d-.go +clean: + rm -rf d-.go +test: + guile -L . test.scm +install: d-.scm d-.go + install -D -t "$(INSTALL_PREFIX)/share/guile/site/3.0/" d-.scm + install -D -t "$(INSTALL_PREFIX)/lib/guile/3.0/site-ccache/" d-.go +uninstall: + rm -f "$(INSTALL_PREFIX)/share/guile/site/3.0/d-.scm" + rm -f "$(INSTALL_PREFIX)/lib/guile/3.0/site-ccache/d-.go" +%.go: %.scm + guild compile $^ -o $@ diff --git a/configure b/configure new file mode 100755 index 0000000..7f667aa --- /dev/null +++ b/configure @@ -0,0 +1,8 @@ +#!/usr/bin/bash + +case $1 in + --prefix) + sed '1i\'INSTALL_PREFIX="$2" < Makefile.in > Makefile + shift 2 + ;; +esac diff --git a/d-.scm b/d-.scm new file mode 100644 index 0000000..5939457 --- /dev/null +++ b/d-.scm @@ -0,0 +1,20 @@ +(define-module (d-) + #:export + (~> + ~>> + partial)) + +(define-syntax ~> + (syntax-rules () + [(_ v) v] + [(_ v (fn args ...) more ...) (~> (fn v args ...) more ...)] + [(_ v fn more ...) (~> (fn v) more ...)])) + +(define-syntax ~>> + (syntax-rules () + [(_ v) v] + [(_ v (fn args ...) more ...) (~> (fn args ... v) more ...)] + [(_ v fn more ...) (~> (fn v) more ...)])) + +(define (partial fn . args) + (lambda x (apply fn (append args x)))) diff --git a/test.scm b/test.scm new file mode 100644 index 0000000..ccd5dee --- /dev/null +++ b/test.scm @@ -0,0 +1,32 @@ +(use-modules (d-) + (rnrs base)) + +(define-syntax-rule (define-unit-test (test-name body ...)) + (let () body ...)) + +(define-syntax-rule (define-test module-name tests ...) + (begin (define-unit-test tests) ...)) + +(define-test ~> + (unwrapped + (define value (~> 1 1+ 1+)) + (assert (= value 3))) + (wrapped + (define value (~> 1 (/ 2) (/ 2))) + (assert (= value 1/4)))) + +(define-test ~>> + (unwrapped + (define value (~>> 1 1+ 1+)) + (assert (= value 3))) + (wrapped + (define value (~>> 1 (/ 2) (/ 2))) + (assert (= value 1)))) + +(define-test partial + (test + (define value (partial / 2)) + (assert (= (value 4) 1/2)) + (assert (= (value 1) 2)))) + +