summaryrefslogtreecommitdiffstats
path: root/mpd.scm
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-03-03 01:08:16 -0800
committerGravatar Tom Willemse2022-03-03 01:08:16 -0800
commitc12a766e1920e726129dfd1161a2ef15471f89e8 (patch)
treeda1347e2ee4330fe46fb04dc14134e9c1e32ba65 /mpd.scm
parent5c371433b9ba76da6fde27849775e5bf9c4c7db4 (diff)
downloadmpd-random-albums-c12a766e1920e726129dfd1161a2ef15471f89e8.tar.gz
mpd-random-albums-c12a766e1920e726129dfd1161a2ef15471f89e8.zip
Lispify the MPD queryHEADmaster
Write a small DSL for converting a simple lisp expression to an MPD query format. This turns, for example: (and (= artist "Katatonia") (= album "Last Fair Deal Gone Down")) Into: ((artist == "Katatonia") AND (album == "Last Fair Deal Gone Down")) The expressions inside ‘query’ are quasi-quoted, so that variable substitution is possible.
Diffstat (limited to 'mpd.scm')
-rw-r--r--mpd.scm22
1 files changed, 22 insertions, 0 deletions
diff --git a/mpd.scm b/mpd.scm
new file mode 100644
index 0000000..74d297b
--- /dev/null
+++ b/mpd.scm
@@ -0,0 +1,22 @@
+(define-structure mpd (export query)
+ (open scheme-with-scsh)
+ (begin
+ (define-syntax query
+ (syntax-rules ()
+ ((_ a)
+ (mpd-query-1 `a))))
+
+ (define (mpd-query-equals params)
+ (apply format #f "~s == ~s" params))
+
+ (define (mpd-query-and params)
+ (format #f "~a AND ~a"
+ (mpd-query-1 (car params))
+ (mpd-query-1 (cadr params))))
+
+ (define (mpd-query-1 query)
+ (format #f "(~a)"
+ (let ((op (car query)))
+ (case op
+ ('= (mpd-query-equals (cdr query)))
+ ('and (mpd-query-and (cdr query)))))))))