Skip to content

Commit a35dca6

Browse files
committed
fix eqv? on same pairs
1 parent c43bee9 commit a35dca6

File tree

5 files changed

+7
-4
lines changed

5 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* lists are now iterators
66
* add optional `=>` syntax to `cond` macro (as per R7RS)
77
* make `undefined` parser constant
8-
* add support for `log` of complex, rational, and negative numbers
8+
* add support for `log` ofcomplex, rational, and negative numbers
9+
* allow to define shorthand object literals [#185](https://github.com/jcubic/lips/issues/185)
910
### Bugfix
1011
* fix scoping issue in nested `syntax-rules`
1112
* fix `repr` of object that have space in key
@@ -25,6 +26,8 @@
2526
* fix `length` of nil
2627
* fix trimming spaces in `Env::set`
2728
* fix `repr` of symbols with impossible characters created with `string->symbol`
29+
* fix `eqv?` on same pairs
30+
* fix `abs` on inexact numbers that can be represented as integers [#181](https://github.com/jcubic/lips/issues/181)
2831

2932
## 1.0.0-beta.14
3033
### Breaking

dist/std.min.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
(define-macro (vector-literal . args) (if (not (or (pair? args) (eq? args ()))) (throw (new Error (concat "Parse Error: vector require pair got " (type args) " in " (repr args)))) (let ((v (list->array args))) (Object.freeze v) v)))
126126
(define-syntax vector (syntax-rules () ((_ arg ...) (list->array (list arg ...)))) "(vector 1 2 3 (+ 3 1))\u000A#(1 2 3 4)\u000A\u000AMacro for defining vectors (JavaScript arrays). Vectors literals are\u000Aautomatically quoted. So you can use expressions inside them. Only other\u000Aliterals, like other vectors or object.")
127127
(set-repr! Array (lambda (arr q) (let ((result (--> (Array.from arr) (map (lambda (x i) (if (not (in i arr)) "#<empty>" (repr (. arr i) q))))))) (concat "#(" (--> result (join " ")) ")"))))
128-
(define (eqv? a b) "(eqv? a b)\u000A\u000AFunction compare the values. It return true if they are the same, they\u000Aneed to have same type" (if (string=? (type a) (type b)) (cond ((number? a) (or (and (exact? a) (exact? b) (= a b)) (and (inexact? a) (inexact? b) (cond ((a.isNaN) (b.isNaN)) ((and (zero? a) (zero? b)) (eq? a._minus b._minus)) ((and (complex? a) (complex? b)) (let ((re.a (real-part a)) (re.b (real-part b)) (im.a (imag-part a)) (im.b (imag-part b))) (and (if (and (zero? re.a) (zero? re.b)) (eq? (. re.a (quote _minus)) (. re.b (quote _minus))) #t) (if (and (zero? im.a) (zero? im.b)) (eq? (. im.a (quote _minus)) (. im.b (quote _minus))) #t) (or (= re.a re.b) (and (--> re.a (isNaN)) (--> re.b (isNaN)))) (or (= im.a im.b) (and (--> im.a (isNaN)) (--> im.b (isNaN))))))) (else (= a b)))))) ((pair? a) (and (null? a) (null? b))) (else (eq? a b))) #f))
128+
(define (eqv? a b) "(eqv? a b)\u000A\u000AFunction compare the values. It return true if they are the same, they\u000Aneed to have same type" (if (string=? (type a) (type b)) (cond ((number? a) (or (and (exact? a) (exact? b) (= a b)) (and (inexact? a) (inexact? b) (cond ((a.isNaN) (b.isNaN)) ((and (zero? a) (zero? b)) (eq? a._minus b._minus)) ((and (complex? a) (complex? b)) (let ((re.a (real-part a)) (re.b (real-part b)) (im.a (imag-part a)) (im.b (imag-part b))) (and (if (and (zero? re.a) (zero? re.b)) (eq? (. re.a (quote _minus)) (. re.b (quote _minus))) #t) (if (and (zero? im.a) (zero? im.b)) (eq? (. im.a (quote _minus)) (. im.b (quote _minus))) #t) (or (= re.a re.b) (and (--> re.a (isNaN)) (--> re.b (isNaN)))) (or (= im.a im.b) (and (--> im.a (isNaN)) (--> im.b (isNaN))))))) (else (= a b)))))) ((and (pair? a) (null? a)) (null? b)) (else (eq? a b))) #f))
129129
(define (equal? a b) "(equal? a b)\u000A\u000AFunction check if values are equal if both are pair or array\u000Ait compares the their elements recursivly." (cond ((and (pair? a)) (and (pair? b) (equal? (car a) (car b)) (equal? (cdr a) (cdr b)))) ((symbol? a) (and (symbol? b) (equal? a.__name__ b.__name__))) ((regex? a) (and (regex? b) (equal? (. a (quote source)) (. b (quote source))))) ((typed-array? a) (and (typed-array? b) (equal? (Array.from a) (Array.from b)))) ((vector? a) (and (vector? b) (= (length a) (length b)) (--> a (every (lambda (item i) (equal? item (vector-ref b i))))))) ((string? a) (and (string? b) (string=? a b))) ((function? a) (and (function? b) (%same-functions a b))) ((array? a) (and (array? b) (eq? (length a) (length b)) (= (--> a (filter (lambda (item i) (equal? item (. b i)))) (quote length)) (length a)))) ((plain-object? a) (and (plain-object? b) (let ((keys_a (--> (Object.keys a) (sort))) (keys_b (--> (Object.keys b) (sort)))) (and (= (length keys_a) (length keys_b)) (equal? keys_a keys_b) (equal? (--> keys_a (map (lambda (key) (. a key)))) (--> keys_b (map (lambda (key) (. b key))))))))) (else (eqv? a b))))
130130
(define make-promise (lambda (proc) "(make-promise fn)\u000A\u000AFunction create promise from a function." (typecheck "make-promise" proc "function") (let ((result-ready? #f) (result #f)) (let ((promise (lambda () (if result-ready? result (let ((x (proc))) (if result-ready? result (begin (set! result-ready? #t) (set! result x) result))))))) (set-obj! promise (Symbol.for "promise") #t) (set! promise.toString (lambda () (string-append "#<promise - " (if result-ready? (string-append "forced with " (type result)) "not forced") ">"))) promise))))
131131
(define-macro (delay expression) "(delay expression)\u000A\u000AMacro will create a promise from expression that can be forced with (force)." (quasiquote (make-promise (lambda () (unquote expression)))))

dist/std.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@
15511551
(and (--> im.a (isNaN))
15521552
(--> im.b (isNaN)))))))
15531553
(else (= a b))))))
1554-
((pair? a) (and (null? a) (null? b)))
1554+
((and (pair? a) (null? a)) (null? b))
15551555
(else (eq? a b)))
15561556
false))
15571557

dist/std.xcb

0 Bytes
Binary file not shown.

lib/R5RS.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
(and (--> im.a (isNaN))
120120
(--> im.b (isNaN)))))))
121121
(else (= a b))))))
122-
((pair? a) (and (null? a) (null? b)))
122+
((and (pair? a) (null? a)) (null? b))
123123
(else (eq? a b)))
124124
false))
125125

0 commit comments

Comments
 (0)