Skip to content

Commit

Permalink
add support for equal? on records #273
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 16, 2024
1 parent 8d59366 commit 64e6bf0
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* add support to ES Modules [#254](https://github.com/jcubic/lips/issues/254)
* add support for `(scheme-report-environment 7)`
* add a way to compare custom instances with `equal?` [#270](https://github.com/jcubic/lips/issues/270)
* add support for `equal?` on records [#273](https://github.com/jcubic/lips/issues/273)
### Bugfix
* remove evaluating of async list data as first argument
* fix `number->string` for binary numbers
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.17.3-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete)
[![Build and test](https://github.com/jcubic/lips/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/lips/actions/workflows/build.yaml)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&a3856ea567ed3ad8203dcd0e53c85edb)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&f9d187f3e5e7714da90a616b472c4d99)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips)
![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips)
Expand Down
10 changes: 5 additions & 5 deletions dist/lips.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.esm.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/lips.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/std.min.scm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions dist/std.scm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/std.xcb
Binary file not shown.
11 changes: 11 additions & 0 deletions lib/R7RS.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,17 @@
name)))
`(set! ,(string->symbol prop) ,field)))
(cdr constructor))))
(equal (lambda (self other)
(if (instanceof ,name other)
(and ,@(map (lambda (field)
(let* ((name (symbol->string field))
(self-prop (string-append "self."
name))
(other-prop (string-append "other."
name)))
`(equal? ,(string->symbol self-prop)
,(string->symbol other-prop))))))
#f)))
(typeOf (lambda (self)
"record"))
(toString (lambda (self)
Expand Down
10 changes: 10 additions & 0 deletions tests/std.scm
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,13 @@
(y kdr set-kdr!))

(t.is (type (kons 1 2)) "record")))

(test "std: equal? on records"
(lambda (t)
(define-record-type <pare>
(kons x y)
pare?
(x kar set-kar!)
(y kdr set-kdr!))

(t.is (kons 1 2) (kons 1 2))))

0 comments on commit 64e6bf0

Please sign in to comment.