From 585be825cedb48e582740e4ffb91a8a48248a94b Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Fri, 9 Jun 2023 16:14:35 -0400 Subject: README tweaks, put style guide into README --- docs/index.md | 1 - docs/tcl.md | 121 ---------------------------------------------------------- 2 files changed, 122 deletions(-) delete mode 100644 docs/tcl.md (limited to 'docs') diff --git a/docs/index.md b/docs/index.md index a0832a5d..2c5b1e02 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2,4 +2,3 @@ - [code](./code) - [design](./design) -- [tcl](./tcl) \ No newline at end of file diff --git a/docs/tcl.md b/docs/tcl.md deleted file mode 100644 index 25690b93..00000000 --- a/docs/tcl.md +++ /dev/null @@ -1,121 +0,0 @@ -# Tcl - -## Tcl for JavaScripters - -JS: -``` -let names = ["64", "GameCube", "Wii", "Switch"]; -names = names.map(name => `Nintendo ${name}`); -console.log(names); - -function add(a, b) { return a + b; } -const numbers = [1, 2]; -console.log(add(...numbers)); -``` - -Tcl: -``` -set names [list 64 GameCube Wii Switch] -set names [lmap name $names {expr {"Nintendo $name"}}] -puts $names - -proc add {a b} { expr {$a + $b} } -set numbers [list 1 2] -puts [add {*}$numbers] -``` - -## Style guide - -### Tcl code vs. virtual programs vs. printed programs - -In general, avoid adding new .tcl files to the Git repo. Pure Tcl -libraries are an antipattern; we should only need them for the hard -core of the system. - -Most new code (both libraries and applications) should be virtual -programs (which ilve as .folk files in the virtual-programs/ -subfolder) or printed programs. - -### Folk - -- Use complete sentences when you word your claims and wishes. - - Bad: `Claim $this firstName Omar` - - Good: `Claim $this has first name Omar` - -- Scope using `$this` where appropriate to prevent weird global - interactions - - Bad: `Claim the value is 3` - - Good: `Claim $this has value 3` - -- Style for joins across multiple lines -- use `&\` and align on the - first token after `When`: - - ``` - When the fox is out &\ - the label is "Hello" &\ - everything seems good { - ... - } - ``` - -### Tcl - -#### fn - -Use `fn` instead of `proc` to get a lexically captured command. - -#### Error handling - -Use `try` (and `on error`) in new code. Avoid using `catch`; it's -older and easier to get wrong. - -#### Return - -In general, don't use `return` if it's the last statement in a code -block. Just put the statement there whose value you want to return. - -Bad: `proc add {a b} { return [expr {$a + $b}] }` -Good: `proc add {a b} { expr {$a + $b} }` - -Bad: `set x 3; return $x` -Good: `set x 3; set x` - -You should use `return` only when you actually need to return _early_. - -#### Tcl datatypes - -Create a namespace for your datatype that is an ensemble command with -operations on that datatype. - -(Examples: `statement`, `c`, `region`, `point`, `image`) - -Call the constructor `create`, as in `dict create` and `statement -create`. - -#### Singletons - -Capitalized namespace, like `Statements`. - - -### Working with regions - -A common pattern I've found myself doing is: - -```tcl -When /thing/ has region /r/ { - lassign $r vertices edges - lassign $vertices a b c d -} -``` - -Now you can think about addressing - -``` -a - b -| | -d - c -``` -- cgit v1.2.3