Changeset 33699 in project


Ignore:
Timestamp:
10/05/16 16:19:42 (3 years ago)
Author:
Alex Shinn
Message:

treat keywords as literals, not identifiers, in Chicken (ticket #1333)

Location:
release/4/matchable
Files:
2 edited
6 copied

Legend:

Unmodified
Added
Removed
  • release/4/matchable/tags/3.7/match.scm

    r33292 r33699  
    228228;;   http://synthcode.com/scheme/match-cond-expand.scm
    229229;;
     230;; 2016/10/05 - treat keywords as literals, not identifiers, in Chicken
    230231;; 2016/03/06 - fixing named match-let (thanks to Stefan Israelsson Tampe)
    231232;; 2015/05/09 - fixing bug in var extraction of quasiquote patterns
     
    424425    ;; compare it with EQUAL?.
    425426    ((match-two v x g+s (sk ...) fk (id ...))
    426      (let-syntax
    427          ((new-sym?
    428            (syntax-rules (id ...)
    429              ((new-sym? x sk2 fk2) sk2)
    430              ((new-sym? y sk2 fk2) fk2))))
    431        (new-sym? random-sym-to-match
    432                  (let ((x v)) (sk ... (id ... x)))
    433                  (if (equal? v x) (sk ... (id ...)) fk))))
     427     ;; This extra match-check-identifier is optional in general, but
     428     ;; can serve as a fast path, and is needed to distinguish
     429     ;; keywords in Chicken.
     430     (match-check-identifier
     431      x
     432      (let-syntax
     433          ((new-sym?
     434            (syntax-rules (id ...)
     435              ((new-sym? x sk2 fk2) sk2)
     436              ((new-sym? y sk2 fk2) fk2))))
     437        (new-sym? random-sym-to-match
     438                  (let ((x v)) (sk ... (id ... x)))
     439                  (if (equal? v x) (sk ... (id ...)) fk)))
     440      (if (equal? v x) (sk ... (id ...)) fk)))
    434441    ))
    435442
     
    926933           (cadr (cddr expr)))))))
    927934
     935 (chicken
     936  (define-syntax match-check-ellipsis
     937    (er-macro-transformer
     938     (lambda (expr rename compare)
     939       (if (compare '... (cadr expr))
     940           (car (cddr expr))
     941           (cadr (cddr expr))))))
     942  (define-syntax match-check-identifier
     943    (er-macro-transformer
     944     (lambda (expr rename compare)
     945       (if (and (symbol? (cadr expr)) (not (keyword? (cadr expr))))
     946           (car (cddr expr))
     947           (cadr (cddr expr)))))))
     948
    928949 (else
    929950  ;; Portable versions
    930951  ;;
    931   ;; This *should* work, but doesn't :(
     952  ;; This is the R7RS version.  For other standards, and
     953  ;; implementations not yet up-to-spec we have to use some tricks.
     954  ;;
    932955  ;;   (define-syntax match-check-ellipsis
    933956  ;;     (syntax-rules (...)
  • release/4/matchable/tags/3.7/matchable.setup

    r33299 r33699  
    44(install-extension 'matchable
    55 '("matchable.so" "matchable.import.so")
    6  '((version "3.6")))
     6 '((version "3.7")))
  • release/4/matchable/trunk/match.scm

    r33292 r33699  
    228228;;   http://synthcode.com/scheme/match-cond-expand.scm
    229229;;
     230;; 2016/10/05 - treat keywords as literals, not identifiers, in Chicken
    230231;; 2016/03/06 - fixing named match-let (thanks to Stefan Israelsson Tampe)
    231232;; 2015/05/09 - fixing bug in var extraction of quasiquote patterns
     
    424425    ;; compare it with EQUAL?.
    425426    ((match-two v x g+s (sk ...) fk (id ...))
    426      (let-syntax
    427          ((new-sym?
    428            (syntax-rules (id ...)
    429              ((new-sym? x sk2 fk2) sk2)
    430              ((new-sym? y sk2 fk2) fk2))))
    431        (new-sym? random-sym-to-match
    432                  (let ((x v)) (sk ... (id ... x)))
    433                  (if (equal? v x) (sk ... (id ...)) fk))))
     427     ;; This extra match-check-identifier is optional in general, but
     428     ;; can serve as a fast path, and is needed to distinguish
     429     ;; keywords in Chicken.
     430     (match-check-identifier
     431      x
     432      (let-syntax
     433          ((new-sym?
     434            (syntax-rules (id ...)
     435              ((new-sym? x sk2 fk2) sk2)
     436              ((new-sym? y sk2 fk2) fk2))))
     437        (new-sym? random-sym-to-match
     438                  (let ((x v)) (sk ... (id ... x)))
     439                  (if (equal? v x) (sk ... (id ...)) fk)))
     440      (if (equal? v x) (sk ... (id ...)) fk)))
    434441    ))
    435442
     
    926933           (cadr (cddr expr)))))))
    927934
     935 (chicken
     936  (define-syntax match-check-ellipsis
     937    (er-macro-transformer
     938     (lambda (expr rename compare)
     939       (if (compare '... (cadr expr))
     940           (car (cddr expr))
     941           (cadr (cddr expr))))))
     942  (define-syntax match-check-identifier
     943    (er-macro-transformer
     944     (lambda (expr rename compare)
     945       (if (and (symbol? (cadr expr)) (not (keyword? (cadr expr))))
     946           (car (cddr expr))
     947           (cadr (cddr expr)))))))
     948
    928949 (else
    929950  ;; Portable versions
    930951  ;;
    931   ;; This *should* work, but doesn't :(
     952  ;; This is the R7RS version.  For other standards, and
     953  ;; implementations not yet up-to-spec we have to use some tricks.
     954  ;;
    932955  ;;   (define-syntax match-check-ellipsis
    933956  ;;     (syntax-rules (...)
  • release/4/matchable/trunk/matchable.setup

    r33299 r33699  
    44(install-extension 'matchable
    55 '("matchable.so" "matchable.import.so")
    6  '((version "3.6")))
     6 '((version "3.7")))
Note: See TracChangeset for help on using the changeset viewer.