59 lines
1.8 KiB
Org Mode
59 lines
1.8 KiB
Org Mode
#+TITLE: Babel Library
|
|
#+PROPERTY: header-args:scheme: :session *guile* :prologue "(use-modules (ice-9 pretty-print))"
|
|
|
|
This library contains code blocks to be used by other files in this repository.
|
|
|
|
* Converting Lists
|
|
|
|
Converting org lists into guix ~use-~ calls.
|
|
|
|
#+NAME: list-to-use
|
|
#+begin_src scheme :var use-call="use-modules" :var entries='() :var all-parens=0 :results output
|
|
(pretty-print
|
|
`(,(string->symbol use-call)
|
|
,@(map (lambda (x)
|
|
(let ((splits (string-split x #\ )))
|
|
(if (and (= (length splits) 1)
|
|
(= 0 all-parens))
|
|
(string->symbol (car splits))
|
|
(map (lambda (y) (string->symbol y))
|
|
splits))))
|
|
entries)))
|
|
#+end_src
|
|
|
|
Converting Org lists into Scheme symbol lists.
|
|
|
|
#+NAME: sym-list-sample
|
|
- Entry 1
|
|
- Entry 2
|
|
|
|
#+NAME: org-to-scheme-sym-list
|
|
#+begin_src scheme :var input=sym-list-sample :results output
|
|
(pretty-print
|
|
`(list
|
|
,@(map (lambda (x) (string->symbol x)) input)))
|
|
#+end_src
|
|
|
|
#+RESULTS: org-to-scheme-sym-list
|
|
: ice-9/boot-9.scm:1685:16: In procedure raise-exception:
|
|
: Wrong type to apply: "Entry 1"
|
|
:
|
|
: Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
|
|
: scheme@(guile-user) [1]>
|
|
|
|
* Converting Tables
|
|
|
|
#+NAME: service-converter
|
|
#+begin_src scheme :var input='() :colnames yes :results code
|
|
(pretty-print
|
|
`(list
|
|
,@(map
|
|
(lambda (row)
|
|
(let ((service-name (car row))
|
|
(configuration (cadr row)))
|
|
`(service ,(string->symbol (string-append service-name "-service-type"))
|
|
(,(string->symbol (string-append service-name "-configuration"))
|
|
,@(call-with-input-string configuration
|
|
read)))))
|
|
input)))
|
|
#+end_src
|