Skip to content

Commit

Permalink
add uninterned literals symbols #265
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 25, 2025
1 parent 7bc36ad commit 311b55d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 43 deletions.
26 changes: 15 additions & 11 deletions dist/lips.cjs

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

26 changes: 15 additions & 11 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.

26 changes: 15 additions & 11 deletions dist/lips.js

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

6 changes: 3 additions & 3 deletions dist/lips.min.js

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions lib/srfi/258.scm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@
Returns #t if symbol is an interned (ordinary) symbol, and #f
if it is uninterned."
(typecheck "symbol-interned?" symbol "symbol")
(let ((copy (new lips.LSymbol symbol.__name__)))
(eq? copy symbol)))
symbol.__interned__)

(define generate-uninterned-symbol gensym)
(define generate-uninterned-symbol
(let ((count 0))
(lambda args
(let ((prefix (if (null? args)
":"
(car args))))
(typecheck "generate-uninterned-symbol" prefix "string")
(let ((name (string-append prefix
(number->string count))))
(set! count (+ count 1))
(lips.LSymbol name #f))))))

(set-special! ":|" '%uninterned-symbol)

(define (%uninterned-symbol symbol)
`(quote ,(lips.LSymbol symbol.__name__ #f)))
8 changes: 6 additions & 2 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ function strip_s_comments(tokens) {
// ----------------------------------------------------------------------
// Detect if object is ES6 Symbol that work with polyfills
// ----------------------------------------------------------------------
function isSymbol(x) {
function is_symbol(x) {
return typeof x === 'symbol' ||
typeof x === 'object' &&
Object.prototype.toString.call(x) === '[object Symbol]';
Expand All @@ -759,6 +759,7 @@ function LSymbol(name, interned = true) {
typeof this === 'undefined') {
return new LSymbol(name, interned);
}
read_only(this, '__interned__', interned);
this.__name__ = name;
if (interned && typeof name === 'string') {
LSymbol.list[name] = this;
Expand All @@ -777,10 +778,13 @@ LSymbol.is = function(symbol, name) {
// ----------------------------------------------------------------------
LSymbol.prototype.toString = function(quote) {
//return '#<symbol \'' + this.name + '\'>';
if (isSymbol(this.__name__)) {
if (is_symbol(this.__name__)) {
return symbol_to_string(this.__name__);
}
var str = this.valueOf();
if (!this.__interned__) {
return `:|${str}|`;
}
// those special characters can be normal symbol when printed
if (quote && str.match(/(^;|[\s()[\]'])/)) {
return `|${str}|`;
Expand Down

0 comments on commit 311b55d

Please sign in to comment.