feat: add a (radix combinators) module
parent
96d7183112
commit
0c0fd191ca
|
@ -0,0 +1,41 @@
|
|||
(define-module (radix combinators)
|
||||
#:use-module (srfi srfi-26)
|
||||
#:use-module (ice-9 match)
|
||||
#:export (all?
|
||||
any?
|
||||
conjoin
|
||||
disjoin
|
||||
inclusive-disjoin))
|
||||
|
||||
(define (all? pred lst)
|
||||
(null? (filter null? (map pred lst))))
|
||||
|
||||
(define (any? pred lst)
|
||||
(cond ((null? lst) #f)
|
||||
((pred (car lst)) #t)
|
||||
(else (any? pred (cdr lst)))))
|
||||
|
||||
#| (conjoin (list (conjoin '()) predicates)) = (conjoin predicates) |#
|
||||
(define (conjoin . predicates)
|
||||
(lambda args
|
||||
(if (null? predicates) #t
|
||||
(match-let loop (((head-pred . tail-preds) predicates))
|
||||
(cond ((null? tail-preds) (apply head-pred args))
|
||||
((apply head-pred args) (loop tail-preds))
|
||||
(else #f))))))
|
||||
|
||||
#| (disjoin (list (disjoin '()) predicates)) = (disjoin predicates) |#
|
||||
(define (disjoin . predicates)
|
||||
(lambda args
|
||||
(if (null? predicates) #f
|
||||
(null? (cdr (filter (cut apply <> args)
|
||||
predicates))))))
|
||||
|
||||
(define (inclusive-disjoin . predicates)
|
||||
(lambda args
|
||||
(if (null? predicates) #f
|
||||
(match-let loop (((head-pred . tail-preds) predicates))
|
||||
(cond ((null? tail-preds) (apply head-pred args))
|
||||
((not (apply head-pred args)) (loop tail-preds))
|
||||
(else #f))))))
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
(define-module (radix files fish)
|
||||
#:use-module (gnu)
|
||||
#:use-module (ice-9 ftw)
|
||||
#:use-module (ice-9 rdelim)
|
||||
#:use-module (radix combinators)
|
||||
#:use-module (gnu packages shells)
|
||||
#:export (abbreviations
|
||||
fenv
|
||||
|
@ -19,6 +22,31 @@
|
|||
(define variables
|
||||
(local-file "../../../files/fish/variables.fish"))
|
||||
|
||||
(define fenv-dir
|
||||
(run-with-store (open-connection)
|
||||
(package-file fish-foreign-env)))
|
||||
|
||||
(define fenv-files
|
||||
(map (cut string-append fenv-dir "/share/fish/functions/" <>)
|
||||
(filter (negate (cut string-prefix? "." <>))
|
||||
(scandir (string-append fenv-dir
|
||||
"/share/fish/functions")))))
|
||||
|
||||
(define (remove-unimportant-lines str)
|
||||
(string-join
|
||||
(filter (negate (inclusive-disjoin
|
||||
string-null?
|
||||
(cut string-prefix? "#" <>)))
|
||||
(string-split str #\newline))
|
||||
"\n"))
|
||||
|
||||
(define fenv
|
||||
(file-append fish-foreign-env
|
||||
"/share/fish/functions/fenv.fish"))
|
||||
(plain-file "fenv"
|
||||
(string-join
|
||||
(map (lambda (file)
|
||||
(let* ((port (open-input-file file))
|
||||
(content (read-string port)))
|
||||
(close-input-port port)
|
||||
(remove-unimportant-lines content)))
|
||||
fenv-files)
|
||||
"\n")))
|
||||
|
|
Loading…
Reference in New Issue