Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine macro code for cond and let[] #106

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.5.0-a8"
version = "0.5.0-a9"
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
edition = "2018"
license = "MIT"
Expand Down
26 changes: 26 additions & 0 deletions calcit/snapshots/test-macro.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,32 @@
quote $ let{} (a b) ({,} :a 3 :b 4)
+ a b

&reset-gensym-index!

assert=
macroexpand-all $ quote
let[] (a b) ([] 1 2)
+ a b
quasiquote $ ~&let (v__1 (~[] 1 2))
~&let (a (~&list:nth v__1 0))
~&let (b (~&list:nth v__1 1))
+ a b

assert=
macroexpand-all $ quote
let[] (a b) xs
+ a b
quasiquote $ ~&let (a (~&list:nth xs 0))
~&let (b (~&list:nth xs 1))
+ a b

assert=
macroexpand-all $ quote
cond
(= a 1) |one
true |other
quasiquote $ ~if (= a 1) |one |other

assert=
[] 3 4 5 6
let-sugar
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.5.0-a8",
"version": "0.5.0-a9",
"main": "./lib/calcit.procs.js",
"devDependencies": {
"@types/node": "^16.10.5",
Expand Down
32 changes: 21 additions & 11 deletions src/cirru/calcit-core.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,16 @@
expr $ &list:nth pair 0
&let
branch $ &list:nth pair 1
quasiquote
if ~expr ~branch
~ $ if (&list:empty? else) nil
quasiquote
cond
~ $ &list:nth else 0
~@ $ &list:rest else
if
if (empty? else) (= true expr) false
, branch
quasiquote
if ~expr ~branch
~ $ if (&list:empty? else) nil
quasiquote
cond
~ $ &list:nth else 0
~@ $ &list:rest else

|key-match $ quote
defmacro key-match (value & body)
Expand Down Expand Up @@ -1155,7 +1158,8 @@
every? vars symbol?
, false
let
v $ gensym |v
variable? $ symbol? data
v $ if variable? data $ gensym |v
defs $ apply-args
[] ([]) vars 0
defn let[]% (acc xs idx)
Expand All @@ -1172,12 +1176,18 @@
append acc $ [] (&list:first xs) (quasiquote (&list:nth ~v ~idx))
rest xs
inc idx
quasiquote
&let
~v ~data

if variable?
quasiquote
let
~ defs
~@ body
quasiquote
&let
~v ~data
let
~ defs
~@ body

|defrecord $ quote
defmacro defrecord (name & xs)
Expand Down
2 changes: 1 addition & 1 deletion ts-src/calcit.procs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// CALCIT VERSION
export const calcit_version = "0.5.0-a8";
export const calcit_version = "0.5.0-a9";

import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
import { parse, ICirruNode } from "@cirru/parser.ts";
Expand Down