symbol-prefix-proc that allows re-prefixing
Thien-Thi Nguyen <[email protected]>
| Newsgroups | gmane.lisp.guile.user,gmane.lisp.guile.sources |
|---|---|
| Message-ID | <[email protected]> |
example usage:
(use-modules ((database postgres)
#:renamer (symbol-prefix-proc 'PG|||))) ;;; no `cut'
;; => PG|||pg-exec, ...
(use-modules ((database postgres)
#:renamer (symbol-prefix-proc 'PG||| 3))) ;;; `cut'
;; => PG|||exec, ...
(this will appear in guile 1.4.1.99.)
thi
_______________________________________________________________
;; Return a procedure that prefixes its arg (a symbol) with
;; @var{prefix} (also a symbol). Optional arg @var{cut} specifies
;; the number of characters to remove from the head of the original symbol
;; before prefixing (useful for substitution).
;;
;;-sig: (prefix [cut])
;;
(define (symbol-prefix-proc prefix . cut-spec)
;; Insert gratuitous C++ slam here. --ttn
(if (null? cut-spec)
(lambda (symbol)
(symbol-append prefix symbol))
(let ((cut (car cut-spec)))
(lambda (symbol)
(string->symbol
(format #f "~A~A" prefix
(substring (symbol->string symbol) cut)))))))
_______________________________________________
Guile-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/guile-user