Skip to content

Commit

Permalink
move example code to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Nov 15, 2024
1 parent 07a5c9f commit 1142ae5
Show file tree
Hide file tree
Showing 110 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ eval @inspect(sixSoles())
[ [Goto The Playground](https://inet.xieyuheng.com/playground/aW1wb3J0IHsgTGlzdCB9IGZyb20gImh0dHBzOi8vY29kZS1vZi1pbmV0LWpzLnhpZXl1aGVuZy5jb20vZG9jcy9zdGQvZGF0YXR5cGUvTGlzdC5pIgoKLy8gQ29uY2F0ZW5hdGlvbiBvZiBsaXN0cyBpcyBwZXJmb3JtZWQgaW4gbGluZWFyIHRpbWUKLy8gd2l0aCByZXNwZWN0IHRvIGl0cyBmaXJzdCBhcmd1bWVudC4KLy8gQ29uc3RhbnQgdGltZSBjb25jYXRlbmF0aW9uIGlzIHBvc3NpYmxlCi8vIHdpdGggZGlmZmVyZW5jZS1saXN0czogdGhlIGlkZWEgY29uc2lzdHMgaW4KLy8gcGx1Z2dpbmcgdGhlIGZyb250IG9mIHRoZSBzZWNvbmQgYXJndW1lbnQKLy8gYXQgdGhlIGJhY2sgb2YgdGhlIGZpcnN0IG9uZS4KCnR5cGUgRGlmZkxpc3QoRWxlbWVudDogQFR5cGUpCgpub2RlIGRpZmYoCiAgZnJvbnQ6IExpc3QoJ0EpLAogIC0tLS0tLS0KICBiYWNrOiBMaXN0KCdBKSwKICB2YWx1ZSE6IERpZmZMaXN0KCdBKSwKKQoKbm9kZSBkaWZmQXBwZW5kKAogIHRhcmdldCE6IERpZmZMaXN0KCdBKSwKICByZXN0OiBEaWZmTGlzdCgnQSkKICAtLS0tLS0tLQogIHJlc3VsdDogRGlmZkxpc3QoJ0EpCikKCm5vZGUgZGlmZk9wZW4oCiAgdGFyZ2V0ITogRGlmZkxpc3QoJ0EpLAogIG5ld0JhY2s6IExpc3QoJ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List } from "https://code-of-inet-js.xieyuheng.com/docs/std/datatype/List.i"
import { List } from "https://code-of-inet-js.xieyuheng.com/examples/datatype/List.i"
// Concatenation of lists is performed in linear time
// with respect to its first argument.
Expand Down Expand Up @@ -185,7 +185,7 @@ rule diffOpen(target!, newBack, oldBack)
// TEST
import { cons } from "https://code-of-inet-js.xieyuheng.com/docs/std/datatype/List.i"
import { cons } from "https://code-of-inet-js.xieyuheng.com/examples/datatype/List.i"
type Trivial
Expand Down
10 changes: 5 additions & 5 deletions docs/articles/programming-with-interaction-nets.md
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ to import definitions from other module.
import {
Nat, zero, add1, add,
one, two, three,
} from "https://code-of-inet-js.xieyuheng.com/std/datatype/Nat.i"
} from "https://code-of-inet-js.xieyuheng.com/examples/datatype/Nat.i"
node natErase(
target!: Nat
Expand Down Expand Up @@ -794,7 +794,7 @@ rule append(target!, rest, result) cons(head, tail, value!) {
cons(head, append(tail, rest), result)
}
import { Nat, zero } from "https://code-of-inet-js.xieyuheng.com/std/datatype/Nat.i"
import { Nat, zero } from "https://code-of-inet-js.xieyuheng.com/examples/datatype/Nat.i"
function sixZeros(): List(Nat) {
return append(
Expand Down Expand Up @@ -836,7 +836,7 @@ the relationship between all nodes is symmetric.
[Goto the playground of `DiffList` and `(diffAppend)`](https://inet.xieyuheng.com/playground/aW1wb3J0IHsgTGlzdCB9IGZyb20gImh0dHBzOi8vY29kZS1vZi1pbmV0LWpzLmZpZGIuYXBwL3N0ZC9kYXRhdHlwZS9MaXN0LmkiCgp0eXBlIERpZmZMaXN0KEVsZW1lbnQ6IEBUeXBlKQoKbm9kZSBkaWZmKAogIGZyb250OiBMaXN0KCdBKSwKICAtLS0tLS0tCiAgYmFjazogTGlzdCgnQSksCiAgdmFsdWUhOiBEaWZmTGlzdCgnQSksCikKCm5vZGUgZGlmZkFwcGVuZCgKICB0YXJnZXQhOiBEaWZmTGlzdCgnQSksCiAgcmVzdDogRGlmZkxpc3Q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WZmQXBwZW5kKHZhbHVlMSwgdmFsdWUyKQp9CgpldmFsIHR3b1R3b1plcm9zKCk)

```
import { List } from "https://code-of-inet-js.xieyuheng.com/std/datatype/List.i"
import { List } from "https://code-of-inet-js.xieyuheng.com/examples/datatype/List.i"
type DiffList(Element: @Type)
Expand Down Expand Up @@ -874,8 +874,8 @@ rule diffOpen(target!, newBack, oldBack)
@connect(front, oldBack)
}
import { Nat, zero } from "https://code-of-inet-js.xieyuheng.com/std/datatype/Nat.i"
import { cons } from "https://code-of-inet-js.xieyuheng.com/std/datatype/List.i"
import { Nat, zero } from "https://code-of-inet-js.xieyuheng.com/examples/datatype/Nat.i"
import { cons } from "https://code-of-inet-js.xieyuheng.com/examples/datatype/List.i"
function twoTwoZeros(): DiffList(Nat) {
let front, back, value1 = diff()
Expand Down
10 changes: 5 additions & 5 deletions docs/articles/反应网编程.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ eval max(two(), three())
import {
Nat, zero, add1, add,
one, two, three,
} from "https://code-of-inet-js.xieyuheng.com/std/datatype/Nat.i"
} from "https://code-of-inet-js.xieyuheng.com/examples/datatype/Nat.i"
node natErase(
target!: Nat
Expand Down Expand Up @@ -768,7 +768,7 @@ rule append(target!, rest, result) cons(head, tail, value!) {
cons(head, append(tail, rest), result)
}
import { Nat, zero } from "https://code-of-inet-js.xieyuheng.com/std/datatype/Nat.i"
import { Nat, zero } from "https://code-of-inet-js.xieyuheng.com/examples/datatype/Nat.i"
function sixZeros(): List(Nat) {
return append(
Expand Down Expand Up @@ -806,7 +806,7 @@ eval sixZeros()
[去 `DiffList` 与 `(diffAppend)` 的演算场](https://inet.xieyuheng.com/playground/aW1wb3J0IHsgTGlzdCB9IGZyb20gImh0dHBzOi8vY29kZS1vZi1pbmV0LWpzLmZpZGIuYXBwL3N0ZC9kYXRhdHlwZS9MaXN0LmkiCgp0eXBlIERpZmZMaXN0KEVsZW1lbnQ6IEBUeXBlKQoKbm9kZSBkaWZmKAogIG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JvbnQsIGNvbnMoemVybygpLCBjb25zKHplcm8oKSwgYmFjaykpKQogIGxldCBmcm9udCwgYmFjaywgdmFsdWUyID0gZGlmZigpCiAgQGNvbm5lY3QoZnJvbnQsIGNvbnMoemVybygpLCBjb25zKHplcm8oKSwgYmFjaykpKQogIHJldHVybiBkaWZmQXBwZW5kKHZhbHVlMSwgdmFsdWUyKQp9CgpldmFsIHR3b1R3b1plcm9zKCk)

```
import { List } from "https://code-of-inet-js.xieyuheng.com/std/datatype/List.i"
import { List } from "https://code-of-inet-js.xieyuheng.com/examples/datatype/List.i"
type DiffList(Element: @Type)
Expand Down Expand Up @@ -844,8 +844,8 @@ rule diffOpen(target!, newBack, oldBack)
@connect(front, oldBack)
}
import { Nat, zero } from "https://code-of-inet-js.xieyuheng.com/std/datatype/Nat.i"
import { cons } from "https://code-of-inet-js.xieyuheng.com/std/datatype/List.i"
import { Nat, zero } from "https://code-of-inet-js.xieyuheng.com/examples/datatype/Nat.i"
import { cons } from "https://code-of-inet-js.xieyuheng.com/examples/datatype/List.i"
function twoTwoZeros(): DiffList(Nat) {
let front, back, value1 = diff()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[execute / Import] I can not do circular import.

loading module url: docs/std/tests/module/circular-import-3.error.i
importing module url: docs/std/tests/module/circular-import-1.error.i
loading module url: examples/tests/module/circular-import-3.error.i
importing module url: examples/tests/module/circular-import-1.error.i

[execute] I fail to execute a statement.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[execute / Import] I can not do circular import.

loading module url: docs/std/tests/module/circular-import-1.error.i
importing module url: docs/std/tests/module/circular-import-2.error.i
loading module url: examples/tests/module/circular-import-1.error.i
importing module url: examples/tests/module/circular-import-2.error.i

[execute] I fail to execute a statement.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[execute / Import] I can not do circular import.

loading module url: docs/std/tests/module/circular-import-2.error.i
importing module url: docs/std/tests/module/circular-import-3.error.i
loading module url: examples/tests/module/circular-import-2.error.i
importing module url: examples/tests/module/circular-import-3.error.i

[execute] I fail to execute a statement.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[execute / Require] I can not do circular require.

loading module url: docs/std/tests/module/circular-require-3.error.i
requiring module url: docs/std/tests/module/circular-require-1.error.i
loading module url: examples/tests/module/circular-require-3.error.i
requiring module url: examples/tests/module/circular-require-1.error.i

[execute] I fail to execute a statement.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[execute / Require] I can not do circular require.

loading module url: docs/std/tests/module/circular-require-1.error.i
requiring module url: docs/std/tests/module/circular-require-2.error.i
loading module url: examples/tests/module/circular-require-1.error.i
requiring module url: examples/tests/module/circular-require-2.error.i

[execute] I fail to execute a statement.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[execute / Require] I can not do circular require.

loading module url: docs/std/tests/module/circular-require-2.error.i
requiring module url: docs/std/tests/module/circular-require-3.error.i
loading module url: examples/tests/module/circular-require-2.error.i
requiring module url: examples/tests/module/circular-require-3.error.i

[execute] I fail to execute a statement.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[execute / Import] I can not do circular import.

loading module url: docs/std/tests/module/self-import.error.i
importing module url: docs/std/tests/module/self-import.error.i
loading module url: examples/tests/module/self-import.error.i
importing module url: examples/tests/module/self-import.error.i

[execute] I fail to execute a statement.

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[execute / Require] I can not do circular require.

loading module url: docs/std/tests/module/self-require.error.i
requiring module url: docs/std/tests/module/self-require.error.i
loading module url: examples/tests/module/self-require.error.i
requiring module url: examples/tests/module/self-require.error.i

[execute] I fail to execute a statement.

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[checkRuleIsAboutOwnNode] To define a rule, one of the node must be owned by this module.

loading module url: docs/std/tests/statement/rule-for-non-own-node.error.i
first node module url: docs/std/datatype/Nat.i
second node module url: docs/std/datatype/Nat.i
loading module url: examples/tests/statement/rule-for-non-own-node.error.i
first node module url: examples/datatype/Nat.i
second node module url: examples/datatype/Nat.i

[execute] I fail to execute a statement.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"build": "tsc",
"build:watch": "tsc --watch",
"test:ts": "vitest --dir src --run",
"test:inet-parse": "test-runner test 'node ./bin/inet-js parse --no-color' 'docs/std/**/*.i'",
"test:inet-format": "test-runner test 'node ./bin/inet-js format --no-color' 'docs/std/**/*.i'",
"test:inet-run": "test-runner snapshot 'node ./bin/inet-js run --no-color' 'docs/std/**/*.i' --exclude 'docs/std/**/*.error.i'",
"test:inet-run-error": "test-runner snapshot-error 'node ./bin/inet-js run --no-color' 'docs/std/**/*.error.i'",
"test:inet-parse": "test-runner test 'node ./bin/inet-js parse --no-color' 'examples/**/*.i'",
"test:inet-format": "test-runner test 'node ./bin/inet-js format --no-color' 'examples/**/*.i'",
"test:inet-run": "test-runner snapshot 'node ./bin/inet-js run --no-color' 'examples/**/*.i' --exclude 'examples/**/*.error.i'",
"test:inet-run-error": "test-runner snapshot-error 'node ./bin/inet-js run --no-color' 'examples/**/*.error.i'",
"test": "npm run test:ts && npm run test:inet-run && npm run test:inet-run-error",
"format": "prettier src docs --write"
},
Expand Down
2 changes: 1 addition & 1 deletion src/command-line/commands/Format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Format extends Command<Args, Opts> {
return [
`Format a file:`,
``,
blue(` ${runner.name} ${this.name} std/datatype/Nat.test.i`),
blue(` ${runner.name} ${this.name} examples/datatype/Nat.test.i`),
``,
].join("\n")
}
Expand Down
2 changes: 1 addition & 1 deletion src/command-line/commands/Parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Parse extends Command<Args, Opts> {
return [
`Parse a file:`,
``,
blue(` ${runner.name} ${this.name} std/datatype/Nat.test.i`),
blue(` ${runner.name} ${this.name} examples/datatype/Nat.test.i`),
``,
].join("\n")
}
Expand Down
4 changes: 2 additions & 2 deletions src/command-line/commands/Run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class Run extends Command<Args, Opts> {
return [
`Run a file:`,
``,
blue(` ${runner.name} ${this.name} std/datatype/Nat.test.i`),
blue(` ${runner.name} ${this.name} examples/datatype/Nat.test.i`),
``,
`Run a URL:`,
``,
blue(` ${runner.name} ${this.name} https://code-of-inet.xieyuheng.com/std/datatype/Nat.test.i`),
blue(` ${runner.name} ${this.name} https://code-of-inet.xieyuheng.com/examples/datatype/Nat.test.i`),

``,
].join("\n")
Expand Down

0 comments on commit 1142ae5

Please sign in to comment.