Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
complexvalues [2019/01/04 16:50] christian [Anatomy of a Value] |
complexvalues [2022/03/06 08:57] (current) christian [Values] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Complex | + | ===== Values ===== |
The Values package is my base library for almost everything I do. It provides Values (as opposed to Objects) which are simple, immutable objects. Values can only be created but never modified. This allows for a functional programming style and simplyfies systems, since much less state has to be maintained. Especially I like to see all structure and details (of complex values) at a glance and the ease of creating test values. | The Values package is my base library for almost everything I do. It provides Values (as opposed to Objects) which are simple, immutable objects. Values can only be created but never modified. This allows for a functional programming style and simplyfies systems, since much less state has to be maintained. Especially I like to see all structure and details (of complex values) at a glance and the ease of creating test values. | ||
+ | Features: | ||
+ | * Values as known in the functional world: **immutable** and consisting only of values or primitive types. Values do not have an identity and are equal when their elements are equal. A Value always forms a simple tree without loops or references. Instead of mutating objects, values are copied with new elements. Values are created with a constructor taking all elements as arguments. | ||
+ | * **Literal**: | ||
+ | * **Defaults**: | ||
+ | * **Named Values**: some instances of a value class may be well known and should be use in the code instead of the generic constructor. This feature should be used with caution, since changes will break code using obsolete instances. Currently, only '' | ||
==== Motivation ==== | ==== Motivation ==== | ||
Line 38: | Line 43: | ||
</ | </ | ||
- | Withit | + | With it you can: |
* create a value with <code smalltalk> | * create a value with <code smalltalk> | ||
* ask for its parts <code smalltalk> | * ask for its parts <code smalltalk> | ||
Line 101: | Line 106: | ||
</ | </ | ||
- | Every value class has an # | + | Every value class has an # |
<code smalltalk> | <code smalltalk> | ||
Line 132: | Line 137: | ||
</ | </ | ||
- | After generating code with: <code smalltalk> | + | After generating code with: |
+ | <code smalltalk> | ||
+ | our example responds to #nickname : | ||
<code smalltalk> | <code smalltalk> | ||
Line 142: | Line 149: | ||
Person class>> | Person class>> | ||
</ | </ | ||
+ | |||
+ | Now you can specify a nickname: | ||
+ | <code smalltalk> | ||
+ | Person name: ' | ||
+ | </ | ||
+ | |||
+ | If you use the same parameter as the default, it is ignored | ||
+ | <code smalltalk> | ||
+ | Person name: ' | ||
+ | </ | ||
+ | because it is equal to | ||
+ | <code smalltalk> | ||
+ | Person name: ' | ||
+ | </ | ||
+ | |||
==== Get it ==== | ==== Get it ==== |