Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
distinguish strings created from symbol->string
Browse files Browse the repository at this point in the history
  • Loading branch information
jitwit committed Nov 20, 2019
1 parent 7e5adbe commit 2180857
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions rt/rt.mjs
Expand Up @@ -126,7 +126,8 @@ function rt(engine) {
// that's not specified on the Scheme language level. Using JS
// strings for symbols allows us to compare with ===, as is
// required.
'string?': x => x instanceof String && x.charAt(0) === 's',
'string?': x => (typeof x === 'string' || x instanceof String)
&& x.charAt(0) === 's',
'%symbol?': x => typeof(x) === 'string' && x.charAt(0) === 'S',
'%string=?' : (x, y) => x.valueOf() === y.valueOf(),

Expand All @@ -145,7 +146,7 @@ function rt(engine) {
},

'%string->symbol': value => 'S' + value,
'%symbol->string': x => new String (x.substring(1)),
'%symbol->string': x => x.substring(1),

// Gensyms are instances of String (objects with identity).
'%make-gensym': str => new String('S' + str),
Expand Down
6 changes: 4 additions & 2 deletions test/string-eq.ss
Expand Up @@ -18,6 +18,8 @@
(import (rnrs))

(define (do-test)
(let ((x (list->string '(#\a #\b #\c))))
(let* ((x (list->string '(#\a #\b #\c)))
(y (string->symbol x)))
(and (not (eq? x (list->string '(#\a #\b #\c))))
(eq? x x)))))
(eq? x x)
(eq? (symbol->string y) (symbol->string y))))))

0 comments on commit 2180857

Please sign in to comment.