Skip to content

Commit

Permalink
cj-env-2: pmatch: use equal not eq, treat self-quoting values as quoted
Browse files Browse the repository at this point in the history
  • Loading branch information
pflanze committed Aug 12, 2020
1 parent b74f91a commit b324db2
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cj-env-2.scm
Expand Up @@ -177,11 +177,15 @@
(set! have-else? #t)
`(else ,@rest))
(`(`pexpr . `rest)
(mcase pexpr
(`(quote `val)
`((eq? ,V ',val) ,@rest))
(else
`((,pexpr ,V) ,@rest)))))
`(,(mcase pexpr
(self-quoting?
`(equal? ,V ,pexpr))
(`(quote `val)
`(equal? ,V ',val))
(else
;; predicate
`(,pexpr ,V)))
,@rest)))
cases)))
`(let ((,V ,expr))
(cond ,@cases*
Expand All @@ -191,11 +195,17 @@
(TEST
> (define (t v)
(pmatch v
(123.4 'is-123_4)
(number? 'num)
('foo 'is-foo)
("bar" 'is-bar)
(string? 'str)))
> (t "foo")
str
> (t "bar")
is-bar
> (t 123.4)
is-123_4
> (t 'foo)
is-foo
> (t 123)
Expand Down

0 comments on commit b324db2

Please sign in to comment.