Changeset 37616 in project


Ignore:
Timestamp:
05/25/19 10:28:50 (3 weeks ago)
Author:
sjamaan
Message:

Matchable: use unquoted record identifiers when matching records

Location:
release/5/matchable/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/5/matchable/trunk/matchable.scm

    r37615 r37616  
    3030  (define-syntax is-a?
    3131    (syntax-rules ()
    32       ((_ obj type) (record-instance? obj (quote type)))))
     32      ((_ obj type) (record-instance? obj type))))
    3333
    3434  (include "match.scm")
  • release/5/matchable/trunk/tests/run.scm

    r35591 r37616  
    11#;(include "../matchable.scm")
    22
    3 (import scheme (chicken base) (chicken memory representation)
    4         matchable test)
     3(import scheme (chicken base) matchable test)
    54
    65(test-begin "match")
     
    103102          x)))
    104103
    105 #+(not alexpander)
    106104(test-group "records"
     105  (module boxes (box make-box)
     106    (import scheme (chicken base))
     107    (define-record box value))
     108
     109  (import boxes)
     110
    107111  (define-record point x y)
    108112  (define-record-type my-box (make-my-box x) box? (x get-my-box-x))
    109113
    110   (test "record"
     114  (test "toplevel record using raw name"
     115        '(123 456)
     116        (match (make-point 123 456) (($ 'point x y) (list x y))))
     117 
     118  (test "toplevel record using identifier"
    111119        '(123 456)
    112120        (match (make-point 123 456) (($ point x y) (list x y))))
    113121
     122  (test-error "module-namespaced record using invalid raw name fails"
     123              (match (make-box 123) (($ 'foo#box x) (list x))))
     124
     125  (test "module-namespaced record using raw name"
     126        '(123)
     127        (match (make-box 123) (($ 'boxes#box x) (list x))))
     128
     129  (test "module-namespaced record using identifier"
     130        '(456)
     131        (match (make-box 456) (($ box x) (list x))))
     132 
    114133  (test "record with different predicate name"
    115134        'ok
     
    123142
    124143  (test-error "record with @ pattern should fail"
    125         (match (make-point 123 456) ((@ point (x a) (y b)) 'ok)))
     144              (match (make-point 123 456) ((@ point (x a) (y b)) 'ok)))
    126145
    127146
Note: See TracChangeset for help on using the changeset viewer.