Skip to content

Commit 55664a6

Browse files
committed
Fixing TOCs and wordings
1 parent 719ade9 commit 55664a6

File tree

5 files changed

+51
-45
lines changed

5 files changed

+51
-45
lines changed

docs/DEVELOPMENT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Python packages are released using
77
it. Usually it means setup docker and install the package from PyPi (see [setup
88
instructions](https://cibuildwheel.pypa.io/en/stable/setup/#local)).
99

10-
There are additional preparations to be made. First of all it is needed to
10+
There are additional preparations to be made. First it is needed to
1111
allow building and installing `libhyperonc` library on a build environment.
1212
`cibuildwheel` uses isolated docker container for each kind of platform it
1313
supports. Only code of the Python package is copied into container
@@ -62,7 +62,7 @@ tag which should be in form of `v<version>` (for example if version is
6262
`0.1.7` then tag is `v0.1.7`). After typing the tag press `Create new tag
6363
on publish`. Now press `Generate release notes` button. It will automatically
6464
fill the `Release title` and `Release description` fields. Tick `Set as a
65-
pre-release` checkbox if needed and press `Publish release` button. Now you
65+
pre-release` checkbox if needed and press `Publish release` button. Now you
6666
have published new GitHub release and triggered a job to build release
6767
artifacts.
6868

docs/das_setup.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Distributed AtomSpace setup
12

23
## Running DAS module tests locally
34

docs/metta.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,3 +677,5 @@ else:
677677
$result += merge_bindings($bindings, $b)
678678
return $result
679679
```
680+
681+
## Standard library

docs/minimal-metta.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
# Minimal MeTTa specification
2+
13
This document describes the minimal set of embedded MeTTa instructions which is
24
designed to write the complete MeTTa interpreter in MeTTa. Current version of the
35
document includes improvements which were added after experimenting with the
46
first version of such an interpreter. It is not a final version and some
57
directions of the future work is explained at the end of the document.
68

7-
# Minimal instruction set
9+
## Minimal instruction set
810

9-
## Interpreter state
11+
### Interpreter state
1012

1113
The MeTTa interpreter evaluates an atom passed as an input. It evaluates it
1214
step by step executing a single instruction on each step. In order to do that
@@ -39,7 +41,7 @@ minimal set it is not interpreted further and returned as a part of the final
3941
result. Thus only the instructions of the minimal set are considered a code
4042
other atoms are considered a data.
4143

42-
## Evaluation order
44+
### Evaluation order
4345

4446
MeTTa implements the applicative evaluation order by default, arguments are
4547
evaluated before they are passed to the function. User can change this order
@@ -50,7 +52,7 @@ there is a [chain](#chain) operation which can be used to evaluate an argument
5052
before passing it. Thus `chain` can be used to change evaluation order in MeTTa
5153
interpreter.
5254

53-
## Error/Empty/NotReducible/()
55+
### Error/Empty/NotReducible/()
5456

5557
There are atoms which can be returned to designate a special situation in a code:
5658
- `(Error <atom> <message>)` means the interpretation is finished with error;
@@ -70,7 +72,7 @@ There are atoms which can be returned to designate a special situation in a code
7072
These atoms are not interpreted further as they are not a part of the minimal
7173
set of instructions and considered a data.
7274

73-
## eval
75+
### eval
7476

7577
`(eval <atom>)` is a first instruction which evaluates an atom passed as an
7678
argument. Evaluation is different for the grounded function calls (the
@@ -80,7 +82,7 @@ expressions. For the pure MeTTa expression the interpreter searches the `(=
8082
the result of evaluation. Execution of the grounded atom leads to the call of
8183
the foreign function passing the tail of the expression as arguments. For
8284
example `(+ 1 2)` calls the implementation of addition with `1` and `2` as
83-
arguments. The list of atoms returned by the grounded function is a result of
85+
arguments. The list of atoms returned by the grounded function is a result of
8486
the evaluation in this case. A grounded function can have side effects as well.
8587
In both cases bindings of the `eval`'s argument are merged to the bindings of
8688
the result.
@@ -98,7 +100,7 @@ the instruction for a special values are the following:
98100
grounded function. Function can return `()/Empty/NotReducible` to express "no
99101
result"/"remove my result"/"not defined on data".
100102

101-
## chain
103+
### chain
102104

103105
Minimal MeTTa implements normal evaluation order (see [Evaluation
104106
order](#evaluation-order). Arguments are passed to the function without
@@ -113,7 +115,7 @@ evaluation and returns result of the substitution. When evaluation of the
113115
`<atom>` brings more than a single result `chain` returns one instance of the
114116
`<template>` expression for each result.
115117

116-
## function/return
118+
### function/return
117119

118120
`function` operation has the signature `(function <atom>)`. It evaluates the
119121
`<atom>` until it becomes `(return <atom>)`. Then `(function (return <atom>))`
@@ -130,10 +132,10 @@ of this stack. Nevertheless using `chain` instead of `function` to implement
130132
the evaluation loop also allows representing stack in a natural form.
131133

132134
Evaluation of the `function` should always end by evaluating `(return <atom>)`
133-
expression. But as a result of an error some branch may end by non evaluatable
135+
expression. But as a result of an error some branch may end by non evaluable
134136
atom instead. In such case interpreter returns `(Error NoReturn)` error.
135137

136-
## unify
138+
### unify
137139

138140
`unify` operation allows conditioning on the results of the evaluation.
139141
`unify`'s signature is `(unify <atom> <pattern> <then> <else>)`. The operation
@@ -142,15 +144,15 @@ matches `<atom>` with a `<pattern>`. If match is successful then it returns
142144
variable bindings. If matching is not successful then it returns the `<else>`
143145
branch with the original variable bindings.
144146

145-
## cons-atom/decons-atom
147+
### cons-atom/decons-atom
146148

147149
`cons-atom` and `decons-atom` allows constructing and deconstructing the expression atom
148150
from/to pair of the head and tail. `(decons-atom <expr>)` expects non-empty
149151
expression as an argument and returns a pair `(<head> <tail>)`. `(cons-atom <head>
150152
<tail>)` returns an expression where the first sub-atom is `<head>` and others
151153
are copied from `<tail>`.
152154

153-
## collapse-bind
155+
### collapse-bind
154156

155157
`collapse-bind` has the signature `(collapse-bind <atom>)`. It evaluates the
156158
`<atom>` and returns an expression which contains all alternative evaluations
@@ -164,7 +166,7 @@ of the atom and filter out ones which led to errors.
164166
Name `collapse-bind` is temporary and chosen to eliminate conflict with
165167
`collapse` which is part of the standard library.
166168

167-
## superpose-bind
169+
### superpose-bind
168170

169171
`superpose-bind` has the signature `(superpose-bind ((<atom> <bindings>)
170172
...))`. It puts list of the results into the interpreter plan each pair as a
@@ -175,7 +177,7 @@ separate alternative.
175177
can collect the list of alternatives using `collapse-bind` filter them and
176178
return filtered items to the plan using `superpose-bind`.
177179

178-
## Scope of a variable
180+
### Scope of a variable
179181

180182
Each separately evaluated expression is a variable scope, and therefore variable names are treated as unique inside an expression.
181183
reason is that the whole expression is a variable scope. For example one can
@@ -204,7 +206,7 @@ following example:
204206
Here the value will not be assigned to the `$a` from the caller expression because
205207
each of the two variables has a different scope and they do not reference each other.
206208

207-
# Examples
209+
## Examples
208210

209211
Examples of the programs written using minimal MeTTa interpreter:
210212

@@ -243,9 +245,9 @@ Evaluate atom in a loop until result is calculated:
243245
(eval (reduce $res $var $templ)) )))))
244246
```
245247

246-
# Properties
248+
## Properties
247249

248-
## Turing completeness
250+
### Turing completeness
249251

250252
The following program implements a Turing machine using the minimal MeTTa
251253
instruction set (the full code of the example can be found
@@ -282,16 +284,16 @@ instruction set (the full code of the example can be found
282284
(return (() 0 $next-tail)) )))))
283285
```
284286

285-
## Comparison with MeTTa Operational Semantics
287+
### Comparison with MeTTa Operational Semantics
286288

287289
One difference from MOPS [1] is that the minimal instruction set allows
288290
relatively easy write deterministic programs and non-determinism is injected
289-
only via matching and evaluation. `Query` and `Chain` from MOPS are very
290-
similar to `eval`. `Transform` is very similar to `unify`. `chain` has no
291+
only via matching and evaluation. `Query` and `Chain` from MOPS are
292+
similar to `eval`. `Transform` is similar to `unify`. `chain` has no
291293
analogue in MOPS. `cons-atom`/`decons-atom` to some extent are analogues of
292294
`AtomAdd`/`AtomRemove` in a sense that they can be used to change the state.
293295

294-
## Partial and complete functions
296+
### Partial and complete functions
295297

296298
Each instruction in a minimal instruction set is a total function.
297299
Nevertheless `Empty` allows defining partial functions in MeTTa. For example
@@ -300,7 +302,7 @@ partial `if` can be defined as follows:
300302
(= (if $condition $then) (unify $condition True $then Empty))
301303
```
302304

303-
## eval or return
305+
### eval or return
304306

305307
Using `eval` to designate evaluation of the atom seems too verbose. But we need
306308
to give a programmer some way to designate whether the atom should be evaluated
@@ -356,7 +358,7 @@ used on each exit path while nothing in code of function points to this. Using
356358
- functions which evaluate result in a loop and have to use `return`;
357359
- functions which just replace the calling expression by their bodies.
358360

359-
# MeTTa interpreter written in Rust
361+
## MeTTa interpreter written in Rust
360362

361363
MeTTa interpreter written in minimal MeTTa has poor performance. To fix this
362364
the interpreter is rewritten in Rust. Rust implementation can be called using
@@ -373,16 +375,16 @@ returning bindings as a results. Returning bindings as results is a nice to
373375
have feature anyway to be able representing any functionality as a grounded
374376
atom. But it is not implemented yet.
375377

376-
# Future work
378+
## Future work
377379

378-
## Explicit atomspace variable bindings
380+
### Explicit atomspace variable bindings
379381

380382
Current implementation implicitly keeps and applies variable bindings during
381383
the process of the interpretation. Explicit bindings are used to implement
382-
`collapse-bind` where they are absolutely necessary. Bindings can be easily
384+
`collapse-bind` where they are necessary. Bindings can be easily
383385
made explicit everywhere but the value of explicit bindings is not obvious see
384386
[discussion in issue
385-
#290](https://github.com/trueagi-io/hyperon-experimental/issues/290#issuecomment-1541314289).
387+
##290](https://github.com/trueagi-io/hyperon-experimental/issues/290#issuecomment-1541314289).
386388

387389
Making atomspace part of the explicit context could make import semantics more
388390
straightforward. In the current implementation of the minimal instruction set
@@ -395,7 +397,7 @@ Nevertheless defining `eval` through `unify` requires rework of the grounded
395397
functions interface to allow calling them by executing `unify` instructions.
396398
Which is an interesting direction to follow.
397399

398-
## Special matching syntax
400+
### Special matching syntax
399401

400402
Sometimes it is convenient to change the semantics of the matching within a
401403
pattern. Some real examples are provided below. One possible way to extend
@@ -404,7 +406,7 @@ first position. For instance `(:<mod> <atom>)` could apply `<mod>` rule to
404406
match the `<atom>`. How to eliminate interference of this syntax with symbol
405407
atoms used by programmers is an open question.
406408

407-
### Syntax to match atom by equality
409+
#### Syntax to match atom by equality
408410

409411
In many situations we need to check that atom is equal to some symbol. `unify`
410412
doesn't work well in such cases because when checked atom is a variable it is
@@ -413,15 +415,15 @@ matched with anything (for instance `(unify $x Empty then else)` returns
413415
equality. For instance `(unify <atom> (:= Empty) then else)` should match
414416
`<atom>` with pattern only when `<atom>` is `Empty`.
415417

416-
### Syntax to match part of the expression
418+
#### Syntax to match part of the expression
417419

418420
We could have a specific syntax which would allow matching part of the
419421
expressions. For example such syntax could be used to match head and tail of
420422
the expression without using `cons-atom`/`decons-atom`. Another example is matching part
421423
of the expression with some gap, i.e. `(A ... D ...)` could match `(A B C D E)`
422424
atom.
423425

424-
# Links
426+
## Links
425427

426428
1. Lucius Gregory Meredith, Ben Goertzel, Jonathan Warrell, and Adam
427429
Vandervorst. Meta-MeTTa: an operational semantics for MeTTa.

docs/modules_dev.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
# MeTTa modules
12

2-
# MeTTa Modules (Rust / Python Developer Documentation)
3+
## MeTTa Modules (Rust / Python Developer Documentation)
34

45
TODO: Integrate this documentation within the larger MeTTa Book
56

67
Modules are implementations of free-standing MeTTa functionality that can be imported into other MeTTa modules or programs. Modules may be implemented in MeTTa code itself, but they may also include functionality implemented with, or linked from host languages such as Rust, C, or Python. Modules may include additional files and resources as well.
78

89
**_NOTE:_** Importantly, a module can have sub-module dependencies, aka "downward" dependencies, but it cannot have "upward" dependencies, ie. dependencies on the client code importing the module.
910

10-
## What *is* a Module?
11+
### What *is* a Module?
1112

1213
Fundamentally a module in a persistent encapsulation of a context within which MeTTa code can run. Every module has a unique [Space] (and also a [Tokenizer], for now). For MeTTa code running within the context of a module, the `&self` token will resolve to the module's space.
1314

1415
A loaded module is represented with the [MettaMod] struct. In addition to a [Space] and a [Tokenizer], a module may also contain a filesystem path to the module's resources, the sub-modules imported by the module, a [ModuleDescriptor] object, and a [PkgInfo] struct, the latter of which are documented in the [Package Management](#package-management) section.
1516

1617
To execute code in the context of any loaded module, use the [RunnerState::new_with_module] method.
1718

18-
## Loading a Module
19+
### Loading a Module
1920

2021
Modules are loaded into a [Metta] runner using one of the module loading methods: [Metta::load_module_direct], [Metta::load_module_at_path], or [RunContext::load_module]. Loaded modules are referred to with a [ModId].
2122

2223
Fundamentally, all modules are loaded via a loader object that implements the [ModuleLoader] trait. Irrespective of the module's original format or host language, a loader object's [ModuleLoader::load] function ultimately loads the module into the runner.
2324

24-
### Module Names & Name Paths
25+
#### Module Names & Name Paths
2526

2627
Each loaded module must have a name. A legal module name is an ascii string, containing only alpha-numeric characters plus `_` and `-`.
2728

@@ -55,7 +56,7 @@ will cause the name `some_module` to be resolved into a specific module instance
5556

5657
**NOTE**: The same module name may occur in multiple places in the hierarchy, and there is no guaranteed a name will always refer to the same module. However, within a given node of the module name hierarchy, a module name will always be unique.
5758

58-
## Importing a Module
59+
### Importing a Module
5960

6061
A module is imported into another module using one of the import methods:
6162
- [MettaMod::import_dependency_as], corresponding to `import module as name`
@@ -64,7 +65,7 @@ A module is imported into another module using one of the import methods:
6465

6566
Once imported, a sub-module is accessed via an embedded [Space] atom in the destination module's space, [Tokenizer] entries for accessing the source module's space, tokens, or a combination of the two.
6667

67-
### Behavior WIP
68+
#### Behavior WIP
6869

6970
TODO: The precise semantics of importing (in other words, linking) are still under discussion and development. Specifically we may wish to provide a mechanism to explicitly declare what is exported from a module (and thus available for import). This would be similar to the `export` key words in some languages, or the `pub` visibility qualifiers in Rust.
7071

@@ -77,7 +78,7 @@ Some issues regarding this are:
7778

7879
More discussion on these topics is in the section: "Importing / Linking" of the `modules_internal_discussion.md` file.
7980

80-
# Package Management
81+
## Package Management
8182

8283
Package Management is the set of features that allow for:
8384
- searching for modules across multiple locations (Catalogs)
@@ -86,15 +87,15 @@ Package Management is the set of features that allow for:
8687

8788
Modularity is a fundamental and inseparable aspect of the MeTTa runner, but Package Management features could be optional.
8889

89-
## Module File Formats
90+
### Module File Formats
9091

9192
Modules may be loaded from files and other file-system-like resources (for example, a github repo) using the objects that implement the [FsModuleFormat] trait. This trait contains the interface to interpret a file or a directory and instantiate a [ModuleLoader] to load the module(s) contained within.
9293

9394
The objects [SingleFileModuleFmt] and [DirModuleFmt] are part of the default environment and are capable of loading MeTTa modules from single `.metta` files and directories containing a `module.metta` file respectively. Additionally, the `hyperon` Python module contains a [FsModuleFormat] for loading MeTTa modules from Python modules - both stand-alone `.py` files as well as directories containing an `__init__.py` file.
9495

9596
More information on the individual module file formats is available in the MeTTa usage documentation and MeTTa Python documentation respectively.
9697

97-
## The PkgInfo Structure
98+
### The PkgInfo Structure
9899

99100
Each module has an associated [PkgInfo] structure, which provides the module author a place to specify meta-data about the module and express requirements for the module's dependencies. Additionally a [PkgInfo] can provide explicit loading instructions such as file system paths or github URLs for dependent modules. The [PkgInfo] structure is the same concept as the Cargo.toml file used in Cargo/Rust.
100101

@@ -105,7 +106,7 @@ docs on https://docs.rs when Rust crate is published).
105106

106107
TODO: PkgInfo documentation also belongs in user-facing docs. In that section, cover how to specify the pkginfo as a MeTTa structure and/or in a `_pkg-info.metta` or `_pkg-info.json` file as opposed to as a Rust struct.
107108

108-
## Module Name Resolution
109+
### Module Name Resolution
109110

110111
When MeTTa code executes the `!(import! &space some_module)` operation, the module name needs to be mapped to a loaded or loadable module. This process occurs according to the logic described by the flowchart below.
111112

@@ -130,15 +131,15 @@ Depending on the host OS, the config directory locations will be:
130131

131132
In the future we may create a centralized module catalog along the lines of `PyPI` or `crates.io`.
132133

133-
## Catalogs
134+
### Catalogs
134135

135136
An object that implements the [ModuleCatalog] trait exposes an interface to locate modules based on name and version constraints, and create [ModuleLoader] objects to retrieve and load those modules.
136137

137138
One built-in [ModuleCatalog] object type is the [DirCatalog]. As described in the "Module File Formats" section, a [DirCatalog] uses a collection of [FsModuleFormat] objects to export a catalog of modules contained within its associated directory.
138139

139140
Additional catalogs may be implemented for other module repository formats or protocols - for example a central package service similar to `PyPI` or `crates.io`, as mentioned earlier.
140141

141-
## Implementing a [ModuleLoader]
142+
### Implementing a [ModuleLoader]
142143

143144
All modules are ultimately loaded programmatically through the MeTTa API, and it's the role of a [ModuleLoader] to make the necessary API calls.
144145

0 commit comments

Comments
 (0)