Không có mô tả

Herbert Vojčík 45563d44b6 Extract common code to Axes class-side helpers. 6 năm trước cách đây
src 45563d44b6 Extract common code to Axes class-side helpers. 6 năm trước cách đây
.gitignore 084a65a91b Initial commit. Extracted from Trapped. 9 năm trước cách đây
Gruntfile.js ef91544d33 Shape into Axxord, step 2. 6 năm trước cách đây
LICENSE-MIT 084a65a91b Initial commit. Extracted from Trapped. 9 năm trước cách đây
README.md 6ac9e12684 README: Axes. 6 năm trước cách đây
bower.json ef91544d33 Shape into Axxord, step 2. 6 năm trước cách đây
deploy.js ef91544d33 Shape into Axxord, step 2. 6 năm trước cách đây
devel.js e67e5b041d Move to amber 0.19.1. 6 năm trước cách đây
index.html ef91544d33 Shape into Axxord, step 2. 6 năm trước cách đây
local.amd.json ef91544d33 Shape into Axxord, step 2. 6 năm trước cách đây
package.json ef91544d33 Shape into Axxord, step 2. 6 năm trước cách đây
testing.js e227741785 Shape into Axxord, step 3. 6 năm trước cách đây

README.md

Axxord

Small blackboard system for Amber Smalltalk.

Axes

Axes is hierarchical index used to access blackboard data.

Axes is an array of elements: either strings, numbers or a sub-arrays. These are used to denote the (relative) location of a piece of data in a hierarchical object, and is used to read or write from / to this position.

Elements of a path are equivalent to elements of paths in classic file systems: each elements is one step deeper in a tree hierarchy. Thus, to read a data denoted by a path, Axes starts from actual position, reads the contents denoted by first element, use the result to read the contents denoted by second elements etc. until the end. To write the data, the algorithm is similar to reading one, byt the last element is used to write the data instead.

  • if string path element is read from foo, foo at: aString is performed;
  • if string path element is written to foo, foo at: aString put: value is performed;
  • if number path element is read from foo, foo at: aNumber is performed;
  • if number path element is written to foo, foo at: aNumber put: value is performed;
  • if subarray path element #(bar) is read from foo, foo bar is performed;
  • if subarray path element #(bar) is written to foo, foo bar: value is performed.

###API


Object >> atAxes: aCollection ifAbsent: aBlock

For example container atAxes: #((todos) 1 done) ifAbsent: [...]' essentially does

| x |
x := container todos at: 1.
^ x at: 'done'

But, whenever:

  • container fails to perform todos, or
  • container todos fails to perform at:ifAbsent:, or
  • container todos does not contain index 1, or
  • container todos at: 1 fails to perform at:ifAbsent:, or
  • container todos at: 1 does not contain index 'done',

the ifAbsent block value is returned.


Object >> atAxes: aCollection ifAbsent: aBlock put: anObject

For example container atAxes: #((todos) 1 done) ifAbsent: [...] put: 'foo' essentially does

| x |
x := container todos at: 1.
^ x at: 'done' put: 'foo'

But, whenever:

  • container fails to perform todos, or
  • container todos fails to perform at:ifAbsent:, or
  • container todos does not contain index 1, or
  • container todos at: 1 fails to do at:put:,

the ifAbsent block value is returned.


Axes class >> parse: aString

Parses a string to get a proper array index to use with atAxes: API.

The syntax is resembling Smalltalk literal array syntax very closely. For example Axes parse: '(value)' and Axes parse: '(todos) 1 done' produce #((value)) and #((todos) 1 done) as results.

Syntactic sugar: as (foo) happens often, to denote unary selector, it can be written equivalently as ~foo, to improve readability. So above Axes' parseable string representation would likely be written '~value' and '~todos 1 done' instead.