Skip to content

Commit

Permalink
Merge pull request #45 from calcit-lang/tuple-polymorphism
Browse files Browse the repository at this point in the history
add tuple; add native method syntax
  • Loading branch information
soyaine authored May 31, 2021
2 parents 817c40d + 1607b72 commit 88950f4
Show file tree
Hide file tree
Showing 31 changed files with 722 additions and 42 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ js-out/
node_modules/

lib/*.js
builds/
builds/


.compact-inc.cirru
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.20"
version = "0.3.23"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
24 changes: 24 additions & 0 deletions calcit/calcit.cirru

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

7 changes: 5 additions & 2 deletions calcit/compact.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
|call-3 $ quote
defn call-3 (a b c) (echo "\"a is:" a) (echo "\"b is:" b) (echo "\"c is:" c)
|main! $ quote
defn main! () (demos) (fib 10)
defn main! () (demos) (; fib 10) (try-method)
|demos $ quote
defn demos () (echo "\"demo")
echo $ &+ 2 2
Expand Down Expand Up @@ -57,6 +57,9 @@
test-args
|call-many $ quote
defn call-many (x0 & xs) (echo "\"many...") (echo "\"x0" x0) (echo "\"xs" xs)
|try-method $ quote
defn try-method () $ println
.count $ range 11
|rec-sum $ quote
defn rec-sum (acc xs)
if (empty? xs) acc $ recur
Expand All @@ -77,7 +80,7 @@
|f1 $ quote
defn f1 () $ echo "\"calling f1"
|reload! $ quote
defn reload! () (println "\"reloaded 2") (fib 40)
defn reload! () (println "\"reloaded 2") (; fib 40) (try-method)
|add-more $ quote
defmacro add-more (acc x times)
if (&< times 1) acc $ recur
Expand Down
1 change: 1 addition & 0 deletions calcit/snapshots/test-js.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
js/console.log "|is a Number"

.log js/console |demo
js/console.log "|Dates in difference syntax" (.!now js/Date) (.now js/Date)
js/console.log $ .-PI js/Math

js/console.log $ aget js/Math |PI
Expand Down
34 changes: 34 additions & 0 deletions calcit/snapshots/test-list.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,38 @@
log-title "|Testing alias"
assert= (' 1 2 3) ([] 1 2 3)

|test-methods $ quote
fn ()
log-title "|Testing list methods"
assert= 3
.count $ [] 1 2 3
assert=
[] 4 5 6
.map ([] 1 2 3) $ fn (x) (+ x 3)
assert=
[] 2 3 4
.map ([] 1 2 3) .inc

assert=
[] 4 3 2 1
.sort-by ([] 1 2 3 4) negate

assert=
[] 1 2 3 4
.sort-by ([] 1 2 3 4) inc

assert=
[]
{} (:v :a) (:n 1)
{} (:v :c) (:n 2)
{} (:v :b) (:n 3)
.sort-by
[]
{} (:v :a) (:n 1)
{} (:v :b) (:n 3)
{} (:v :c) (:n 2)
, :n

|main! $ quote
defn main! ()

Expand Down Expand Up @@ -326,6 +358,8 @@
test-doseq
test-let[]

test-methods

do true

:proc $ quote ()
Expand Down
24 changes: 24 additions & 0 deletions calcit/snapshots/test-map.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,29 @@
unselect-keys ({} (:a 1) (:b 2) (:c 3)) ([] :c :d)
{} (:a 1) (:b 2)

|test-methods $ quote
fn ()
log-title "|Testing map methods"

assert= 2
.count $ {} (:a 1) (:b 2)
assert=
{} (:a 11)
.map-kv ({} (:a 1)) $ fn (k v)
[] k (+ v 10)

assert=
[] ([] :a 1)
.to-list $ {} (:a 1)

assert= 2
.count $ .to-list $ {}
:a 1
:b 2


|main! $ quote

defn main! ()

log-title "|Testing maps"
Expand All @@ -193,6 +215,8 @@

test-select

test-methods

do true

:proc $ quote ()
Expand Down
9 changes: 9 additions & 0 deletions calcit/snapshots/test-math.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
assert= true (integer? 1)
assert= false (integer? 1.1)

|test-methods $ quote
fn ()
log-title "|Testing number methods"

assert= 1 $ .floor 1.1
assert= 16 $ .pow 2 4

|main! $ quote
defn main! ()
log-title "|Testing numbers"
Expand All @@ -89,6 +96,8 @@

test-integer

test-methods

do true

:proc $ quote ()
Expand Down
9 changes: 9 additions & 0 deletions calcit/snapshots/test-record.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,19 @@
|Cat $ quote
defrecord Cat :name :color

|test-methods $ quote
fn ()
log-title "|Testing record methods"

assert= |Cat
.get-name Cat

|main! $ quote
defn main! ()
test-record

test-methods

do true

:proc $ quote ()
Expand Down
7 changes: 7 additions & 0 deletions calcit/snapshots/test-set.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@
assert= (#{} 1 2 3) (#{} 1 2 (+ 1 2))
assert-detect not $ = (#{} 1 2 3) (#{} 2 3 4)

|test-methods $ quote
fn ()
assert= 3
.count $ #{} 1 2 3

|main! $ quote
defn main! ()
log-title "|Testing set"
test-set

test-methods

do true

:proc $ quote ()
Expand Down
11 changes: 11 additions & 0 deletions calcit/snapshots/test-string.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@
format-to-lisp $ quote $ nil? nil
, "|(nil? nil)"

|test-methods $ quote
defn test-methods ()
log-title "|Testing string methods"

assert= 3 (.count |abc)
assert=
[] |a |c
.split |abc |b

|main! $ quote
defn main! ()
log-title "|Testing str"
Expand All @@ -214,6 +223,8 @@

test-lisp-style

test-methods

do true

:proc $ quote ()
Expand Down
35 changes: 26 additions & 9 deletions calcit/snapshots/test.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
assert-detect not $ > :a :b
assert-detect not $ > :aa :ab

inside-eval:
assert= ([] 1)
.map
[] $ &{} :a 1
, :a

|test-id $ quote
fn ()
assert= 9 $ count $ generate-id! 9
Expand Down Expand Up @@ -227,20 +233,29 @@
defrecord %Num :inc :show
|Num $ quote
def Num $ %{} %Num
:inc $ fn (x) $ [] Num (&+ x 1)
:inc $ fn (x) $ :: Num (&+ x 1)
:show $ fn (x) $ str x

|test-invoke $ quote
|test-method $ quote
fn ()
log-title "|Testing invoke"
log-title "|Testing method"

let
a $ [] Num 0
a $ :: Num 0
assert=
[] Num 2
-> a (invoke :inc) (invoke :inc)
:: Num 2
-> a .inc .inc
assert= |1
-> a (invoke :inc) (invoke :show)
-> a .inc .show

|test-tuple $ quote
fn ()
log-title "|Testing tuple"

assert= :tuple (type-of (:: :a :b))
assert= :a (nth (:: :a :b) 0)
assert= :b (nth (:: :a :b) 1)
assert= 2 (count (:: :a :b))

|reload! $ quote
defn reload! () nil
Expand Down Expand Up @@ -276,8 +291,10 @@
test-fn-eq

test-refs

test-invoke

test-method

test-tuple

inside-eval:
test-gynienic/main!
Expand Down
Loading

0 comments on commit 88950f4

Please sign in to comment.