rhombus-prototype icon indicating copy to clipboard operation
rhombus-prototype copied to clipboard

Unquoted matches are not available in the same pattern

Open usaoc opened this issue 1 year ago • 0 comments

Unquoted matches, that is, $ matches in a '' pattern, are not available within that pattern, even to later subpatterns. For example,

#lang rhombus/static
'1 2' is_a matching(
  '$(first_int :: Int)
     $(pattern:
         kind ~term
       | '$(second_int :: Int)':
           match_when first_int.unwrap() == second_int.unwrap())'
)

this program does not work, nor does

#lang rhombus/static
syntax_class SomeInt(int):
  kind ~term
| '$(this_int :: Int)':
    match_when this_int.unwrap() == int

'1 2' is_a matching(
  '$(first_int :: Int)
     $(_ :: SomeInt(first_int.unwrap()))'
)

In contrast, the corresponding Racket program

#lang racket/base
(require syntax/parse)

(syntax-parse #'(1 2)
  [(first-int:integer
    (~and second-int:integer
          (~fail #:unless (eqv? (syntax-e #'first-int)
                                (syntax-e #'second-int)))))
   #t]
  [_ #f])

works just fine.

usaoc avatar Jan 31 '24 07:01 usaoc