Skip to content

Commit

Permalink
moved operations for complex numbers; tag 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed May 1, 2022
1 parent 39be208 commit ae2745c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ jobs:
&& git clone https://github.com/calcit-lang/calcit-test.git
- name: "test"
run: cr -1 --entry test
run: cr -1

- run: cr --emit-js -1 --entry test && yarn && node ./main.mjs
- run: cr --emit-js -1 && yarn && node ./main.mjs
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@

Calcit Workflow
Arithmetic
----

> running in both Calcit and Calcit-js, with hot code reload.
> for complex numbers
### Usages

Install [Calcit](https://github.com/calcit-lang/calcit) to run demo:
```cirru
ns demo :require
arithmetic.complex :as complex
```bash
cr -1 # run once

cr # run and watch
complex/&+ ([] 1 2) ([] 3 4)
```

run tests:

```bash
cr -1 --entry test
```
Functions:

run test in JavaScript:

```bash
cr --emit-js -1 --entry test # emit-js once
node main.mjs # run code
```
- `&+ a b`
- `&- a b`
- `&* a b`
- `&/ a b`
- `conjugate a`
- `scale a x-scalar`
- `divide-by a x-scalar`, scales down by factor
- `polar-point radian radius`, create a point from radian

### Workflow

Expand Down
96 changes: 68 additions & 28 deletions compact.cirru
Original file line number Diff line number Diff line change
@@ -1,37 +1,77 @@

{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version |0.0.1)
:modules $ [] |calcit-test/ |calcit.std/
{} (:package |arithmetic)
:configs $ {} (:init-fn |arithmetic.test/main!) (:reload-fn |arithmetic.test/reload!) (:version |0.0.1)
:modules $ [] |calcit-test/
:entries $ {}
:test $ {} (:init-fn |app.test/main!) (:reload-fn |app.test/reload!)
:modules $ [] |calcit-test/
:files $ {}
|app.main $ {}
:defs $ {}
|calling-func $ quote
defn calling-func () $ println "\"todo bcc"
|main! $ quote
defn main! () (run-tests)
set-interval 2000 $ fn () (calling-func)
|on-error $ quote
defn on-error (message) (; draw-error-message message)
|reload! $ quote
defn reload! () $ echo "\"Reloaded."
|arithmetic.test $ {}
:ns $ quote
ns app.main $ :require
app.test :refer $ run-tests
calcit.std.time :refer $ set-interval
|app.test $ {}
ns arithmetic.test $ :require
calcit-test.core :refer $ deftest testing is *quit-on-failure?
arithmetic.complex :as complex
:defs $ {}
|main! $ quote
defn main! () $ run-tests
|reload! $ quote
defn reload! () $ println "\"TODO reload"
defn reload! () (run-tests) (println "\"reloaded.")
|run-tests $ quote
defn run-tests () (reset! *quit-on-failure? true) (test-add)
|test-add $ quote
deftest test-add $ testing |add
is $ = 2 (+ 1 1)
:ns $ quote
ns app.test $ :require
calcit-test.core :refer $ deftest testing is *quit-on-failure?
defn run-tests () (reset! *quit-on-failure? true) (test-basic)
|test-basic $ quote
deftest test-basic
testing |add $ is
= ([] 3 5)
complex/&+ ([] 1 2) ([] 2 3)
testing |minus $ is
= ([] -1 -1)
complex/&- ([] 1 2) ([] 2 3)
|arithmetic.complex $ {}
:ns $ quote (ns phlox.complex)
:defs $ {}
|&* $ quote
defn &* (v1 v2)
let-sugar
[] a b
, v1
([] x y) v2
[]
- (* a x) (* b y)
+ (* a y) (* b x)
|&+ $ quote
defn &+ (p1 p2)
let-sugar
[] a b
, p1
([] x y) p2
[] (+ a x) (+ b y)
|&- $ quote
defn &- (v1 v2)
let-sugar
[] a b
, v1
([] x y) v2
[] (- a x) (- b y)
|&/ $ quote
defn rebase (value base) "\"complex number division, renamed since naming collision" $ let-sugar
[] x y
, value
([] a b) base
inverted $ / 1
+ (* a a) (* b b)
[]
* inverted $ + (* x a) (* y b)
* inverted $ - (* y a) (* x b)
|conjugate $ quote
defn conjugate (pair) (update pair 1 negate)
|divide-by $ quote
defn divide-by (point x)
[]
/ (first point) x
/ (last point) x
|polar-point $ quote
defn polar-point (angle r)
[]
* r $ js/Math.cos angle
* r $ js/Math.sin angle
|scale $ quote
defn scale (pair v)
map pair $ fn (x) (* v x)
2 changes: 1 addition & 1 deletion main.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { main_$x_, reload_$x_ } from "./js-out/app.test.mjs"
import { main_$x_, reload_$x_ } from "./js-out/arithmetic.test.mjs"

main_$x_()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.7",
"version": "0.0.1",
"dependencies": {
"@calcit/procs": "^0.5.41"
},
Expand Down

0 comments on commit ae2745c

Please sign in to comment.