Added a module for (pre-post-order) utilities

master
Brady McDonough 5 years ago
parent 1c1647aecf
commit b4c3d68a09

@ -1,6 +1,6 @@
TARGET := $(shell guile -c "(display (%site-dir))")
CCACHE := $(shell guile -c "(display(%site-ccache-dir))")
OBJ := csv.go
OBJ := csv.go transform.scm
.PHONY: all clean install uninstall
all: $(OBJ)

@ -1,7 +1,8 @@
;; guile-csv
;; Copyright (C) 2008, 2012, 2013
;; Copyright (C) 2008, 2012, 2013, 2021
;; Andy Wingo <wingo at pobox dot com>
;; Nala Ginrut <nalaginrut@gmail.com>
;; Brady McDonough
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU Lesser General Public License as

@ -0,0 +1,45 @@
;; guile-csv transform
;; Copyright (C) 2021
;; Brady McDonough
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU Lesser General Public License as
;; published by the Free Software Foundation; either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public
;; License along with this program; if not, contact:
;;
;; Free Software Foundation, Inc. Voice: +1-617-542-5942
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
;; Boston, MA 02110-1301, USA gnu@gnu.org
(define-module (csv transform)
#:use-module (ice-9 receive)
#:use-module (sxml transform)
#:export (bubble-term)
#:reexport (pre-post-order))
(define (key-contains-defer str)
(lambda ($pair) (string-contains (symbol->string (car $pair)) str)))
;; Generates a handler for pre-post-order.
;; EXAMPLE USAGE:
;; (pre-post-order $tree `(,(bubble-term rec "key-name")
;; (*default* . ,(lambda x x))))
;; This will generate a rule which travels in *preorder* to each record named
;;'rec' and replace the rec symbol with the pair keyed as "key-name"
(define-syntax bubble-term
(syntax-rules ()
((_ record-sym $str)
`(record-sym *preorder* .
,(lambda $record
(let* (($lst (cadr $record)))
(receive (head rest)
(partition (key-contains-defer $str) $lst)
(cons head (cons rest '())))))))))
Loading…
Cancel
Save