Skip to content

Commit

Permalink
handle difference and identical? in specific ways; alpha release
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Apr 26, 2021
1 parent def2acf commit 23f7965
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 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_runner"
version = "0.3.0-a7"
version = "0.3.0-a8"
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
edition = "2018"
license = "MIT"
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.3.0-a7",
"version": "0.3.0-a8",
"main": "./lib/calcit.procs.js",
"devDependencies": {
"@types/node": "^14.14.41",
Expand Down
3 changes: 3 additions & 0 deletions src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn is_proc_name(s: &str) -> bool {
| "&<"
| "&>"
| "not"
| "identical?"
// math
| "&+"
| "&-"
Expand Down Expand Up @@ -166,6 +167,8 @@ pub fn handle_proc(name: &str, args: &CalcitItems) -> Result<Calcit, String> {
"&<" => logics::binary_less(args),
"&>" => logics::binary_greater(args),
"not" => logics::not(args),
// in Rust, no real pointer `identical?`, fallback to value equal
"identical?" => logics::binary_equal(args),
// math
"&+" => math::binary_add(args),
"&-" => math::binary_minus(args),
Expand Down
10 changes: 9 additions & 1 deletion src/builtins/sets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ pub fn call_exclude(xs: &CalcitItems) -> Result<Calcit, String> {
}
pub fn call_difference(xs: &CalcitItems) -> Result<Calcit, String> {
match (xs.get(0), xs.get(1)) {
(Some(Calcit::Set(a)), Some(Calcit::Set(b))) => Ok(Calcit::Set(a.clone().difference(b.clone()))),
(Some(Calcit::Set(a)), Some(Calcit::Set(b))) => {
// im::HashSet::difference has different semantics
// https://docs.rs/im/12.2.0/im/struct.HashSet.html#method.difference
let mut ys = a.to_owned();
for item in b {
ys.remove(item);
}
Ok(Calcit::Set(ys))
}
(Some(a), Some(b)) => Err(format!("&difference expected 2 sets: {} {}", a, b)),
(a, b) => Err(format!("&difference expected 2 arguments: {:?} {:?}", a, b)),
}
Expand Down
2 changes: 1 addition & 1 deletion src/primes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl PartialEq for Calcit {
pub const CORE_NS: &str = "calcit.core";
pub const GENERATED_NS: &str = "calcit.gen";

pub const CALCI_VERSION: &str = "0.3.0-a7";
pub const CALCI_VERSION: &str = "0.3.0-a8";

impl Calcit {
pub fn turn_string(&self) -> String {
Expand Down

0 comments on commit 23f7965

Please sign in to comment.