[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

symbol-prefix-proc that allows re-prefixing

From: Thien-Thi Nguyen
Subject: symbol-prefix-proc that allows re-prefixing
Date: Sat, 29 May 2004 14:05:34 +0200

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


;; 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)
           (format #f "~A~A" prefix
                   (substring (symbol->string symbol) cut)))))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]