diff options
author | Tom Willemse | 2022-03-03 01:08:16 -0800 |
---|---|---|
committer | Tom Willemse | 2022-03-03 01:08:16 -0800 |
commit | c454bde37c777bf422a7df729fb9ff43c2ef3f3c (patch) | |
tree | 4b62a3b9ff685b6238ff4cd424bb1970f5ce434d /mpd/usr/share | |
parent | 79df03a72ad0dc7c13f5e313f5038786dc38bc90 (diff) | |
download | new-dotfiles-c454bde37c777bf422a7df729fb9ff43c2ef3f3c.tar.gz new-dotfiles-c454bde37c777bf422a7df729fb9ff43c2ef3f3c.zip |
[mpd] Lispify the MPD query
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/usr/share')
-rw-r--r-- | mpd/usr/share/scsh/mpd.scm | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/mpd/usr/share/scsh/mpd.scm b/mpd/usr/share/scsh/mpd.scm new file mode 100644 index 0000000..74d297b --- /dev/null +++ b/mpd/usr/share/scsh/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))))))))) |