Skip to content

Commit db06c19

Browse files
authored
Merge pull request #22 from calcit-lang/snippets
provide several snippets
2 parents d678d26 + 59a778e commit db06c19

File tree

10 files changed

+622
-288
lines changed

10 files changed

+622
-288
lines changed

.github/workflows/upload.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ jobs:
1919

2020
- uses: supplypike/setup-bin@v3
2121
with:
22-
uri: 'https://github.com/calcit-lang/calcit/releases/download/0.8.2/cr'
22+
uri: 'https://github.com/calcit-lang/calcit/releases/download/0.8.13/cr'
2323
name: 'cr'
24-
version: '0.8.2'
24+
version: '0.8.13'
2525

2626
- uses: supplypike/setup-bin@v3
2727
with:
28-
uri: 'https://github.com/calcit-lang/calcit/releases/download/0.8.2/caps'
28+
uri: 'https://github.com/calcit-lang/calcit/releases/download/0.8.13/caps'
2929
name: 'caps'
30-
version: '0.8.2'
30+
version: '0.8.13'
3131
- name: "compiles to js"
3232
run: >
3333
caps --ci && cr --emit-js --once

calcit.cirru

Lines changed: 305 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compact.cirru

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
a $ {} (:inner-text title) (:class-name css/link) (:href url) (:target "\"_blank")
1313
|comp-bg $ %{} :CodeEntry (:doc |)
1414
:code $ quote
15-
defcomp comp-bg () (println "\"@@@@@@@@@@@@@@@@\n@\n@ Well, code is not minified on purpose~\n@\n@ although it's still bundled with Vite.\n@\n@@@@@@@@@@@@@@@@")
15+
defcomp comp-bg ()
1616
; img $ {} (:src "\"http://cdn.tiye.me/logo/calcit.png")
1717
:style $ {} (:width "\"60vw") (:z-index -10) (:min-width "\"480px") (:position :fixed) (:opacity 0.12) (:right 0) (:top "\"10vh")
1818
div $ {}
@@ -55,7 +55,8 @@
5555
<> "\"an interpreter for calcit snapshot, and hot code swapping friendly."
5656
=< nil 8
5757
=< nil 24
58-
comp-snippet-demo
58+
comp-snippet-demo $ >> states :snippets
59+
=< nil 8
5960
comp-promotions
6061
list->
6162
{} $ :class-name style-cards-containers
@@ -120,23 +121,38 @@
120121
:style $ {} (:flex-wrap :wrap)
121122
div
122123
{} $ :class-name css/row-middle
123-
button $ {} (:inner-text "\"Play snippets")
124-
:class-name $ str-spaced css/button style-promo-button style-main-button
125-
:on-click $ fn (e d!) (js/window.open "\"http://repo.calcit-lang.org/calcit-wasm-play/" "\"_blank")
126-
=< 8 nil
124+
add-link "\"GitHub" "\"https://github.com/calcit-lang/calcit/"
125+
div
126+
{} (:class-name css/row-middle)
127+
:style $ {} (:gap "\"8px")
128+
add-link "\"Browse APIs" "\"http://apis.calcit-lang.org"
127129
button $ {} (:inner-text "\"Guidebook")
128130
:class-name $ str-spaced css/button style-promo-button
129131
:on-click $ fn (e d!) (js/window.open "\"http://repo.calcit-lang.org/guidebook/" "\"_blank")
130-
=< 8 nil
131-
add-link "\"Browse APIs" "\"http://apis.calcit-lang.org"
132-
div
133-
{} $ :class-name css/row-middle
134-
add-link "\"GitHub" "\"https://github.com/calcit-lang/calcit/"
132+
button $ {} (:inner-text "\"Play snippets")
133+
:class-name $ str-spaced css/button style-promo-button style-main-button
134+
:on-click $ fn (e d!) (js/window.open "\"http://repo.calcit-lang.org/calcit-wasm-play/" "\"_blank")
135135
|comp-snippet-demo $ %{} :CodeEntry (:doc |)
136136
:code $ quote
137-
defcomp comp-snippet-demo () $ div ({})
138-
pre $ {} (:class-name style-snippet)
139-
:innerHTML $ cirru-color/generateHtml "\"defcomp comp-link (link)\n tag-match link $ \n :link title sub-title url\n div ({})\n a $ {} (:href url)\n :inner-text title\n :target \"\\\"_blank\"\n :class-name style-display-link\n =< 8 nil\n <> sub-title $ str-spaced css/font-fancy style-sub-title\n"
137+
defcomp comp-snippet-demo (states)
138+
let
139+
cursor $ :cursor states
140+
state $ either (:data states) :tag-match
141+
div
142+
{} (:class-name css/row)
143+
:style $ {} (:flex-wrap :wrap)
144+
comp-tabs
145+
{} (:selected state) (:vertical? true)
146+
:style $ {} (:margin-top 20) (:padding "\"0 8px") (:min-width 160)
147+
[] (&{} :name :tag-match :title "|Pattern matching") (&{} :name :component :title |Component) (&{} :name :persistent-data :title "|Persistent data") (&{} :name :pipeline :title "|Pipeline macro")
148+
fn (info d!)
149+
d! cursor $ :name info
150+
pre $ {}
151+
:class-name $ str-spaced css/expand style-snippet
152+
:style $ {} (:min-width 300)
153+
:innerHTML $ cirru-color/generateHtml
154+
trim $ pick-demo state
155+
, "\"defcomp comp-link (link)\n tag-match link $ \n :link title sub-title url\n div ({})\n a $ {} (:href url)\n :inner-text title\n :target \"\\\"_blank\"\n :class-name style-display-link\n =< 8 nil\n <> sub-title $ str-spaced css/font-fancy style-sub-title\n"
140156
|comp-visual $ %{} :CodeEntry (:doc |)
141157
:code $ quote
142158
defcomp comp-visual () $ div ({})
@@ -145,9 +161,25 @@
145161
{} $ :style
146162
{} $ :display :flex
147163
img $ {} (:class-name style-editor-img) (:src "\"https://cos-sh.tiye.me/cos-up/00c992c3061ed59d8c7d533b7a31433b-calcit-editor.png")
164+
|demo-component $ %{} :CodeEntry (:doc |)
165+
:code $ quote
166+
def demo-component $ inline-content! "\"content/demo/comp.cirru"
167+
|demo-persistent-data $ %{} :CodeEntry (:doc |)
168+
:code $ quote
169+
def demo-persistent-data $ inline-content! "\"content/demo/persistent-data.cirru"
170+
|demo-pipeline $ %{} :CodeEntry (:doc |)
171+
:code $ quote
172+
def demo-pipeline $ inline-content! "\"content/demo/pipeline.cirru"
173+
|demo-tag-match $ %{} :CodeEntry (:doc |)
174+
:code $ quote
175+
def demo-tag-match $ inline-content! "\"content/demo/tag-match.cirru"
148176
|inline-content! $ %{} :CodeEntry (:doc |)
149177
:code $ quote
150178
defmacro inline-content! (path) (read-file path)
179+
|pick-demo $ %{} :CodeEntry (:doc |)
180+
:code $ quote
181+
defn pick-demo (k)
182+
case-default k demo-tag-match (:tag-match demo-tag-match) (:pipeline demo-pipeline) (:component demo-component) (:persistent-data demo-persistent-data)
151183
|style-bg $ %{} :CodeEntry (:doc |)
152184
:code $ quote
153185
defstyle style-bg $ {}
@@ -220,7 +252,6 @@
220252
:background-color $ hsl 0 0 100
221253
:border $ str "\"1px solid " (hsl 0 0 90)
222254
:line-height "\"24px"
223-
:max-width "\"calc(100vw - 64px)"
224255
:overflow :auto
225256
|style-sub-title $ %{} :CodeEntry (:doc |)
226257
:code $ quote
@@ -240,6 +271,7 @@
240271
respo.css :refer $ defstyle
241272
respo-ui.css :as css
242273
app.schema :refer $ doc-features doc-columns
274+
respo-ui.comp :refer $ comp-tabs
243275
|app.config $ %{} :FileEntry
244276
:defs $ {}
245277
|cdn? $ %{} :CodeEntry (:doc |)
@@ -282,9 +314,10 @@
282314
when (some? raw)
283315
dispatch! :hydrate-storage $ extract-cirru-edn (js/JSON.parse raw)
284316
println "|App started."
317+
println "\"@@@@@@@@@@@@@@@@\n@\n@ Well, code is not minified on purpose~\n@\n@ although it's still bundled with Vite.\n@\n@@@@@@@@@@@@@@@@"
285318
|mount-target $ %{} :CodeEntry (:doc |)
286319
:code $ quote
287-
def mount-target $ .querySelector js/document |.app
320+
def mount-target $ js/document.querySelector |.app
288321
|persist-storage! $ %{} :CodeEntry (:doc |)
289322
:code $ quote
290323
defn persist-storage! () $ .setItem js/localStorage (:storage-key config/site)
@@ -332,7 +365,7 @@
332365
:: :column "\"Frameworks" $ [] (:: :link |Respo "|virtual DOM library" |https://github.com/Respo/respo.calcit) (:: :link |Phlox "|virtual DOM like wrapper on top of PIXI" |https://github.com/Quamolit/phlox.calcit) (:: :link "\"Lagopus" "\"thin WebGPU abstraction" "\"https://github.com/Triadica/lagopus") (:: :link |Quamolit "|what if we make animations in React's way?" |https://github.com/Quamolit/quamolit.calcit) (:: :link |Quaterfoil "|thin virtual DOM wrapper over three.js" |https://github.com/Quamolit/quatrefoil.calcit) (:: :link |Cumulo "|template for tiny realtime apps" |https://github.com/Cumulo/cumulo-workflow.calcit)
333366
:: :column "\"Tools" $ [] (:: :link "|Calcit IR viewer" nil |https://github.com/calcit-lang/calcit-ir-viewer) (:: :link "|Calcit Error viewer" nil |https://github.com/calcit-lang/calcit-error-viewer) (:: :link "\"Calcit binding for clipboard" nil "\"https://github.com/calcit-lang/calcit-clipboard") (:: :link "\"Calcit JSON" "\"JSON binding" "\"https://github.com/calcit-lang/calcit-json")
334367
:: :column "\"Videos" $ [] (:: :link "\"Calcit 开发记录: list-match 语法" nil "\"https://www.bilibili.com/video/BV1Su4y1X7kg/") (:: :link "\"Calcit 0.7 变更记录, Tag, Tuple 和多态" nil "\"https://www.bilibili.com/video/BV11L411v7Vk/") (:: :link "\"Calcit 更新: caps 命令下载依赖" nil "\"https://www.bilibili.com/video/BV11A41127UW/") (:: :link "\"Calcit 开发记录: bundle_calcit 增加热替换支持" nil "\"https://www.bilibili.com/video/BV1WU4y1S7KK/") (:: :link "|Calcit-js 开发的阶段介绍 2021-11" nil |https://www.bilibili.com/video/BV1Yg411K73P) (:: :link "|calcit-js 开发记录(21-01-22) 关于 ternary-tree.ts 重构" nil |https://www.bilibili.com/video/BV1Ht4y167Fg) (:: :link "|calcit-js 阶段介绍(2021-01)" nil |https://www.bilibili.com/video/BV1H5411n7su) (:: :link "|calcit-runner 阶段记录介绍(2021-01)" nil |https://www.bilibili.com/video/BV1cK4y1W7dZ)
335-
:: :column "\"Articles" $ [] (:: :link "\"design decision: rename \"keyword\" to \"tag\" #209" nil "\"https://github.com/calcit-lang/calcit/discussions/209") (:: :link "|Calcit 脚本语言一些基础介绍" nil |https://zhuanlan.zhihu.com/p/394791973) (:: :link "|Introducing calcit-js: toy language inspired by cljs" nil |https://clojureverse.org/t/introducing-calcit-js-toy-language-inspired-by-cljs/7097) (:: :link "|An indentation way to Lisp" nil |https://github.com/calcit-lang/calcit-runner/discussions/123) (:: :link "|Problems encountered in generating js" nil |https://github.com/calcit-lang/calcit-runner.nim/discussions/148) (:: :link "|calcit-js 的 JavaScript 代码生成与疑难" nil |https://github.com/calcit-lang/calcit-runner.nim/discussions/184) (:: :link "|ternary-tree.ts: 关于初期的性能优化(on early optimizations)" nil |https://github.com/calcit-lang/ternary-tree.ts/discussions/7) (:: :link "|A trick for cheaper persistent list in JavaScript" nil |https://clojureverse.org/t/a-trick-for-cheaper-persistent-list-in-javascript/7172)
368+
:: :column "\"Articles" $ [] (:: :link "\"Calcit 相比 Clojure 一些有意思的元编程能力 #226" nil "\"https://github.com/calcit-lang/calcit/discussions/226") (:: :link "\"design decision: rename \"keyword\" to \"tag\" #209" nil "\"https://github.com/calcit-lang/calcit/discussions/209") (:: :link "|Calcit 脚本语言一些基础介绍" nil |https://zhuanlan.zhihu.com/p/394791973) (:: :link "|Introducing calcit-js: toy language inspired by cljs" nil |https://clojureverse.org/t/introducing-calcit-js-toy-language-inspired-by-cljs/7097) (:: :link "|An indentation way to Lisp" nil |https://github.com/calcit-lang/calcit-runner/discussions/123) (:: :link "|Problems encountered in generating js" nil |https://github.com/calcit-lang/calcit-runner.nim/discussions/148) (:: :link "|calcit-js 的 JavaScript 代码生成与疑难" nil |https://github.com/calcit-lang/calcit-runner.nim/discussions/184) (:: :link "|ternary-tree.ts: 关于初期的性能优化(on early optimizations)" nil |https://github.com/calcit-lang/ternary-tree.ts/discussions/7) (:: :link "|A trick for cheaper persistent list in JavaScript" nil |https://clojureverse.org/t/a-trick-for-cheaper-persistent-list-in-javascript/7172)
336369
|doc-features $ %{} :CodeEntry (:doc |)
337370
:code $ quote
338371
def doc-features $ [] (:: :feature "\"Immutable" "\"Values and states are represented in different data structures, which is the semantics from functional programming. Internally it's [rpds](https://docs.rs/rpds/) in Rust and a custom [2-3 tree](https://github.com/calcit-lang/ternary-tree.ts) in JavaScript.") (:: :feature "\"Lisp(Code is Data)" "\"Calcit-js was designed based on experiences from ClojureScript, with a bunch of builtin macros. It offers similar experiences to ClojureScript. So Calcit offers much power via macros, while keeping its core simple.") (:: :feature "\"Indentations-based Syntax" "\"With `bundle_calcit` command, Calcit code can be written as an indentation-based language. So you don't have to match parentheses like in Clojure. It also means now you need to handle indentations very carefully.") (:: :feature "\"Hot code swapping" "\"Calcit was built with hot swapping in mind. Combined with [calcit-editor](https://github.com/calcit-lang/editor), it watches code changes by default, and re-runs program on updates. For calcit-js, it works with Vite and Webpack to reload, learning from Elm, ClojureScript and React.") (:: :feature "\"ES Modules Syntax" "\"To leverage the power of modern browsers with help of Vite, we need another ClojureScript that emits `import`/`export` for Vite. Calcit-js does this! And this page is built with Calcit-js as well, open Console to find out more.")

content/cirru.md

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
1+
### Editors
12

2-
### Cirru
3+
Calcit adopts idea of structural editing, using an auto-layout code editor. [@calcit/editor](https://github.com/calcit-lang/editor) is Calcit's default editor. You may find more about the ideas in [Structural Editing](http://guide.calcit-lang.org/structural-editor.html) section. Snapshot of editor is saved in "Cirru EDN" data format.
34

4-
Also see [Cirru Project](http://cirru.org/) for higher goals of auto-layout code editor, which is Calcit's default editor.
5+
Also see [Cirru Project](http://cirru.org/) for previous work on structural editing.
56

6-
Example of a `compact.cirru` file generated from calcit-editor:
7-
8-
```cirru
9-
{} (:package |app)
10-
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!)
11-
:modules $ []
12-
:files $ {}
13-
|app.main $ %{} :FileEntry
14-
:defs $ {}
15-
|main! $ quote
16-
defn main! () (+ 1 2)
17-
|reload! $ quote
18-
defn reload! ()
19-
:ns $ quote
20-
ns app.main $ :require
21-
```
22-
23-
If you want to write in a text editor, check out `bundle_calcit` command in project. 也可以查看相关中文[介绍视频](https://www.bilibili.com/video/BV1ry4y1W7VW?from=search&seid=17614445788882056969).
24-
25-
There's also a "Cirru EDN" format for data.
7+
If you want to write in a text editor, check out `bundle_calcit` command in project. A boilerplate can be find in [minimal-calcit](https://github.com/calcit-lang/minimal-calcit). 也可以查看相关中文[介绍视频](https://www.bilibili.com/video/BV1ry4y1W7VW?from=search&seid=17614445788882056969).

content/demo/comp.cirru

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defcomp comp-link (link)
2+
tag-match link $
3+
:link title sub-title url
4+
div ({})
5+
a $ {} (:href url)
6+
:inner-text title
7+
:target "\"_blank"
8+
:class-name style-display-link
9+
=< 8 nil
10+
<> sub-title $ str-spaced css/font-fancy style-sub-title

content/demo/persistent-data.cirru

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
-> ({})
3+
assoc :a 1
4+
assoc-in ([] :b :c) 2
5+
update :a $ fn (a) (inc a)

content/demo/pipeline.cirru

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
-> 100 range
3+
filter $ fn (x)
4+
> n 50
5+
map $ fn (x) (* x x)
6+
w-log

content/demo/tag-match.cirru

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
tag-match shape
3+
(:circle base radius) $ println "Circle with radius:" radius
4+
(:rect base width height) $ println "Rect with height:" height
5+
_ $ println "Unknown shape"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"dependencies": {
3-
"@calcit/procs": "^0.8.2",
3+
"@calcit/procs": "^0.8.13",
44
"cirru-color": "^0.2.3"
55
},
66
"devDependencies": {
77
"bottom-tip": "^0.1.5",
8-
"vite": "^4.4.9"
8+
"vite": "^5.0.4"
99
},
1010
"version": "0.0.1"
1111
}

0 commit comments

Comments
 (0)