LINUX.ORG.RU

История изменений

Исправление Flogger_d, (текущая версия) :

Вообще все переделал, чтобы было удобнее. Теперь так:

(use-modules (ice-9 regex))
(use-modules (ice-9 syncase))

(define re "LAYER\\s+([a-zA-Z][a-zA-Z0-9_]*)")
(define sample "LAYER M1")

(define (make-next-match match) 
 (let ((idx 0)) 
	(lambda ()
	 (set! idx (+ idx 1))
	 (let ((range (vector-ref match idx)) (sample (vector-ref match 0)))
	  (substring sample (car range)(cdr range))))))


(define-syntax with-matched
 (syntax-rules () 
	((_ (var0 var ...) expr ... )
	 (lambda (match) 
		 (let* ( (next-match (make-next-match match))
                           (var0 (next-match)) (var (next-match)) ...
                         )	expr ... )))))


(cond 
 ((string-match re sample) =>
  (with-matched (m lyrName) (format #t "Recognized LAYER statement: layer name is '~a'\n" lyrName)))
 (else (format #t "No match at all\n")))

Исправление Flogger_d, :

Вообще все переделал, чтобы было удобнее. Теперь так:

(use-modules (ice-9 regex))
(use-modules (ice-9 syncase))

(define re "LAYER\\s+([a-zA-Z][a-zA-Z0-9_]*)")
(define sample "LAYER M1")

(define (make-next-match match) 
 (let ((idx 0)) 
	(lambda ()
	 (set! idx (+ idx 1))
	 (let ((range (vector-ref match idx)) (sample (vector-ref match 0)))
	  (substring sample (car range)(cdr range))))))


(define-syntax with-matched
 (syntax-rules () 
	((_ (var0 var ...) expr ... )
	 (lambda (match) 
		 (let* ( (next-match (make-next-match match))
			   (var0 (next-match)) (var (next-match)) ...
			 )	expr ... )))))


(cond 
 ((string-match re sample) =>
  (with-matched (m lyrName) (format #t "Recognized LAYER statement: layer name is '~a'\n" lyrName)))
 (else (format #t "No match at all\n")))

Исходная версия Flogger_d, :

Вообще все переделал, чтобы было удобнее. Теперь так:

(use-modules (ice-9 regex))
(use-modules (ice-9 syncase))

(define re "LAYER\\s+([a-zA-Z][a-zA-Z0-9_]*)")
(define sample "LAYER M1")

(define (make-next-match match) 
 (let ((idx 0)) 
	(lambda ()
	 (set! idx (+ idx 1))
	 (let ((range (vector-ref match idx)) (sample (vector-ref match 0)))
	  (substring sample (car range)(cdr range))))))


(define-syntax with-matched
 (syntax-rules () 
	((_ (var0 var ...) expr ... )
	 (lambda (match) 
		 (let* ( (next-match (make-next-match match))
						(var0 (next-match)) (var (next-match)) ...
					 )	expr ... )))))


(cond 
 ((string-match re sample) =>
  (with-matched (m lyrName) (format #t "Recognized LAYER statement: layer name is '~a'\n" lyrName)))
 (else (format #t "No match at all\n")))