Welcome to the CHICKEN Scheme pasting service

Perlesque global submatch accessor added by evhan on Wed Apr 4 15:08:12 2012

;;
;; foo =~ /(bar)/
;; $1 # => "bar"
;;
;; (irregex-search "(bar)" foo)
;; ($ 1) ; => "bar"
;;
(module irregex-dollar
  ($ irregex-match irregex-search)
  (import scheme chicken)
  (require-library irregex)
  (import
    (rename irregex
      (irregex-match  orig-irregex-match)
      (irregex-search orig-irregex-search)))
  (reexport
    (except irregex
      irregex-match
      irregex-search))

  (define last-match
    (make-parameter #f))

  (define ($ n)
    (and-let* ((m (last-match)))
      (and (<= n (irregex-match-num-submatches m))
           (irregex-match-substring m n))))

  (define-syntax dollarize
    (syntax-rules ()
      ((_ from to)
       (define (to . args)
         (let ((m (apply from args)))
           (last-match m)
           m)))))

  (dollarize orig-irregex-match  irregex-match)
  (dollarize orig-irregex-search irregex-search))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which version of Scheme does C4 implement?
Visually impaired? Let me spell it for you (wav file) download WAV