Skip to content

Commit

Permalink
fix js Map iterator; tag 0.8.49
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Apr 6, 2024
1 parent c8ab377 commit 6abe008
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit"
version = "0.8.48"
version = "0.8.49"
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
edition = "2021"
license = "MIT"
Expand Down
11 changes: 10 additions & 1 deletion calcit/test.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
|test-refs $ %{} :CodeEntry (:doc |)
:code $ quote
fn () (log-title "|Testing refs") (assert= 0 @*ref-demo)
add-watch *ref-demo :change $ fn (prev current) (println "|change happened:" prev current)
add-watch *ref-demo :change $ fn (current prev) (println "|change happened:" prev current)
reset! *ref-demo 2
remove-watch *ref-demo :change
assert= 2 @*ref-demo
Expand All @@ -218,6 +218,15 @@
v $ %:: Deref :value 1
assert= 2 @v
assert= (nth v 1) 1

let
*b $ atom 0
*c $ atom 0
add-watch *b :change $ fn (current prev)
reset! *c current
reset! *b 1
assert= 1 @*b
assert= 1 @*c
|test-tag $ %{} :CodeEntry (:doc |)
:code $ quote
defn test-tag ()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@calcit/procs",
"version": "0.8.48",
"version": "0.8.49",
"main": "./lib/calcit.procs.mjs",
"devDependencies": {
"@types/node": "^20.11.28",
Expand Down
14 changes: 8 additions & 6 deletions ts-src/calcit-data.mts
Original file line number Diff line number Diff line change
Expand Up @@ -518,22 +518,24 @@ export let _$n__$e_ = (x: CalcitValue, y: CalcitValue): boolean => {
}

if (tx === "string") {
return (x as string) === (y as string);
// already checked above
return false;
}
if (tx === "boolean") {
return (x as boolean) === (y as boolean);
// already checked above
return false;
}
if (tx === "number") {
return x === y;
// already checked above
return false;
}
if (tx === "function") {
// comparing functions by reference
return x === y;
}
if (x instanceof CalcitTag) {
if (y instanceof CalcitTag) {
return x === y;
}
// comparing tags by reference
// already checked above
return false;
}
if (x instanceof CalcitSymbol) {
Expand Down
37 changes: 18 additions & 19 deletions ts-src/calcit.procs.mts
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,9 @@ export let reset_$x_ = (a: CalcitRef, v: CalcitValue): null => {
}
let prev = a.value;
a.value = v;
for (let k in a.listeners) {
let f = a.listeners.get(k);
a.listeners.forEach((f) => {
f(v, prev);
}
});
return null;
};

Expand Down Expand Up @@ -1328,23 +1327,32 @@ export function invoke_method_closure(p: string) {
function lookup_class(obj: CalcitValue): [CalcitRecord, string] {
let klass: CalcitRecord;
let tag: string;
if (obj == null) {
tag = "&core-nil-class";
klass = calcit_builtin_classes.nil;
} else if (obj instanceof CalcitTuple) {
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
tag = "&core-list-class";
klass = calcit_builtin_classes.list;
} else if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
tag = "&core-map-class";
klass = calcit_builtin_classes.map;
} else if (obj instanceof CalcitRecord) {
if (obj.klass instanceof CalcitRecord) {
tag = obj.tag.toString();
tag = obj.name.toString();
klass = obj.klass;
} else {
throw new Error("Method invoking expected a record as class");
}
} else if (obj instanceof CalcitRecord) {
} else if (obj instanceof CalcitTuple) {
if (obj.klass instanceof CalcitRecord) {
tag = obj.name.toString();
tag = obj.tag.toString();
klass = obj.klass;
} else {
throw new Error("Method invoking expected a record as class");
}
} else if (obj instanceof CalcitSet) {
tag = "&core-set-class";
klass = calcit_builtin_classes.set;
} else if (obj == null) {
tag = "&core-nil-class";
klass = calcit_builtin_classes.nil;
} else if (typeof obj === "number") {
tag = "&core-number-class";
klass = calcit_builtin_classes.number;
Expand All @@ -1354,15 +1362,6 @@ function lookup_class(obj: CalcitValue): [CalcitRecord, string] {
} else if (typeof obj === "function") {
tag = "&core-fn-class";
klass = calcit_builtin_classes.fn;
} else if (obj instanceof CalcitSet) {
tag = "&core-set-class";
klass = calcit_builtin_classes.set;
} else if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
tag = "&core-list-class";
klass = calcit_builtin_classes.list;
} else if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
tag = "&core-map-class";
klass = calcit_builtin_classes.map;
} else {
return null;
}
Expand Down

0 comments on commit 6abe008

Please sign in to comment.