From 46ac4c271b7afff41969280f8e6419468aeadeaf Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Sun, 28 Apr 2024 15:34:44 +0800 Subject: [PATCH] rename clause keyword to relation --- TODO.md | 2 + .../tests/finite-domain/FiniteDomain.ch | 0 .../finite-domain/FiniteDomain.example.ch | 0 .../finite-domain/FiniteDomain.example.ch.out | 0 .../tests/finite-domain/FiniteDomain.test.ch | 0 .../finite-domain/FiniteDomain.test.ch.out | 0 .../archive}/tests/finite-domain/index.ch | 0 {archive => docs/archive}/tests/hyperrule.ch | 0 .../archive}/tests/hyperrule.ch.out | 0 .../archive}/tests/hyperrule/abc.ch | 0 .../archive}/tests/hyperrule/abc.ch.out | 0 .../tests/hyperrule/propagate-idempotent.ch | 0 .../hyperrule/propagate-idempotent.ch.out | 0 .../hyperrule/propagate-keep-the-input.ch | 0 .../hyperrule/propagate-keep-the-input.ch.out | 0 .../archive}/tests/hyperrule/walk.ch | 0 .../archive}/tests/hyperrule/walk.ch.out | 0 .../weather-hyperrule-list-as-exp.ch | 0 .../weather-hyperrule-list-as-exp.ch.out | 0 .../tests/hyperrule/weather-include.ch | 0 .../tests/hyperrule/weather-include.ch.out | 0 .../tests/hyperrule/weather-with-guard.ch | 0 .../tests/hyperrule/weather-with-guard.ch.out | 0 .../archive}/tests/hyperrule/weather.ch | 0 .../archive}/tests/hyperrule/weather.ch.out | 0 {archive => docs/archive}/tests/rule.ch | 0 {archive => docs/archive}/tests/rule.ch.out | 0 .../archive}/tests/rule/arithmetic.ch | 0 .../archive}/tests/rule/arithmetic.ch.out | 0 .../archive}/tests/rule/combinatory-logic.ch | 0 .../tests/rule/combinatory-logic.ch.out | 0 .../tests/rule/conjunctive-normal-form.ch | 0 .../tests/rule/conjunctive-normal-form.ch.out | 0 .../archive}/tests/rule/rule-list-as-exp.ch | 0 .../tests/rule/rule-list-as-exp.ch.out | 0 .../tests/rule/same-pattern-variable.ch | 0 .../tests/rule/same-pattern-variable.ch.out | 0 .../archive}/tests/rule/with-guard.ch | 0 .../archive}/tests/rule/with-guard.ch.out | 0 .../archive}/tests/rule/with-include.ch | 0 .../archive}/tests/rule/with-include.ch.out | 0 .../03-affordable-journeys.ch | 37 -------- .../04-acyclic-directed-graph.ch | 31 ------- .../books/clause-and-effect/01-party-pairs.ch | 10 +-- .../clause-and-effect/01-party-pairs.ch.out | 0 .../clause-and-effect/02-drinking-pairs.ch | 14 ++-- .../02-drinking-pairs.ch.out | 0 .../03-affordable-journeys.ch | 37 ++++++++ .../03-affordable-journeys.ch.out | 0 .../04-acyclic-directed-graph.ch | 31 +++++++ .../04-acyclic-directed-graph.ch.out | 0 .../books/clause-and-effect/05-member.ch | 4 +- .../books/clause-and-effect/05-member.ch.out | 0 .../clause-and-effect/06-length-of-a-list.ch | 4 +- .../clause-and-effect/08-maximum-of-a-list.ch | 6 +- .../09-searching-a-cyclic-graph.ch | 30 +++---- .../09-searching-a-cyclic-graph.ch.out | 0 .../a-boston-high-tech-company.ch | 84 +++++++++---------- .../a-boston-high-tech-company.ch.out | 0 .../logic-as-programs.md | 12 +-- .../the-reasoned-schemer/01-playthings.ch | 8 +- .../the-reasoned-schemer/01-playthings.ch.out | 0 .../02-teaching-old-toys-new-tricks.ch | 16 ++-- .../02-teaching-old-toys-new-tricks.ch.out | 0 .../03-seeing-old-friends-in-new-ways.ch | 26 +++--- .../03-seeing-old-friends-in-new-ways.ch.out | 0 .../04-double-your-fun.ch | 8 +- .../04-double-your-fun.ch.out | 0 .../the-reasoned-schemer/05-members-only.ch | 10 +-- .../05-members-only.ch.out | 0 .../06-the-fun-never-ends.ch | 6 +- .../06-the-fun-never-ends.ch.out | 0 .../the-reasoned-schemer/07-a-bit-too-much.ch | 54 ++++++------ .../07-a-bit-too-much.ch.out | 0 .../08-just-a-bit-more.ch | 28 +++---- .../08-just-a-bit-more.ch.out | 0 .../books/the-reasoned-schemer/09-thin-ice.ch | 0 .../the-reasoned-schemer/10-under-the-hood.ch | 0 docs/{ => examples}/langs/lambda-closure.ch | 22 ++--- .../langs/lambda-closure.ch.out | 0 .../langs/lambda-simple-type.ch | 24 +++--- .../langs/lambda-simple-type.ch.out | 0 docs/examples/std/list/Append.ch | 6 ++ docs/{ => examples}/std/list/Append.test.ch | 0 .../std/list/Append.test.ch.out | 0 docs/{ => examples}/std/list/Lookup.ch | 4 +- docs/{ => examples}/std/list/Lookup.test.ch | 0 .../std/list/Lookup.test.ch.out | 0 docs/{ => examples}/std/list/index.ch | 0 docs/{ => examples}/std/nat/Add.ch | 4 +- docs/{ => examples}/std/nat/Add.test.ch | 0 docs/{ => examples}/std/nat/Add.test.ch.out | 0 docs/{ => examples}/std/nat/Mul.ch | 6 +- docs/{ => examples}/std/nat/Mul.test.ch | 0 docs/{ => examples}/std/nat/Mul.test.ch.out | 0 docs/examples/std/nat/Nat.ch | 7 ++ docs/{ => examples}/std/nat/index.ch | 0 docs/examples/std/nat/numbers.ch | 14 ++++ docs/{ => examples}/std/nat/play.ch | 2 +- docs/{ => examples}/std/nat/play.ch.out | 0 docs/examples/std/trilean/Trilean.ch | 62 ++++++++++++++ .../{ => examples}/std/trilean/Trilean.ch.out | 0 .../tests/basic/assert-false.error.ch | 0 .../tests/basic/assert-false.error.ch.err | 0 .../tests/basic/assert-non-boolean.error.ch | 0 .../basic/assert-non-boolean.error.ch.err | 0 docs/{ => examples}/tests/basic/assert.ch | 0 docs/{ => examples}/tests/basic/compute.ch | 0 .../{ => examples}/tests/basic/compute.ch.out | 0 docs/{ => examples}/tests/basic/currying.ch | 0 .../tests/basic/currying.ch.out | 0 docs/{ => examples}/tests/basic/dot.ch | 0 .../tests/basic/function-print.ch | 0 .../tests/basic/function-print.ch.out | 0 .../tests/basic/function-with-clause.ch | 2 +- .../tests/basic/function-with-clause.ch.out | 0 .../tests/basic/function-with-early-return.ch | 0 .../basic/function-with-early-return.ch.out | 0 .../basic/function-with-return-expression.ch | 0 .../function-with-return-expression.ch.out | 0 .../tests/basic/function-with-return-null.ch | 0 .../basic/function-with-return-null.ch.out | 0 docs/{ => examples}/tests/basic/function.ch | 0 .../tests/basic/function.ch.out | 0 docs/{ => examples}/tests/basic/if-else-if.ch | 0 .../tests/basic/if-else-if.ch.out | 0 .../tests/basic/if-exp-without-else.ch | 0 .../tests/basic/if-exp-without-else.ch.out | 0 docs/{ => examples}/tests/basic/if-exp.ch | 0 docs/{ => examples}/tests/basic/if-exp.ch.out | 0 .../basic/if-non-boolean-target.error.ch | 0 .../basic/if-non-boolean-target.error.ch.err | 0 .../tests/basic/if-without-else.ch | 0 .../tests/basic/if-without-else.ch.out | 0 docs/{ => examples}/tests/basic/if.ch | 0 docs/{ => examples}/tests/basic/if.ch.out | 0 docs/{ => examples}/tests/basic/let.ch | 0 docs/{ => examples}/tests/basic/print.ch | 0 docs/{ => examples}/tests/basic/print.ch.out | 0 .../tests/constraints/not-equal.ch | 0 .../tests/constraints/not-equal.ch.out | 0 .../tests/constraints/number-types.ch | 0 .../tests/constraints/number-types.ch.out | 0 .../tests/constraints/string-types.ch | 0 .../tests/constraints/string-types.ch.out | 0 .../no-misused-variable-name.error.ch | 2 +- .../no-misused-variable-name.error.ch.err | 2 +- .../no-unused-variable-name.error.ch | 2 +- .../no-unused-variable-name.error.ch.err | 2 +- ...variable-name-can-starts-with-uppercase.ch | 0 ...able-name-can-starts-with-uppercase.ch.out | 0 .../conventions/preserved-name-false.error.ch | 0 .../preserved-name-false.error.ch.err | 0 .../conventions/preserved-name-null.error.ch | 0 .../preserved-name-null.error.ch.err | 0 .../conventions/preserved-name-true.error.ch | 0 .../preserved-name-true.error.ch.err | 0 .../relation-arity-mismatch.error.ch | 2 + .../relation-arity-mismatch.error.ch.err | 0 ...n-name-must-starts-with-uppercase.error.ch | 1 + ...me-must-starts-with-uppercase.error.ch.err | 14 ++++ docs/{ => examples}/tests/globals/boolean.ch | 0 .../tests/globals/boolean.ch.out | 0 docs/{ => examples}/tests/globals/equal.ch | 0 .../{ => examples}/tests/globals/equal.ch.out | 0 .../{ => examples}/tests/globals/not-equal.ch | 0 .../tests/globals/not-equal.ch.out | 0 .../tests/globals/null-shadowed.ch | 2 +- .../tests/globals/null-shadowed.ch.out | 0 docs/{ => examples}/tests/globals/null.ch | 0 docs/{ => examples}/tests/globals/null.ch.out | 0 .../goal-apply-too-many-arguments.error.ch | 0 ...goal-apply-too-many-arguments.error.ch.err | 0 docs/{ => examples}/tests/goal/goal.ch | 0 docs/{ => examples}/tests/goal/goal.ch.out | 0 docs/{ => examples}/tests/json/array.ch | 0 docs/{ => examples}/tests/json/array.ch.out | 0 docs/{ => examples}/tests/json/boolean.ch | 0 docs/{ => examples}/tests/json/boolean.ch.out | 0 docs/{ => examples}/tests/json/null.ch | 0 docs/{ => examples}/tests/json/null.ch.out | 0 docs/{ => examples}/tests/json/number.ch | 0 docs/{ => examples}/tests/json/number.ch.out | 0 docs/{ => examples}/tests/json/object.ch | 0 docs/{ => examples}/tests/json/object.ch.out | 0 docs/{ => examples}/tests/json/string.ch | 0 docs/{ => examples}/tests/json/string.ch.out | 0 docs/{ => examples}/tests/module/A.ch | 2 +- docs/{ => examples}/tests/module/A.ch.out | 0 docs/{ => examples}/tests/module/AB.ch | 2 +- docs/{ => examples}/tests/module/AB.ch.out | 0 docs/{ => examples}/tests/module/ABC.ch | 2 +- docs/{ => examples}/tests/module/ABC.ch.out | 0 docs/examples/tests/module/example.ch | 5 ++ .../tests/module/import-all-as.ch | 0 .../tests/module/import-all-as.ch.out | 0 .../tests/module/import-all-private.error.ch | 0 .../module/import-all-private.error.ch.err | 0 .../{ => examples}/tests/module/import-all.ch | 0 .../tests/module/import-all.ch.out | 0 .../tests/module/import-private.error.ch | 0 .../tests/module/import-private.error.ch.err | 0 .../module/imported-name-can-be-shadowed.ch | 2 +- .../imported-name-can-be-shadowed.ch.out | 0 .../object/construct-object-by-relation.ch | 2 +- .../construct-object-by-relation.ch.out | 0 .../object/merge-properties-to-object.ch | 0 .../object/merge-properties-to-object.ch.out | 0 docs/{ => examples}/tests/relation/conj.ch | 0 .../{ => examples}/tests/relation/conj.ch.out | 0 docs/examples/tests/relation/datom.ch | 9 ++ .../tests/relation/datom.ch.out | 0 docs/{ => examples}/tests/relation/disj.ch | 0 .../{ => examples}/tests/relation/disj.ch.out | 0 .../tests/relation/lookup-inline-disj.ch | 6 +- .../tests/relation/lookup-inline-disj.ch.out | 0 .../tests/relation/multiset-arithmetic.ch | 48 +++++------ .../tests/relation/multiset-arithmetic.ch.out | 0 .../tests/relation/sat-clause.ch | 34 ++++---- .../tests/relation/sat-clause.ch.out | 0 .../relation/sequencing-of-procedure-calls.ch | 35 ++++++++ .../sequencing-of-procedure-calls.ch.out | 0 docs/{ => examples}/tests/term/my-list.ch | 4 +- docs/{ => examples}/tests/term/my-list.ch.out | 0 .../tests/termination/always.ch | 4 +- .../tests/termination/always.ch.out | 0 .../tests/termination/append.ch | 8 +- .../tests/termination/append.ch.out | 0 docs/examples/tests/termination/never.ch | 23 +++++ .../tests/termination/never.ch.out | 0 .../tests/unification/infix-notation-equal.ch | 0 .../unification/infix-notation-equal.ch.out | 0 .../unification/infix-notation-not-equal.ch | 0 .../infix-notation-not-equal.ch.out | 0 .../tests/unification/occur-check.ch | 0 .../tests/unification/occur-check.ch.out | 0 docs/std/list/Append.ch | 6 -- docs/std/nat/Nat.ch | 7 -- docs/std/nat/numbers.ch | 14 ---- docs/std/trilean/Trilean.ch | 62 -------------- .../relation-arity-mismatch.error.ch | 2 - ...n-name-must-starts-with-uppercase.error.ch | 1 - ...me-must-starts-with-uppercase.error.ch.err | 14 ---- docs/tests/module/example.ch | 5 -- docs/tests/relation/datom.ch | 9 -- .../relation/sequencing-of-procedure-calls.ch | 35 -------- docs/tests/termination/never.ch | 23 ----- src/lang/globals/aboutBoolean.ts | 4 +- src/lang/globals/aboutNull.ts | 2 +- src/lang/syntax/grammars/stmt.ts | 8 +- src/test.ts | 4 +- 251 files changed, 511 insertions(+), 509 deletions(-) rename {archive => docs/archive}/tests/finite-domain/FiniteDomain.ch (100%) rename {archive => docs/archive}/tests/finite-domain/FiniteDomain.example.ch (100%) rename {archive => docs/archive}/tests/finite-domain/FiniteDomain.example.ch.out (100%) rename {archive => docs/archive}/tests/finite-domain/FiniteDomain.test.ch (100%) rename {archive => docs/archive}/tests/finite-domain/FiniteDomain.test.ch.out (100%) rename {archive => docs/archive}/tests/finite-domain/index.ch (100%) rename {archive => docs/archive}/tests/hyperrule.ch (100%) rename {archive => docs/archive}/tests/hyperrule.ch.out (100%) rename {archive => docs/archive}/tests/hyperrule/abc.ch (100%) rename {archive => docs/archive}/tests/hyperrule/abc.ch.out (100%) rename {archive => docs/archive}/tests/hyperrule/propagate-idempotent.ch (100%) rename {archive => docs/archive}/tests/hyperrule/propagate-idempotent.ch.out (100%) rename {archive => docs/archive}/tests/hyperrule/propagate-keep-the-input.ch (100%) rename {archive => docs/archive}/tests/hyperrule/propagate-keep-the-input.ch.out (100%) rename {archive => docs/archive}/tests/hyperrule/walk.ch (100%) rename {archive => docs/archive}/tests/hyperrule/walk.ch.out (100%) rename {archive => docs/archive}/tests/hyperrule/weather-hyperrule-list-as-exp.ch (100%) rename {archive => docs/archive}/tests/hyperrule/weather-hyperrule-list-as-exp.ch.out (100%) rename {archive => docs/archive}/tests/hyperrule/weather-include.ch (100%) rename {archive => docs/archive}/tests/hyperrule/weather-include.ch.out (100%) rename {archive => docs/archive}/tests/hyperrule/weather-with-guard.ch (100%) rename {archive => docs/archive}/tests/hyperrule/weather-with-guard.ch.out (100%) rename {archive => docs/archive}/tests/hyperrule/weather.ch (100%) rename {archive => docs/archive}/tests/hyperrule/weather.ch.out (100%) rename {archive => docs/archive}/tests/rule.ch (100%) rename {archive => docs/archive}/tests/rule.ch.out (100%) rename {archive => docs/archive}/tests/rule/arithmetic.ch (100%) rename {archive => docs/archive}/tests/rule/arithmetic.ch.out (100%) rename {archive => docs/archive}/tests/rule/combinatory-logic.ch (100%) rename {archive => docs/archive}/tests/rule/combinatory-logic.ch.out (100%) rename {archive => docs/archive}/tests/rule/conjunctive-normal-form.ch (100%) rename {archive => docs/archive}/tests/rule/conjunctive-normal-form.ch.out (100%) rename {archive => docs/archive}/tests/rule/rule-list-as-exp.ch (100%) rename {archive => docs/archive}/tests/rule/rule-list-as-exp.ch.out (100%) rename {archive => docs/archive}/tests/rule/same-pattern-variable.ch (100%) rename {archive => docs/archive}/tests/rule/same-pattern-variable.ch.out (100%) rename {archive => docs/archive}/tests/rule/with-guard.ch (100%) rename {archive => docs/archive}/tests/rule/with-guard.ch.out (100%) rename {archive => docs/archive}/tests/rule/with-include.ch (100%) rename {archive => docs/archive}/tests/rule/with-include.ch.out (100%) delete mode 100644 docs/books/clause-and-effect/03-affordable-journeys.ch delete mode 100644 docs/books/clause-and-effect/04-acyclic-directed-graph.ch rename docs/{ => examples}/books/clause-and-effect/01-party-pairs.ch (73%) rename docs/{ => examples}/books/clause-and-effect/01-party-pairs.ch.out (100%) rename docs/{ => examples}/books/clause-and-effect/02-drinking-pairs.ch (52%) rename docs/{ => examples}/books/clause-and-effect/02-drinking-pairs.ch.out (100%) create mode 100644 docs/examples/books/clause-and-effect/03-affordable-journeys.ch rename docs/{ => examples}/books/clause-and-effect/03-affordable-journeys.ch.out (100%) create mode 100644 docs/examples/books/clause-and-effect/04-acyclic-directed-graph.ch rename docs/{ => examples}/books/clause-and-effect/04-acyclic-directed-graph.ch.out (100%) rename docs/{ => examples}/books/clause-and-effect/05-member.ch (80%) rename docs/{ => examples}/books/clause-and-effect/05-member.ch.out (100%) rename docs/{ => examples}/books/clause-and-effect/06-length-of-a-list.ch (86%) rename docs/{ => examples}/books/clause-and-effect/08-maximum-of-a-list.ch (79%) rename docs/{ => examples}/books/clause-and-effect/09-searching-a-cyclic-graph.ch (61%) rename docs/{ => examples}/books/clause-and-effect/09-searching-a-cyclic-graph.ch.out (100%) rename docs/{ => examples}/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch (87%) rename docs/{ => examples}/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch.out (100%) rename docs/{ => examples}/books/structure-and-interpretation-of-computer-programs/logic-as-programs.md (92%) rename docs/{ => examples}/books/the-reasoned-schemer/01-playthings.ch (93%) rename docs/{ => examples}/books/the-reasoned-schemer/01-playthings.ch.out (100%) rename docs/{ => examples}/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch (91%) rename docs/{ => examples}/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch.out (100%) rename docs/{ => examples}/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch (87%) rename docs/{ => examples}/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch.out (100%) rename docs/{ => examples}/books/the-reasoned-schemer/04-double-your-fun.ch (93%) rename docs/{ => examples}/books/the-reasoned-schemer/04-double-your-fun.ch.out (100%) rename docs/{ => examples}/books/the-reasoned-schemer/05-members-only.ch (93%) rename docs/{ => examples}/books/the-reasoned-schemer/05-members-only.ch.out (100%) rename docs/{ => examples}/books/the-reasoned-schemer/06-the-fun-never-ends.ch (93%) rename docs/{ => examples}/books/the-reasoned-schemer/06-the-fun-never-ends.ch.out (100%) rename docs/{ => examples}/books/the-reasoned-schemer/07-a-bit-too-much.ch (73%) rename docs/{ => examples}/books/the-reasoned-schemer/07-a-bit-too-much.ch.out (100%) rename docs/{ => examples}/books/the-reasoned-schemer/08-just-a-bit-more.ch (63%) rename docs/{ => examples}/books/the-reasoned-schemer/08-just-a-bit-more.ch.out (100%) rename docs/{ => examples}/books/the-reasoned-schemer/09-thin-ice.ch (100%) rename docs/{ => examples}/books/the-reasoned-schemer/10-under-the-hood.ch (100%) rename docs/{ => examples}/langs/lambda-closure.ch (57%) rename docs/{ => examples}/langs/lambda-closure.ch.out (100%) rename docs/{ => examples}/langs/lambda-simple-type.ch (58%) rename docs/{ => examples}/langs/lambda-simple-type.ch.out (100%) create mode 100644 docs/examples/std/list/Append.ch rename docs/{ => examples}/std/list/Append.test.ch (100%) rename docs/{ => examples}/std/list/Append.test.ch.out (100%) rename docs/{ => examples}/std/list/Lookup.ch (79%) rename docs/{ => examples}/std/list/Lookup.test.ch (100%) rename docs/{ => examples}/std/list/Lookup.test.ch.out (100%) rename docs/{ => examples}/std/list/index.ch (100%) rename docs/{ => examples}/std/nat/Add.ch (57%) rename docs/{ => examples}/std/nat/Add.test.ch (100%) rename docs/{ => examples}/std/nat/Add.test.ch.out (100%) rename docs/{ => examples}/std/nat/Mul.ch (82%) rename docs/{ => examples}/std/nat/Mul.test.ch (100%) rename docs/{ => examples}/std/nat/Mul.test.ch.out (100%) create mode 100644 docs/examples/std/nat/Nat.ch rename docs/{ => examples}/std/nat/index.ch (100%) create mode 100644 docs/examples/std/nat/numbers.ch rename docs/{ => examples}/std/nat/play.ch (94%) rename docs/{ => examples}/std/nat/play.ch.out (100%) create mode 100644 docs/examples/std/trilean/Trilean.ch rename docs/{ => examples}/std/trilean/Trilean.ch.out (100%) rename docs/{ => examples}/tests/basic/assert-false.error.ch (100%) rename docs/{ => examples}/tests/basic/assert-false.error.ch.err (100%) rename docs/{ => examples}/tests/basic/assert-non-boolean.error.ch (100%) rename docs/{ => examples}/tests/basic/assert-non-boolean.error.ch.err (100%) rename docs/{ => examples}/tests/basic/assert.ch (100%) rename docs/{ => examples}/tests/basic/compute.ch (100%) rename docs/{ => examples}/tests/basic/compute.ch.out (100%) rename docs/{ => examples}/tests/basic/currying.ch (100%) rename docs/{ => examples}/tests/basic/currying.ch.out (100%) rename docs/{ => examples}/tests/basic/dot.ch (100%) rename docs/{ => examples}/tests/basic/function-print.ch (100%) rename docs/{ => examples}/tests/basic/function-print.ch.out (100%) rename docs/{ => examples}/tests/basic/function-with-clause.ch (91%) rename docs/{ => examples}/tests/basic/function-with-clause.ch.out (100%) rename docs/{ => examples}/tests/basic/function-with-early-return.ch (100%) rename docs/{ => examples}/tests/basic/function-with-early-return.ch.out (100%) rename docs/{ => examples}/tests/basic/function-with-return-expression.ch (100%) rename docs/{ => examples}/tests/basic/function-with-return-expression.ch.out (100%) rename docs/{ => examples}/tests/basic/function-with-return-null.ch (100%) rename docs/{ => examples}/tests/basic/function-with-return-null.ch.out (100%) rename docs/{ => examples}/tests/basic/function.ch (100%) rename docs/{ => examples}/tests/basic/function.ch.out (100%) rename docs/{ => examples}/tests/basic/if-else-if.ch (100%) rename docs/{ => examples}/tests/basic/if-else-if.ch.out (100%) rename docs/{ => examples}/tests/basic/if-exp-without-else.ch (100%) rename docs/{ => examples}/tests/basic/if-exp-without-else.ch.out (100%) rename docs/{ => examples}/tests/basic/if-exp.ch (100%) rename docs/{ => examples}/tests/basic/if-exp.ch.out (100%) rename docs/{ => examples}/tests/basic/if-non-boolean-target.error.ch (100%) rename docs/{ => examples}/tests/basic/if-non-boolean-target.error.ch.err (100%) rename docs/{ => examples}/tests/basic/if-without-else.ch (100%) rename docs/{ => examples}/tests/basic/if-without-else.ch.out (100%) rename docs/{ => examples}/tests/basic/if.ch (100%) rename docs/{ => examples}/tests/basic/if.ch.out (100%) rename docs/{ => examples}/tests/basic/let.ch (100%) rename docs/{ => examples}/tests/basic/print.ch (100%) rename docs/{ => examples}/tests/basic/print.ch.out (100%) rename docs/{ => examples}/tests/constraints/not-equal.ch (100%) rename docs/{ => examples}/tests/constraints/not-equal.ch.out (100%) rename docs/{ => examples}/tests/constraints/number-types.ch (100%) rename docs/{ => examples}/tests/constraints/number-types.ch.out (100%) rename docs/{ => examples}/tests/constraints/string-types.ch (100%) rename docs/{ => examples}/tests/constraints/string-types.ch.out (100%) rename docs/{ => examples}/tests/conventions/no-misused-variable-name.error.ch (64%) rename docs/{ => examples}/tests/conventions/no-misused-variable-name.error.ch.err (92%) rename docs/{ => examples}/tests/conventions/no-unused-variable-name.error.ch (64%) rename docs/{ => examples}/tests/conventions/no-unused-variable-name.error.ch.err (92%) rename docs/{ => examples}/tests/conventions/pattern-variable-name-can-starts-with-uppercase.ch (100%) rename docs/{ => examples}/tests/conventions/pattern-variable-name-can-starts-with-uppercase.ch.out (100%) rename docs/{ => examples}/tests/conventions/preserved-name-false.error.ch (100%) rename docs/{ => examples}/tests/conventions/preserved-name-false.error.ch.err (100%) rename docs/{ => examples}/tests/conventions/preserved-name-null.error.ch (100%) rename docs/{ => examples}/tests/conventions/preserved-name-null.error.ch.err (100%) rename docs/{ => examples}/tests/conventions/preserved-name-true.error.ch (100%) rename docs/{ => examples}/tests/conventions/preserved-name-true.error.ch.err (100%) create mode 100644 docs/examples/tests/conventions/relation-arity-mismatch.error.ch rename docs/{ => examples}/tests/conventions/relation-arity-mismatch.error.ch.err (100%) create mode 100644 docs/examples/tests/conventions/relation-name-must-starts-with-uppercase.error.ch create mode 100644 docs/examples/tests/conventions/relation-name-must-starts-with-uppercase.error.ch.err rename docs/{ => examples}/tests/globals/boolean.ch (100%) rename docs/{ => examples}/tests/globals/boolean.ch.out (100%) rename docs/{ => examples}/tests/globals/equal.ch (100%) rename docs/{ => examples}/tests/globals/equal.ch.out (100%) rename docs/{ => examples}/tests/globals/not-equal.ch (100%) rename docs/{ => examples}/tests/globals/not-equal.ch.out (100%) rename docs/{ => examples}/tests/globals/null-shadowed.ch (57%) rename docs/{ => examples}/tests/globals/null-shadowed.ch.out (100%) rename docs/{ => examples}/tests/globals/null.ch (100%) rename docs/{ => examples}/tests/globals/null.ch.out (100%) rename docs/{ => examples}/tests/goal/goal-apply-too-many-arguments.error.ch (100%) rename docs/{ => examples}/tests/goal/goal-apply-too-many-arguments.error.ch.err (100%) rename docs/{ => examples}/tests/goal/goal.ch (100%) rename docs/{ => examples}/tests/goal/goal.ch.out (100%) rename docs/{ => examples}/tests/json/array.ch (100%) rename docs/{ => examples}/tests/json/array.ch.out (100%) rename docs/{ => examples}/tests/json/boolean.ch (100%) rename docs/{ => examples}/tests/json/boolean.ch.out (100%) rename docs/{ => examples}/tests/json/null.ch (100%) rename docs/{ => examples}/tests/json/null.ch.out (100%) rename docs/{ => examples}/tests/json/number.ch (100%) rename docs/{ => examples}/tests/json/number.ch.out (100%) rename docs/{ => examples}/tests/json/object.ch (100%) rename docs/{ => examples}/tests/json/object.ch.out (100%) rename docs/{ => examples}/tests/json/string.ch (100%) rename docs/{ => examples}/tests/json/string.ch.out (100%) rename docs/{ => examples}/tests/module/A.ch (72%) rename docs/{ => examples}/tests/module/A.ch.out (100%) rename docs/{ => examples}/tests/module/AB.ch (80%) rename docs/{ => examples}/tests/module/AB.ch.out (100%) rename docs/{ => examples}/tests/module/ABC.ch (80%) rename docs/{ => examples}/tests/module/ABC.ch.out (100%) create mode 100644 docs/examples/tests/module/example.ch rename docs/{ => examples}/tests/module/import-all-as.ch (100%) rename docs/{ => examples}/tests/module/import-all-as.ch.out (100%) rename docs/{ => examples}/tests/module/import-all-private.error.ch (100%) rename docs/{ => examples}/tests/module/import-all-private.error.ch.err (100%) rename docs/{ => examples}/tests/module/import-all.ch (100%) rename docs/{ => examples}/tests/module/import-all.ch.out (100%) rename docs/{ => examples}/tests/module/import-private.error.ch (100%) rename docs/{ => examples}/tests/module/import-private.error.ch.err (100%) rename docs/{ => examples}/tests/module/imported-name-can-be-shadowed.ch (84%) rename docs/{ => examples}/tests/module/imported-name-can-be-shadowed.ch.out (100%) rename docs/{ => examples}/tests/object/construct-object-by-relation.ch (82%) rename docs/{ => examples}/tests/object/construct-object-by-relation.ch.out (100%) rename docs/{ => examples}/tests/object/merge-properties-to-object.ch (100%) rename docs/{ => examples}/tests/object/merge-properties-to-object.ch.out (100%) rename docs/{ => examples}/tests/relation/conj.ch (100%) rename docs/{ => examples}/tests/relation/conj.ch.out (100%) create mode 100644 docs/examples/tests/relation/datom.ch rename docs/{ => examples}/tests/relation/datom.ch.out (100%) rename docs/{ => examples}/tests/relation/disj.ch (100%) rename docs/{ => examples}/tests/relation/disj.ch.out (100%) rename docs/{ => examples}/tests/relation/lookup-inline-disj.ch (88%) rename docs/{ => examples}/tests/relation/lookup-inline-disj.ch.out (100%) rename docs/{ => examples}/tests/relation/multiset-arithmetic.ch (64%) rename docs/{ => examples}/tests/relation/multiset-arithmetic.ch.out (100%) rename docs/{ => examples}/tests/relation/sat-clause.ch (60%) rename docs/{ => examples}/tests/relation/sat-clause.ch.out (100%) create mode 100644 docs/examples/tests/relation/sequencing-of-procedure-calls.ch rename docs/{ => examples}/tests/relation/sequencing-of-procedure-calls.ch.out (100%) rename docs/{ => examples}/tests/term/my-list.ch (82%) rename docs/{ => examples}/tests/term/my-list.ch.out (100%) rename docs/{ => examples}/tests/termination/always.ch (95%) rename docs/{ => examples}/tests/termination/always.ch.out (100%) rename docs/{ => examples}/tests/termination/append.ch (84%) rename docs/{ => examples}/tests/termination/append.ch.out (100%) create mode 100644 docs/examples/tests/termination/never.ch rename docs/{ => examples}/tests/termination/never.ch.out (100%) rename docs/{ => examples}/tests/unification/infix-notation-equal.ch (100%) rename docs/{ => examples}/tests/unification/infix-notation-equal.ch.out (100%) rename docs/{ => examples}/tests/unification/infix-notation-not-equal.ch (100%) rename docs/{ => examples}/tests/unification/infix-notation-not-equal.ch.out (100%) rename docs/{ => examples}/tests/unification/occur-check.ch (100%) rename docs/{ => examples}/tests/unification/occur-check.ch.out (100%) delete mode 100644 docs/std/list/Append.ch delete mode 100644 docs/std/nat/Nat.ch delete mode 100644 docs/std/nat/numbers.ch delete mode 100644 docs/std/trilean/Trilean.ch delete mode 100644 docs/tests/conventions/relation-arity-mismatch.error.ch delete mode 100644 docs/tests/conventions/relation-name-must-starts-with-uppercase.error.ch delete mode 100644 docs/tests/conventions/relation-name-must-starts-with-uppercase.error.ch.err delete mode 100644 docs/tests/module/example.ch delete mode 100644 docs/tests/relation/datom.ch delete mode 100644 docs/tests/relation/sequencing-of-procedure-calls.ch delete mode 100644 docs/tests/termination/never.ch diff --git a/TODO.md b/TODO.md index ceec60d6..d6b7a35a 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,5 @@ +用 constraint programming 的知识来实现类型检查器。 + `Data` instead of `Term` -- only defined by `datatype` [maybe] remove eval diff --git a/archive/tests/finite-domain/FiniteDomain.ch b/docs/archive/tests/finite-domain/FiniteDomain.ch similarity index 100% rename from archive/tests/finite-domain/FiniteDomain.ch rename to docs/archive/tests/finite-domain/FiniteDomain.ch diff --git a/archive/tests/finite-domain/FiniteDomain.example.ch b/docs/archive/tests/finite-domain/FiniteDomain.example.ch similarity index 100% rename from archive/tests/finite-domain/FiniteDomain.example.ch rename to docs/archive/tests/finite-domain/FiniteDomain.example.ch diff --git a/archive/tests/finite-domain/FiniteDomain.example.ch.out b/docs/archive/tests/finite-domain/FiniteDomain.example.ch.out similarity index 100% rename from archive/tests/finite-domain/FiniteDomain.example.ch.out rename to docs/archive/tests/finite-domain/FiniteDomain.example.ch.out diff --git a/archive/tests/finite-domain/FiniteDomain.test.ch b/docs/archive/tests/finite-domain/FiniteDomain.test.ch similarity index 100% rename from archive/tests/finite-domain/FiniteDomain.test.ch rename to docs/archive/tests/finite-domain/FiniteDomain.test.ch diff --git a/archive/tests/finite-domain/FiniteDomain.test.ch.out b/docs/archive/tests/finite-domain/FiniteDomain.test.ch.out similarity index 100% rename from archive/tests/finite-domain/FiniteDomain.test.ch.out rename to docs/archive/tests/finite-domain/FiniteDomain.test.ch.out diff --git a/archive/tests/finite-domain/index.ch b/docs/archive/tests/finite-domain/index.ch similarity index 100% rename from archive/tests/finite-domain/index.ch rename to docs/archive/tests/finite-domain/index.ch diff --git a/archive/tests/hyperrule.ch b/docs/archive/tests/hyperrule.ch similarity index 100% rename from archive/tests/hyperrule.ch rename to docs/archive/tests/hyperrule.ch diff --git a/archive/tests/hyperrule.ch.out b/docs/archive/tests/hyperrule.ch.out similarity index 100% rename from archive/tests/hyperrule.ch.out rename to docs/archive/tests/hyperrule.ch.out diff --git a/archive/tests/hyperrule/abc.ch b/docs/archive/tests/hyperrule/abc.ch similarity index 100% rename from archive/tests/hyperrule/abc.ch rename to docs/archive/tests/hyperrule/abc.ch diff --git a/archive/tests/hyperrule/abc.ch.out b/docs/archive/tests/hyperrule/abc.ch.out similarity index 100% rename from archive/tests/hyperrule/abc.ch.out rename to docs/archive/tests/hyperrule/abc.ch.out diff --git a/archive/tests/hyperrule/propagate-idempotent.ch b/docs/archive/tests/hyperrule/propagate-idempotent.ch similarity index 100% rename from archive/tests/hyperrule/propagate-idempotent.ch rename to docs/archive/tests/hyperrule/propagate-idempotent.ch diff --git a/archive/tests/hyperrule/propagate-idempotent.ch.out b/docs/archive/tests/hyperrule/propagate-idempotent.ch.out similarity index 100% rename from archive/tests/hyperrule/propagate-idempotent.ch.out rename to docs/archive/tests/hyperrule/propagate-idempotent.ch.out diff --git a/archive/tests/hyperrule/propagate-keep-the-input.ch b/docs/archive/tests/hyperrule/propagate-keep-the-input.ch similarity index 100% rename from archive/tests/hyperrule/propagate-keep-the-input.ch rename to docs/archive/tests/hyperrule/propagate-keep-the-input.ch diff --git a/archive/tests/hyperrule/propagate-keep-the-input.ch.out b/docs/archive/tests/hyperrule/propagate-keep-the-input.ch.out similarity index 100% rename from archive/tests/hyperrule/propagate-keep-the-input.ch.out rename to docs/archive/tests/hyperrule/propagate-keep-the-input.ch.out diff --git a/archive/tests/hyperrule/walk.ch b/docs/archive/tests/hyperrule/walk.ch similarity index 100% rename from archive/tests/hyperrule/walk.ch rename to docs/archive/tests/hyperrule/walk.ch diff --git a/archive/tests/hyperrule/walk.ch.out b/docs/archive/tests/hyperrule/walk.ch.out similarity index 100% rename from archive/tests/hyperrule/walk.ch.out rename to docs/archive/tests/hyperrule/walk.ch.out diff --git a/archive/tests/hyperrule/weather-hyperrule-list-as-exp.ch b/docs/archive/tests/hyperrule/weather-hyperrule-list-as-exp.ch similarity index 100% rename from archive/tests/hyperrule/weather-hyperrule-list-as-exp.ch rename to docs/archive/tests/hyperrule/weather-hyperrule-list-as-exp.ch diff --git a/archive/tests/hyperrule/weather-hyperrule-list-as-exp.ch.out b/docs/archive/tests/hyperrule/weather-hyperrule-list-as-exp.ch.out similarity index 100% rename from archive/tests/hyperrule/weather-hyperrule-list-as-exp.ch.out rename to docs/archive/tests/hyperrule/weather-hyperrule-list-as-exp.ch.out diff --git a/archive/tests/hyperrule/weather-include.ch b/docs/archive/tests/hyperrule/weather-include.ch similarity index 100% rename from archive/tests/hyperrule/weather-include.ch rename to docs/archive/tests/hyperrule/weather-include.ch diff --git a/archive/tests/hyperrule/weather-include.ch.out b/docs/archive/tests/hyperrule/weather-include.ch.out similarity index 100% rename from archive/tests/hyperrule/weather-include.ch.out rename to docs/archive/tests/hyperrule/weather-include.ch.out diff --git a/archive/tests/hyperrule/weather-with-guard.ch b/docs/archive/tests/hyperrule/weather-with-guard.ch similarity index 100% rename from archive/tests/hyperrule/weather-with-guard.ch rename to docs/archive/tests/hyperrule/weather-with-guard.ch diff --git a/archive/tests/hyperrule/weather-with-guard.ch.out b/docs/archive/tests/hyperrule/weather-with-guard.ch.out similarity index 100% rename from archive/tests/hyperrule/weather-with-guard.ch.out rename to docs/archive/tests/hyperrule/weather-with-guard.ch.out diff --git a/archive/tests/hyperrule/weather.ch b/docs/archive/tests/hyperrule/weather.ch similarity index 100% rename from archive/tests/hyperrule/weather.ch rename to docs/archive/tests/hyperrule/weather.ch diff --git a/archive/tests/hyperrule/weather.ch.out b/docs/archive/tests/hyperrule/weather.ch.out similarity index 100% rename from archive/tests/hyperrule/weather.ch.out rename to docs/archive/tests/hyperrule/weather.ch.out diff --git a/archive/tests/rule.ch b/docs/archive/tests/rule.ch similarity index 100% rename from archive/tests/rule.ch rename to docs/archive/tests/rule.ch diff --git a/archive/tests/rule.ch.out b/docs/archive/tests/rule.ch.out similarity index 100% rename from archive/tests/rule.ch.out rename to docs/archive/tests/rule.ch.out diff --git a/archive/tests/rule/arithmetic.ch b/docs/archive/tests/rule/arithmetic.ch similarity index 100% rename from archive/tests/rule/arithmetic.ch rename to docs/archive/tests/rule/arithmetic.ch diff --git a/archive/tests/rule/arithmetic.ch.out b/docs/archive/tests/rule/arithmetic.ch.out similarity index 100% rename from archive/tests/rule/arithmetic.ch.out rename to docs/archive/tests/rule/arithmetic.ch.out diff --git a/archive/tests/rule/combinatory-logic.ch b/docs/archive/tests/rule/combinatory-logic.ch similarity index 100% rename from archive/tests/rule/combinatory-logic.ch rename to docs/archive/tests/rule/combinatory-logic.ch diff --git a/archive/tests/rule/combinatory-logic.ch.out b/docs/archive/tests/rule/combinatory-logic.ch.out similarity index 100% rename from archive/tests/rule/combinatory-logic.ch.out rename to docs/archive/tests/rule/combinatory-logic.ch.out diff --git a/archive/tests/rule/conjunctive-normal-form.ch b/docs/archive/tests/rule/conjunctive-normal-form.ch similarity index 100% rename from archive/tests/rule/conjunctive-normal-form.ch rename to docs/archive/tests/rule/conjunctive-normal-form.ch diff --git a/archive/tests/rule/conjunctive-normal-form.ch.out b/docs/archive/tests/rule/conjunctive-normal-form.ch.out similarity index 100% rename from archive/tests/rule/conjunctive-normal-form.ch.out rename to docs/archive/tests/rule/conjunctive-normal-form.ch.out diff --git a/archive/tests/rule/rule-list-as-exp.ch b/docs/archive/tests/rule/rule-list-as-exp.ch similarity index 100% rename from archive/tests/rule/rule-list-as-exp.ch rename to docs/archive/tests/rule/rule-list-as-exp.ch diff --git a/archive/tests/rule/rule-list-as-exp.ch.out b/docs/archive/tests/rule/rule-list-as-exp.ch.out similarity index 100% rename from archive/tests/rule/rule-list-as-exp.ch.out rename to docs/archive/tests/rule/rule-list-as-exp.ch.out diff --git a/archive/tests/rule/same-pattern-variable.ch b/docs/archive/tests/rule/same-pattern-variable.ch similarity index 100% rename from archive/tests/rule/same-pattern-variable.ch rename to docs/archive/tests/rule/same-pattern-variable.ch diff --git a/archive/tests/rule/same-pattern-variable.ch.out b/docs/archive/tests/rule/same-pattern-variable.ch.out similarity index 100% rename from archive/tests/rule/same-pattern-variable.ch.out rename to docs/archive/tests/rule/same-pattern-variable.ch.out diff --git a/archive/tests/rule/with-guard.ch b/docs/archive/tests/rule/with-guard.ch similarity index 100% rename from archive/tests/rule/with-guard.ch rename to docs/archive/tests/rule/with-guard.ch diff --git a/archive/tests/rule/with-guard.ch.out b/docs/archive/tests/rule/with-guard.ch.out similarity index 100% rename from archive/tests/rule/with-guard.ch.out rename to docs/archive/tests/rule/with-guard.ch.out diff --git a/archive/tests/rule/with-include.ch b/docs/archive/tests/rule/with-include.ch similarity index 100% rename from archive/tests/rule/with-include.ch rename to docs/archive/tests/rule/with-include.ch diff --git a/archive/tests/rule/with-include.ch.out b/docs/archive/tests/rule/with-include.ch.out similarity index 100% rename from archive/tests/rule/with-include.ch.out rename to docs/archive/tests/rule/with-include.ch.out diff --git a/docs/books/clause-and-effect/03-affordable-journeys.ch b/docs/books/clause-and-effect/03-affordable-journeys.ch deleted file mode 100644 index b92cad06..00000000 --- a/docs/books/clause-and-effect/03-affordable-journeys.ch +++ /dev/null @@ -1,37 +0,0 @@ -clause Border("sussex", "kent") -clause Border("sussex", "surrey") -clause Border("surrey", "kent") -clause Border("hampshire", "sussex") -clause Border("hampshire", "surrey") -clause Border("hampshire", "berkshire") -clause Border("berkshire", "surrey") -clause Border("wiltshire", "hampshire") -clause Border("wiltshire", "berkshire") - -clause Adjacent(x, y) ----------------- border { - Border(x, y) -} - -clause Adjacent(x, y) ----------------- symmetry { - Border(y, x) -} - -clause Affordable(x, y) --------------------- { - Adjacent(x, z) - Adjacent(z, y) -} - -print find to_kent { - Affordable(to_kent, "kent") -} - -print find to_sussex { - Affordable("sussex", to_sussex) -} - -print find [x, y] { - Affordable(x, y) -} diff --git a/docs/books/clause-and-effect/04-acyclic-directed-graph.ch b/docs/books/clause-and-effect/04-acyclic-directed-graph.ch deleted file mode 100644 index 64c70cfd..00000000 --- a/docs/books/clause-and-effect/04-acyclic-directed-graph.ch +++ /dev/null @@ -1,31 +0,0 @@ -clause Edge("g", "h") -clause Edge("g", "d") -clause Edge("e", "d") -clause Edge("h", "f") -clause Edge("e", "f") -clause Edge("a", "e") -clause Edge("a", "b") -clause Edge("b", "f") -clause Edge("b", "c") -clause Edge("f", "c") - -clause Path(x, x) ------------- {} - -clause Path(x, y) ------------- { - Edge(x, z) - Path(z, y) -} - -print find x { - Path("g", x) -} - -print find x { - Path(x, "h") -} - -print find [x, y] { - Path(x, y) -} diff --git a/docs/books/clause-and-effect/01-party-pairs.ch b/docs/examples/books/clause-and-effect/01-party-pairs.ch similarity index 73% rename from docs/books/clause-and-effect/01-party-pairs.ch rename to docs/examples/books/clause-and-effect/01-party-pairs.ch index 140d0ef9..3ecdae13 100644 --- a/docs/books/clause-and-effect/01-party-pairs.ch +++ b/docs/examples/books/clause-and-effect/01-party-pairs.ch @@ -1,10 +1,10 @@ -clause Male({ name: "bertram" }) -clause Male({ name: "percival" }) +relation Male({ name: "bertram" }) +relation Male({ name: "percival" }) -clause Female({ name: "lucinda" }) -clause Female({ name: "camilla" }) +relation Female({ name: "lucinda" }) +relation Female({ name: "camilla" }) -clause Pair({ male, female }) -- { +relation Pair({ male, female }) -- { Male({ name: male }) Female({ name: female }) } diff --git a/docs/books/clause-and-effect/01-party-pairs.ch.out b/docs/examples/books/clause-and-effect/01-party-pairs.ch.out similarity index 100% rename from docs/books/clause-and-effect/01-party-pairs.ch.out rename to docs/examples/books/clause-and-effect/01-party-pairs.ch.out diff --git a/docs/books/clause-and-effect/02-drinking-pairs.ch b/docs/examples/books/clause-and-effect/02-drinking-pairs.ch similarity index 52% rename from docs/books/clause-and-effect/02-drinking-pairs.ch rename to docs/examples/books/clause-and-effect/02-drinking-pairs.ch index c7e150b6..40325c2a 100644 --- a/docs/books/clause-and-effect/02-drinking-pairs.ch +++ b/docs/examples/books/clause-and-effect/02-drinking-pairs.ch @@ -1,11 +1,11 @@ -clause Drink({ person: "john", alcohol: "martini" }) -clause Drink({ person: "mary", alcohol: "gin" }) -clause Drink({ person: "susan", alcohol: "vodka" }) -clause Drink({ person: "john", alcohol: "gin" }) -clause Drink({ person: "fred", alcohol: "gin" }) -clause Drink({ person: "fred", alcohol: "vodka" }) +relation Drink({ person: "john", alcohol: "martini" }) +relation Drink({ person: "mary", alcohol: "gin" }) +relation Drink({ person: "susan", alcohol: "vodka" }) +relation Drink({ person: "john", alcohol: "gin" }) +relation Drink({ person: "fred", alcohol: "gin" }) +relation Drink({ person: "fred", alcohol: "vodka" }) -clause Friendship({ left, right, alcohol }) +relation Friendship({ left, right, alcohol }) ------------------------------------ { Drink({ person: left, alcohol }) Drink({ person: right, alcohol }) diff --git a/docs/books/clause-and-effect/02-drinking-pairs.ch.out b/docs/examples/books/clause-and-effect/02-drinking-pairs.ch.out similarity index 100% rename from docs/books/clause-and-effect/02-drinking-pairs.ch.out rename to docs/examples/books/clause-and-effect/02-drinking-pairs.ch.out diff --git a/docs/examples/books/clause-and-effect/03-affordable-journeys.ch b/docs/examples/books/clause-and-effect/03-affordable-journeys.ch new file mode 100644 index 00000000..32bbcafd --- /dev/null +++ b/docs/examples/books/clause-and-effect/03-affordable-journeys.ch @@ -0,0 +1,37 @@ +relation Border("sussex", "kent") +relation Border("sussex", "surrey") +relation Border("surrey", "kent") +relation Border("hampshire", "sussex") +relation Border("hampshire", "surrey") +relation Border("hampshire", "berkshire") +relation Border("berkshire", "surrey") +relation Border("wiltshire", "hampshire") +relation Border("wiltshire", "berkshire") + +relation Adjacent(x, y) +---------------- border { + Border(x, y) +} + +relation Adjacent(x, y) +---------------- symmetry { + Border(y, x) +} + +relation Affordable(x, y) +-------------------- { + Adjacent(x, z) + Adjacent(z, y) +} + +print find to_kent { + Affordable(to_kent, "kent") +} + +print find to_sussex { + Affordable("sussex", to_sussex) +} + +print find [x, y] { + Affordable(x, y) +} diff --git a/docs/books/clause-and-effect/03-affordable-journeys.ch.out b/docs/examples/books/clause-and-effect/03-affordable-journeys.ch.out similarity index 100% rename from docs/books/clause-and-effect/03-affordable-journeys.ch.out rename to docs/examples/books/clause-and-effect/03-affordable-journeys.ch.out diff --git a/docs/examples/books/clause-and-effect/04-acyclic-directed-graph.ch b/docs/examples/books/clause-and-effect/04-acyclic-directed-graph.ch new file mode 100644 index 00000000..b8f30eba --- /dev/null +++ b/docs/examples/books/clause-and-effect/04-acyclic-directed-graph.ch @@ -0,0 +1,31 @@ +relation Edge("g", "h") +relation Edge("g", "d") +relation Edge("e", "d") +relation Edge("h", "f") +relation Edge("e", "f") +relation Edge("a", "e") +relation Edge("a", "b") +relation Edge("b", "f") +relation Edge("b", "c") +relation Edge("f", "c") + +relation Path(x, x) +------------ {} + +relation Path(x, y) +------------ { + Edge(x, z) + Path(z, y) +} + +print find x { + Path("g", x) +} + +print find x { + Path(x, "h") +} + +print find [x, y] { + Path(x, y) +} diff --git a/docs/books/clause-and-effect/04-acyclic-directed-graph.ch.out b/docs/examples/books/clause-and-effect/04-acyclic-directed-graph.ch.out similarity index 100% rename from docs/books/clause-and-effect/04-acyclic-directed-graph.ch.out rename to docs/examples/books/clause-and-effect/04-acyclic-directed-graph.ch.out diff --git a/docs/books/clause-and-effect/05-member.ch b/docs/examples/books/clause-and-effect/05-member.ch similarity index 80% rename from docs/books/clause-and-effect/05-member.ch rename to docs/examples/books/clause-and-effect/05-member.ch index c8a24971..0442c9bc 100644 --- a/docs/books/clause-and-effect/05-member.ch +++ b/docs/examples/books/clause-and-effect/05-member.ch @@ -1,7 +1,7 @@ -clause Member(element, [element | _tail]) +relation Member(element, [element | _tail]) ------------------------------------ here {} -clause Member(element, [_head | tail]) +relation Member(element, [_head | tail]) --------------------------------- there { Member(element, tail) } diff --git a/docs/books/clause-and-effect/05-member.ch.out b/docs/examples/books/clause-and-effect/05-member.ch.out similarity index 100% rename from docs/books/clause-and-effect/05-member.ch.out rename to docs/examples/books/clause-and-effect/05-member.ch.out diff --git a/docs/books/clause-and-effect/06-length-of-a-list.ch b/docs/examples/books/clause-and-effect/06-length-of-a-list.ch similarity index 86% rename from docs/books/clause-and-effect/06-length-of-a-list.ch rename to docs/examples/books/clause-and-effect/06-length-of-a-list.ch index 8d648e02..5ea77f4e 100644 --- a/docs/books/clause-and-effect/06-length-of-a-list.ch +++ b/docs/examples/books/clause-and-effect/06-length-of-a-list.ch @@ -1,11 +1,11 @@ import { Zero, Add1, One, Two } from "../../std/nat/index.ch" -clause Length([], n) +relation Length([], n) -------------------- { Zero(n) } -clause Length([_head | tail], n) +relation Length([_head | tail], n) -------------------------------- { Add1(prev, n) Length(tail, prev) diff --git a/docs/books/clause-and-effect/08-maximum-of-a-list.ch b/docs/examples/books/clause-and-effect/08-maximum-of-a-list.ch similarity index 79% rename from docs/books/clause-and-effect/08-maximum-of-a-list.ch rename to docs/examples/books/clause-and-effect/08-maximum-of-a-list.ch index 9f019280..0e3accdc 100644 --- a/docs/books/clause-and-effect/08-maximum-of-a-list.ch +++ b/docs/examples/books/clause-and-effect/08-maximum-of-a-list.ch @@ -1,13 +1,13 @@ -// clause Max(null, n, n) +// relation Max(null, n, n) // ---------------- {} -// clause Max(cons(x, rest), n, max) +// relation Max(cons(x, rest), n, max) // ---------------------------- { // Max(rest, x, max) // x > n // } -// clause Max(cons (x, rest), n, max) +// relation Max(cons (x, rest), n, max) // ---------------------------- { // Max(rest, n, max) // x <= n diff --git a/docs/books/clause-and-effect/09-searching-a-cyclic-graph.ch b/docs/examples/books/clause-and-effect/09-searching-a-cyclic-graph.ch similarity index 61% rename from docs/books/clause-and-effect/09-searching-a-cyclic-graph.ch rename to docs/examples/books/clause-and-effect/09-searching-a-cyclic-graph.ch index 15e389b6..b680311c 100644 --- a/docs/books/clause-and-effect/09-searching-a-cyclic-graph.ch +++ b/docs/examples/books/clause-and-effect/09-searching-a-cyclic-graph.ch @@ -1,30 +1,30 @@ -clause Edge("g", "h") -clause Edge("d", "a") -clause Edge("g", "d") -clause Edge("e", "d") -clause Edge("h", "f") -clause Edge("e", "f") -clause Edge("a", "e") -clause Edge("a", "b") -clause Edge("b", "f") -clause Edge("b", "c") -clause Edge("f", "c") +relation Edge("g", "h") +relation Edge("d", "a") +relation Edge("g", "d") +relation Edge("e", "d") +relation Edge("h", "f") +relation Edge("e", "f") +relation Edge("a", "e") +relation Edge("a", "b") +relation Edge("b", "f") +relation Edge("b", "c") +relation Edge("f", "c") // "a", "e", "d" -- in a loop // We define `Legal` to rule out loop -- to avoid searching in a loop -clause Legal(_, []) +relation Legal(_, []) -clause Legal(z, [head | tail]) +relation Legal(z, [head | tail]) ---------------------------- { NotEqual(z, head) Legal(z, tail) } -clause Path(x, x, _occurs) +relation Path(x, x, _occurs) -clause Path(x, y, occurs) +relation Path(x, y, occurs) ------------------------ { Edge(x, z) Legal(z, occurs) diff --git a/docs/books/clause-and-effect/09-searching-a-cyclic-graph.ch.out b/docs/examples/books/clause-and-effect/09-searching-a-cyclic-graph.ch.out similarity index 100% rename from docs/books/clause-and-effect/09-searching-a-cyclic-graph.ch.out rename to docs/examples/books/clause-and-effect/09-searching-a-cyclic-graph.ch.out diff --git a/docs/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch b/docs/examples/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch similarity index 87% rename from docs/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch rename to docs/examples/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch index 29639b4a..e28b7bba 100644 --- a/docs/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch +++ b/docs/examples/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch @@ -10,18 +10,18 @@ // Here is the information about Ben Bitdiddle, // the resident computer wizard: -clause Job({ +relation Job({ name: "Bitdiddle Ben", dept: "computer", role: "wizard", }) -clause Salary({ +relation Salary({ name: "Bitdiddle Ben", amount: 60000, }) -clause Address({ +relation Address({ name: "Bitdiddle Ben", town: "Slumerville", road: "Ridge Road", @@ -34,71 +34,71 @@ clause Address({ // Here is the information about them: -clause Address({ +relation Address({ name: "Hacker Alyssa P", town: "Cambridge", road: "Mass Ave", door: 78, }) -clause Job({ +relation Job({ name: "Hacker Alyssa P", dept: "computer", role: "programmer", }) -clause Salary({ +relation Salary({ name: "Hacker Alyssa P", amount: 40000, }) -clause Supervisor({ +relation Supervisor({ slave: "Hacker Alyssa P", master: "Bitdiddle Ben", }) -clause Address({ +relation Address({ name: "Fect Cy D", town: "Cambridge", road: "Ames Street", door: 3, }) -clause Job({ +relation Job({ name: "Fect Cy D", dept: "computer", role: "programmer", }) -clause Salary({ +relation Salary({ name: "Fect Cy D", amount: 35000, }) -clause Supervisor({ +relation Supervisor({ slave: "Fect Cy D", master: "Bitdiddle Ben", }) -clause Address({ +relation Address({ name: "Tweakit Lem E", town: "Boston", road: "Bay State Road", door: 22, }) -clause Job({ +relation Job({ name: "Tweakit Lem E", dept: "computer", role: "technician", }) -clause Salary({ +relation Salary({ name: "Tweakit Lem E", amount: 25000, }) -clause Supervisor({ +relation Supervisor({ slave: "Tweakit Lem E", master: "Bitdiddle Ben", }) @@ -106,25 +106,25 @@ clause Supervisor({ // There is also a programmer trainee, // who is supervised by Alyssa: -clause Address({ +relation Address({ name: "Reasoner Louis", town: "Slumerville", road: "Pine Tree Road", door: 80, }) -clause Job({ +relation Job({ name: "Reasoner Louis", dept: "computer", role: "programmer trainee", }) -clause Salary({ +relation Salary({ name: "Reasoner Louis", amount: 30000, }) -clause Supervisor({ +relation Supervisor({ slave: "Reasoner Louis", master: "Hacker Alyssa P", }) @@ -132,25 +132,25 @@ clause Supervisor({ // Ben is a high-level employee. // His supervisor is the company's big wheel himself: -clause Supervisor({ +relation Supervisor({ slave: "Bitdiddle Ben", master: "Warbucks Oliver", }) -clause Address({ +relation Address({ name: "Warbucks Oliver", town: "Swellesley", road: "The Manor", door: 1, }) -clause Job({ +relation Job({ name: "Warbucks Oliver", dept: "administration", role: "big wheel", }) -clause Salary({ +relation Salary({ name: "Warbucks Oliver", amount: 150000, }) @@ -159,73 +159,73 @@ clause Salary({ // the company has an accounting division, // consisting of a chief accountant and his assistant: -clause Address({ +relation Address({ name: "Scrooge Eben", town: "Weston", road: "Shady Lane", door: 10, }) -clause Job({ +relation Job({ name: "Scrooge Eben", dept: "accounting", role: "chief accountant", }) -clause Salary({ +relation Salary({ name: "Scrooge Eben", amount: 75000, }) -clause Supervisor({ +relation Supervisor({ slave: "Scrooge Eben", master: "Warbucks Oliver", }) -clause Address({ +relation Address({ name: "Cratchet Robert", town: "Allston", road: "N Harvard Street", door: 16, }) -clause Job({ +relation Job({ name: "Cratchet Robert", dept: "accounting", role: "scrivener", }) -clause Salary({ +relation Salary({ name: "Cratchet Robert", amount: 18000, }) -clause Supervisor({ +relation Supervisor({ slave: "Cratchet Robert", master: "Scrooge Eben", }) // There is also a secretary for the big wheel: -clause Address({ +relation Address({ name: "Aull DeWitt", town: "Slumerville", road: "Onion Square", door: 5, }) -clause Job({ +relation Job({ name: "Aull DeWitt", dept: "administration", role: "secretary", }) -clause Salary({ +relation Salary({ name: "Aull DeWitt", amount: 25000, }) -clause Supervisor({ +relation Supervisor({ slave: "Aull DeWitt", master: "Warbucks Oliver", }) @@ -238,7 +238,7 @@ clause Supervisor({ // the jobs of both a computer programmer // and a computer technician: -clause Competence({ +relation Competence({ can: { dept: "computer", role: "wizard", @@ -249,7 +249,7 @@ clause Competence({ }, }) -clause Competence({ +relation Competence({ can: { dept: "computer", role: "wizard", @@ -262,7 +262,7 @@ clause Competence({ // A computer programmer could fill in for a trainee: -clause Competence({ +relation Competence({ can: { dept: "computer", role: "programmer", @@ -275,7 +275,7 @@ clause Competence({ // Also, as is well known, -clause Competence({ +relation Competence({ can: { dept: "administration", role: "secretary", @@ -350,7 +350,7 @@ print find x { // We can use the following syntax to create rules. -clause ComputerDeptSlave({ slave }) +relation ComputerDeptSlave({ slave }) ---------------------------- { Job({ name: slave, dept: "computer" }) Supervisor({ slave }) @@ -362,7 +362,7 @@ print find slave { // TODO We do not have `not` yet. -// clause Bigshot({ name, dept }) +// relation Bigshot({ name, dept }) // ------------------------ { // Job({ name, dept }) // not { @@ -380,7 +380,7 @@ print find slave { // TODO `>=` -// clause NotSoPoor({ name, amount }) +// relation NotSoPoor({ name, amount }) // ---------------------------- { // Salary({ name, amount }) // FD::GtEq(amount, 40000) diff --git a/docs/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch.out b/docs/examples/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch.out similarity index 100% rename from docs/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch.out rename to docs/examples/books/structure-and-interpretation-of-computer-programs/a-boston-high-tech-company.ch.out diff --git a/docs/books/structure-and-interpretation-of-computer-programs/logic-as-programs.md b/docs/examples/books/structure-and-interpretation-of-computer-programs/logic-as-programs.md similarity index 92% rename from docs/books/structure-and-interpretation-of-computer-programs/logic-as-programs.md rename to docs/examples/books/structure-and-interpretation-of-computer-programs/logic-as-programs.md index a2a40f9c..1d7fa3bc 100644 --- a/docs/books/structure-and-interpretation-of-computer-programs/logic-as-programs.md +++ b/docs/examples/books/structure-and-interpretation-of-computer-programs/logic-as-programs.md @@ -31,10 +31,10 @@ cons(1, cons(2, cons(3, cons(4, null)))) **Relation:** ```ch -clause Append([], right, right) +relation Append([], right, right) ---------------------------- {} -clause Append( +relation Append( [head | left_tail], right, [head | result_tail], @@ -87,13 +87,13 @@ cons(1, cons(2, cons(3, cons(4, null)))) **Relation:** ```ch todo -clause Merge(null, right, right) +relation Merge(null, right, right) ------------------------ {} -clause Merge(left, null, left) +relation Merge(left, null, left) ------------------------ {} -clause Merge( +relation Merge( [left_head | left_tail], [head | right_tail], [head | result_tail], @@ -103,7 +103,7 @@ clause Merge( FD::Gt(left_head, head) } -clause Merge( +relation Merge( [head | left_tail], [right_head | right_tail], [head | result_tail], diff --git a/docs/books/the-reasoned-schemer/01-playthings.ch b/docs/examples/books/the-reasoned-schemer/01-playthings.ch similarity index 93% rename from docs/books/the-reasoned-schemer/01-playthings.ch rename to docs/examples/books/the-reasoned-schemer/01-playthings.ch index 8e209be3..52a96cf5 100644 --- a/docs/books/the-reasoned-schemer/01-playthings.ch +++ b/docs/examples/books/the-reasoned-schemer/01-playthings.ch @@ -1,6 +1,6 @@ -export clause Succeed() +export relation Succeed() -export clause Fail() +export relation Fail() -------- { Equal(1, 2) } @@ -107,12 +107,12 @@ print find q { Equal("corn", q) } -clause Teacup(t) +relation Teacup(t) --------------- tea { Equal(t, "tea") } -clause Teacup(t) +relation Teacup(t) --------------- cup { Equal(t, "cup") } diff --git a/docs/books/the-reasoned-schemer/01-playthings.ch.out b/docs/examples/books/the-reasoned-schemer/01-playthings.ch.out similarity index 100% rename from docs/books/the-reasoned-schemer/01-playthings.ch.out rename to docs/examples/books/the-reasoned-schemer/01-playthings.ch.out diff --git a/docs/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch b/docs/examples/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch similarity index 91% rename from docs/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch rename to docs/examples/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch index af639a56..4260f54b 100644 --- a/docs/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch +++ b/docs/examples/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch @@ -1,4 +1,4 @@ -export clause Car(p, a) +export relation Car(p, a) ---------- { Equal([a | _d], p) } @@ -22,7 +22,7 @@ print find r { Equal([x | y], r) } -export clause Cdr(p, d) +export relation Cdr(p, d) ---------- { Equal([_a | d], p) } @@ -53,12 +53,12 @@ print find l { Equal(x, "a") } -// clause Cons(a, d, p) +// relation Cons(a, d, p) // --------------- { // Equal([a | d], p) // } -export clause Cons(a, d, p) +export relation Cons(a, d, p) --------------- { Car(p, a) Cdr(p, d) @@ -101,7 +101,7 @@ print find l { Equal("o", y) } -export clause Null(x) +export relation Null(x) ---------- { Equal([], x) } @@ -122,7 +122,7 @@ print find r { Equal([_x, _y, "salad"], r) } -clause Pair(p) +relation Pair(p) ------ { Cons(_a, _d, p) } @@ -147,14 +147,14 @@ print find r { Pair([r]) } -// clause Singleton(l) +// relation Singleton(l) // ----------- { // Pair(l) // Cdr(l, d) // Null(d) // } -clause Singleton(l) +relation Singleton(l) ----------- { Cdr(l, d) Null(d) diff --git a/docs/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch.out b/docs/examples/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch.out similarity index 100% rename from docs/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch.out rename to docs/examples/books/the-reasoned-schemer/02-teaching-old-toys-new-tricks.ch.out diff --git a/docs/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch b/docs/examples/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch similarity index 87% rename from docs/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch rename to docs/examples/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch index af155e60..c904e181 100644 --- a/docs/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch +++ b/docs/examples/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch @@ -1,12 +1,12 @@ import { Succeed, Fail } from "01-playthings.ch" import { Null, Cons, Car, Cdr } from "02-teaching-old-toys-new-tricks.ch" -clause List(l) +relation List(l) ----------- { Null(l) } -clause List(l) +relation List(l) ------------- { Cdr(l, d) List(d) @@ -24,12 +24,12 @@ print find x limit 5 { List(["a", "b" | x]) } -clause ListOfLists(l) +relation ListOfLists(l) ------------- { Null(l) } -clause ListOfLists(l) +relation ListOfLists(l) ------------- { Car(l, a) List(a) @@ -57,17 +57,17 @@ print find x limit 5 { ListOfLists([["a", "b"], ["c", "d"] | x]) } -clause Singleton(l) +relation Singleton(l) ----------- { Equal(l, [_]) } -clause ListOfSingletons(l) +relation ListOfSingletons(l) ------------------- { Null(l) } -clause ListOfSingletons(l) +relation ListOfSingletons(l) -------------------- { Car(l, a) Singleton(a) @@ -95,24 +95,24 @@ print find out limit 5 { // NOTE By "The Law of Fail", we can drop the following clause. -// clause Member(x, l) +// relation Member(x, l) // ------------- { // Null(l) // Fail() // } -// clause Member(x, l) +// relation Member(x, l) // ------------- { // Car(l, a) // Equal(x, a) // } -clause Member(x, l) +relation Member(x, l) ------------- { Car(l, x) } -clause Member(x, l) +relation Member(x, l) ------------- { Cdr(l, d) Member(x, d) @@ -159,14 +159,14 @@ print find l limit 5 { Member("tofu", l) } -clause ProperMember(x, l) +relation ProperMember(x, l) ------------------- { Car(l, x) Cdr(l, d) List(d) } -clause ProperMember(x, l) +relation ProperMember(x, l) ------------------- { Cdr(l, d) ProperMember(x, d) diff --git a/docs/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch.out b/docs/examples/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch.out similarity index 100% rename from docs/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch.out rename to docs/examples/books/the-reasoned-schemer/03-seeing-old-friends-in-new-ways.ch.out diff --git a/docs/books/the-reasoned-schemer/04-double-your-fun.ch b/docs/examples/books/the-reasoned-schemer/04-double-your-fun.ch similarity index 93% rename from docs/books/the-reasoned-schemer/04-double-your-fun.ch rename to docs/examples/books/the-reasoned-schemer/04-double-your-fun.ch index b35571c5..00c31631 100644 --- a/docs/books/the-reasoned-schemer/04-double-your-fun.ch +++ b/docs/examples/books/the-reasoned-schemer/04-double-your-fun.ch @@ -1,12 +1,12 @@ import { Null, Cons, Car, Cdr } from "02-teaching-old-toys-new-tricks.ch" -clause Append(l, t, out) +relation Append(l, t, out) ------------------ { Null(l) Equal(out, t) } -clause Append(l, t, out) +relation Append(l, t, out) ------------------ { Cdr(l, d) Append(d, t, res) @@ -110,13 +110,13 @@ print find [x, y] limit 6 { ) } -clause Unwrap(x, out) +relation Unwrap(x, out) --------------- { Car(x, a) Unwrap(a, out) } -clause Unwrap(x, out) +relation Unwrap(x, out) --------------- { Equal(x, out) } diff --git a/docs/books/the-reasoned-schemer/04-double-your-fun.ch.out b/docs/examples/books/the-reasoned-schemer/04-double-your-fun.ch.out similarity index 100% rename from docs/books/the-reasoned-schemer/04-double-your-fun.ch.out rename to docs/examples/books/the-reasoned-schemer/04-double-your-fun.ch.out diff --git a/docs/books/the-reasoned-schemer/05-members-only.ch b/docs/examples/books/the-reasoned-schemer/05-members-only.ch similarity index 93% rename from docs/books/the-reasoned-schemer/05-members-only.ch rename to docs/examples/books/the-reasoned-schemer/05-members-only.ch index e4e3a3ad..69cd03b2 100644 --- a/docs/books/the-reasoned-schemer/05-members-only.ch +++ b/docs/examples/books/the-reasoned-schemer/05-members-only.ch @@ -1,12 +1,12 @@ import { Null, Cons, Car, Cdr } from "02-teaching-old-toys-new-tricks.ch" -clause Mem(x, l, out) +relation Mem(x, l, out) --------------- { Car(l, x) Equal(out, l) } -clause Mem(x, l, out) +relation Mem(x, l, out) --------------- { Cdr(l, d) Mem(x, d, out) @@ -68,19 +68,19 @@ print find [x, y] limit 5 { Mem("fig", ["fig", "d", "fig", "e" | y], x) } -clause Rember(_x, l, out) +relation Rember(_x, l, out) ------------------ { Null(l) Null(out) } -clause Rember(x, l, out) +relation Rember(x, l, out) ------------------ { Car(l, x) Cdr(l, out) } -clause Rember(x, l, out) +relation Rember(x, l, out) ------------------ { Cdr(l, d) Rember(x, d, res) diff --git a/docs/books/the-reasoned-schemer/05-members-only.ch.out b/docs/examples/books/the-reasoned-schemer/05-members-only.ch.out similarity index 100% rename from docs/books/the-reasoned-schemer/05-members-only.ch.out rename to docs/examples/books/the-reasoned-schemer/05-members-only.ch.out diff --git a/docs/books/the-reasoned-schemer/06-the-fun-never-ends.ch b/docs/examples/books/the-reasoned-schemer/06-the-fun-never-ends.ch similarity index 93% rename from docs/books/the-reasoned-schemer/06-the-fun-never-ends.ch rename to docs/examples/books/the-reasoned-schemer/06-the-fun-never-ends.ch index 38de1d73..6820cce6 100644 --- a/docs/books/the-reasoned-schemer/06-the-fun-never-ends.ch +++ b/docs/examples/books/the-reasoned-schemer/06-the-fun-never-ends.ch @@ -1,11 +1,11 @@ import { Succeed, Fail } from "01-playthings.ch" -clause Always() +relation Always() --------- { Succeed() } -clause Always() +relation Always() --------- { Always() } @@ -45,7 +45,7 @@ print find q { Always() } -clause Never() +relation Never() --------- { Never() } diff --git a/docs/books/the-reasoned-schemer/06-the-fun-never-ends.ch.out b/docs/examples/books/the-reasoned-schemer/06-the-fun-never-ends.ch.out similarity index 100% rename from docs/books/the-reasoned-schemer/06-the-fun-never-ends.ch.out rename to docs/examples/books/the-reasoned-schemer/06-the-fun-never-ends.ch.out diff --git a/docs/books/the-reasoned-schemer/07-a-bit-too-much.ch b/docs/examples/books/the-reasoned-schemer/07-a-bit-too-much.ch similarity index 73% rename from docs/books/the-reasoned-schemer/07-a-bit-too-much.ch rename to docs/examples/books/the-reasoned-schemer/07-a-bit-too-much.ch index 399c1397..24721f02 100644 --- a/docs/books/the-reasoned-schemer/07-a-bit-too-much.ch +++ b/docs/examples/books/the-reasoned-schemer/07-a-bit-too-much.ch @@ -1,14 +1,14 @@ -clause Bit(0) -clause Bit(1) +relation Bit(0) +relation Bit(1) print find x { Bit(x) } -clause BitXor(0, 0, 0) -clause BitXor(0, 1, 1) -clause BitXor(1, 0, 1) -clause BitXor(1, 1, 0) +relation BitXor(0, 0, 0) +relation BitXor(0, 1, 1) +relation BitXor(1, 0, 1) +relation BitXor(1, 1, 0) print find [x, y] { BitXor(x, y, 0) @@ -22,10 +22,10 @@ print find [x, y, r] { BitXor(x, y, r) } -clause BitAnd(0, 0, 0) -clause BitAnd(0, 1, 0) -clause BitAnd(1, 0, 0) -clause BitAnd(1, 1, 1) +relation BitAnd(0, 0, 0) +relation BitAnd(0, 1, 0) +relation BitAnd(1, 0, 0) +relation BitAnd(1, 1, 1) print find [x, y] { BitAnd(x, y, 1) @@ -33,7 +33,7 @@ print find [x, y] { // x + y = r + 2 * c -clause HalfAdder(x, y, r, c) +relation HalfAdder(x, y, r, c) ---------------------- { BitXor(x, y, r) BitAnd(x, y, c) @@ -49,7 +49,7 @@ print find [x, y, r, c] { // b + x + y = r + 2 * c -clause FullAdder(b, x, y, r, c) +relation FullAdder(b, x, y, r, c) ------------------------- { HalfAdder(x, y, w, xy) HalfAdder(w, b, r, wz) @@ -68,7 +68,7 @@ print find [b, x, y, r, c] { FullAdder(b, x, y, r, c) } -export clause Positive(n) +export relation Positive(n) ---------------- { Equal([_a | _d], n) } @@ -89,7 +89,7 @@ print find r { Positive(r) } -export clause GreaterThanOne(n) +export relation GreaterThanOne(n) --------------------- { Equal([_a, _ad | _dd], n) } @@ -114,14 +114,14 @@ print find r { GreaterThanOne(r) } -clause Adder(0, n, [], n) -clause Adder(0, [], m, m) -- { Positive(m) } -clause Adder(1, n, [], r) -- { Adder(0, n, [1], r) } -clause Adder(1, [], m, r) -- { Positive(m) Adder(0, [1], m, r) } -clause Adder(b, [1], [1], [a, c]) -- { FullAdder(b, 1, 1, a, c) } -clause Adder(b, [1], m, r) -- { GenAdder(b, [1], m, r) } -clause Adder(b, n, [1], r) -- { GreaterThanOne(n) GreaterThanOne(r) Adder(b, [1], n, r) } -clause Adder(b, n, m, r) -- { GreaterThanOne(n) GenAdder(b, n, m, r) } +relation Adder(0, n, [], n) +relation Adder(0, [], m, m) -- { Positive(m) } +relation Adder(1, n, [], r) -- { Adder(0, n, [1], r) } +relation Adder(1, [], m, r) -- { Positive(m) Adder(0, [1], m, r) } +relation Adder(b, [1], [1], [a, c]) -- { FullAdder(b, 1, 1, a, c) } +relation Adder(b, [1], m, r) -- { GenAdder(b, [1], m, r) } +relation Adder(b, n, [1], r) -- { GreaterThanOne(n) GreaterThanOne(r) Adder(b, [1], n, r) } +relation Adder(b, n, m, r) -- { GreaterThanOne(n) GenAdder(b, n, m, r) } // Given the carry bit b, // and the numbers n, m, and r, @@ -129,7 +129,7 @@ clause Adder(b, n, m, r) -- { GreaterThanOne(n) GenAdder(b, n, m, r) } // provided that n is positive // and m and r are greater than one. -clause GenAdder(b, n, m, r) +relation GenAdder(b, n, m, r) ------------------------- { Equal([a | x], n) Equal([d | y], m) Positive(y) @@ -162,7 +162,7 @@ print find [x, y] { Adder(0, x, y, [1, 0, 1]) } -export clause Add(x, y, r) +export relation Add(x, y, r) --------------------- { Adder(0, x, y, r) } @@ -183,7 +183,7 @@ print find [x, y] { Add(x, y, [1, 0, 1]) } -clause Sub(n, m, k) +relation Sub(n, m, k) ---------------- { Add(m, k, n) } @@ -216,8 +216,8 @@ print find q { // Add(x, y, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) // } -clause Length([], []) -clause Length([_a | d], n) -- { +relation Length([], []) +relation Length([_a | d], n) -- { Add([1], res, n) Length(d, res) } diff --git a/docs/books/the-reasoned-schemer/07-a-bit-too-much.ch.out b/docs/examples/books/the-reasoned-schemer/07-a-bit-too-much.ch.out similarity index 100% rename from docs/books/the-reasoned-schemer/07-a-bit-too-much.ch.out rename to docs/examples/books/the-reasoned-schemer/07-a-bit-too-much.ch.out diff --git a/docs/books/the-reasoned-schemer/08-just-a-bit-more.ch b/docs/examples/books/the-reasoned-schemer/08-just-a-bit-more.ch similarity index 63% rename from docs/books/the-reasoned-schemer/08-just-a-bit-more.ch rename to docs/examples/books/the-reasoned-schemer/08-just-a-bit-more.ch index d97d8cd9..de41268d 100644 --- a/docs/books/the-reasoned-schemer/08-just-a-bit-more.ch +++ b/docs/examples/books/the-reasoned-schemer/08-just-a-bit-more.ch @@ -4,17 +4,17 @@ import { Add, } from "07-a-bit-too-much.ch" -clause Mul([], _m, []) -clause Mul(n, [], []) -- { Positive(n) } -clause Mul([1], m, m) -- { Positive(m) } -clause Mul(n, [1], n) -- { GreaterThanOne(n) } -clause Mul([0 | x], m, [0 | z]) -- { Positive(x) Positive(z) GreaterThanOne(m) Mul(x, m, z) } -clause Mul([1 | x], [0 | y], p) -- { Positive(x) Positive(y) Mul([0 | y], [1 | x], p) } -clause Mul([1 | x], [1 | y], p) -- { Positive(x) Positive(y) MulOdd(x, [1 | x], [1 | y], p) } +relation Mul([], _m, []) +relation Mul(n, [], []) -- { Positive(n) } +relation Mul([1], m, m) -- { Positive(m) } +relation Mul(n, [1], n) -- { GreaterThanOne(n) } +relation Mul([0 | x], m, [0 | z]) -- { Positive(x) Positive(z) GreaterThanOne(m) Mul(x, m, z) } +relation Mul([1 | x], [0 | y], p) -- { Positive(x) Positive(y) Mul([0 | y], [1 | x], p) } +relation Mul([1 | x], [1 | y], p) -- { Positive(x) Positive(y) MulOdd(x, [1 | x], [1 | y], p) } // x = (n - 1) / 2 -clause MulOdd(x, n, m, p) +relation MulOdd(x, n, m, p) -------------------- { MulBound(q, p, n, m) Mul(x, m, q) @@ -23,9 +23,9 @@ clause MulOdd(x, n, m, p) // NOTE Limit the length of the q above. -clause MulBound([], p, _n, _m) -- { Positive(p) } -clause MulBound([_a0 | x], [_a1 | y], [], [_a2 | z]) -- { MulBound(x, y, z, []) } -clause MulBound([_a0 | x], [_a1 | y], [_a2 | z], m) -- { MulBound(x, y, z, m) } +relation MulBound([], p, _n, _m) -- { Positive(p) } +relation MulBound([_a0 | x], [_a1 | y], [], [_a2 | z]) -- { MulBound(x, y, z, []) } +relation MulBound([_a0 | x], [_a1 | y], [_a2 | z], m) -- { MulBound(x, y, z, m) } print find [x, y, r] limit 10 { Mul(x, y, r) @@ -74,9 +74,9 @@ print find p { Mul([1, 1, 1], [1, 1, 1, 1, 1, 1], p) } -clause EqualLength([], []) -clause EqualLength([1], [1]) -clause EqualLength([_a | x], [_b | y]) +relation EqualLength([], []) +relation EqualLength([1], [1]) +relation EqualLength([_a | x], [_b | y]) ----------------------------------- { Positive(x) Positive(y) diff --git a/docs/books/the-reasoned-schemer/08-just-a-bit-more.ch.out b/docs/examples/books/the-reasoned-schemer/08-just-a-bit-more.ch.out similarity index 100% rename from docs/books/the-reasoned-schemer/08-just-a-bit-more.ch.out rename to docs/examples/books/the-reasoned-schemer/08-just-a-bit-more.ch.out diff --git a/docs/books/the-reasoned-schemer/09-thin-ice.ch b/docs/examples/books/the-reasoned-schemer/09-thin-ice.ch similarity index 100% rename from docs/books/the-reasoned-schemer/09-thin-ice.ch rename to docs/examples/books/the-reasoned-schemer/09-thin-ice.ch diff --git a/docs/books/the-reasoned-schemer/10-under-the-hood.ch b/docs/examples/books/the-reasoned-schemer/10-under-the-hood.ch similarity index 100% rename from docs/books/the-reasoned-schemer/10-under-the-hood.ch rename to docs/examples/books/the-reasoned-schemer/10-under-the-hood.ch diff --git a/docs/langs/lambda-closure.ch b/docs/examples/langs/lambda-closure.ch similarity index 57% rename from docs/langs/lambda-closure.ch rename to docs/examples/langs/lambda-closure.ch index 55bebb12..dc222b6c 100644 --- a/docs/langs/lambda-closure.ch +++ b/docs/examples/langs/lambda-closure.ch @@ -1,42 +1,42 @@ -clause Exp(Exp::Var(name)) -- { String(name) } -clause Exp(Exp::Fn(name, ret)) -- { String(name) Exp(ret) } -clause Exp(Exp::Ap(target, arg)) -- { Exp(target) Exp(arg) } +relation Exp(Exp::Var(name)) -- { String(name) } +relation Exp(Exp::Fn(name, ret)) -- { String(name) Exp(ret) } +relation Exp(Exp::Ap(target, arg)) -- { Exp(target) Exp(arg) } print find exp limit 10 { Exp(exp) } -clause Value(Value::Closure(name, ret, env)) -- { +relation Value(Value::Closure(name, ret, env)) -- { String(name) Exp(ret) Env(env) } -clause Env([]) -clause Env([[name, value] | rest]) -- { +relation Env([]) +relation Env([[name, value] | rest]) -- { String(name) Value(value) Env(rest) } -clause Lookup([[key, value] | _rest], key, value) -- here -clause Lookup([[key, _value] | rest], name, found) +relation Lookup([[key, value] | _rest], key, value) -- here +relation Lookup([[key, _value] | rest], name, found) --------------------------------------------- there { NotEqual(key, name) Lookup(rest, name, found) } -clause Eval(env, Exp::Var(name), value) +relation Eval(env, Exp::Var(name), value) ---------------------------- var { Lookup(env, name, value) } -clause Eval(env, Exp::Fn(name, ret), value) +relation Eval(env, Exp::Fn(name, ret), value) ---------------------------------- fn { Equal(value, Value::Closure(name, ret, env)) } -clause Eval(env, Exp::Ap(target, arg), value) +relation Eval(env, Exp::Ap(target, arg), value) ---------------------------------------- ap { Eval(env, target, Value::Closure(name, ret, env2)) Eval(env, arg, argValue) diff --git a/docs/langs/lambda-closure.ch.out b/docs/examples/langs/lambda-closure.ch.out similarity index 100% rename from docs/langs/lambda-closure.ch.out rename to docs/examples/langs/lambda-closure.ch.out diff --git a/docs/langs/lambda-simple-type.ch b/docs/examples/langs/lambda-simple-type.ch similarity index 58% rename from docs/langs/lambda-simple-type.ch rename to docs/examples/langs/lambda-simple-type.ch index 2d8c11a4..51d64e2b 100644 --- a/docs/langs/lambda-simple-type.ch +++ b/docs/examples/langs/lambda-simple-type.ch @@ -1,31 +1,31 @@ -clause Exp(Exp::Var(name)) -- { String(name) } -clause Exp(Exp::Fn(name, ret)) -- { String(name) Exp(ret) } -clause Exp(Exp::Ap(target, arg)) -- { Exp(target) Exp(arg) } +relation Exp(Exp::Var(name)) -- { String(name) } +relation Exp(Exp::Fn(name, ret)) -- { String(name) Exp(ret) } +relation Exp(Exp::Ap(target, arg)) -- { Exp(target) Exp(arg) } -clause Type(Type::Atom(name)) -- { String(name) } -clause Type(Type::Arrow(argType, retType)) -- { Type(argType) Type(retType) } +relation Type(Type::Atom(name)) -- { String(name) } +relation Type(Type::Arrow(argType, retType)) -- { Type(argType) Type(retType) } -clause Ctx([]) -clause Ctx([[name, type] | rest]) -- { String(name) Type(type) Ctx(rest) } +relation Ctx([]) +relation Ctx([[name, type] | rest]) -- { String(name) Type(type) Ctx(rest) } -clause Lookup([[key, value] | _rest], key, value) -clause Lookup([[key, _value] | rest], name, found) +relation Lookup([[key, value] | _rest], key, value) +relation Lookup([[key, _value] | rest], name, found) -------------------------------------------- { NotEqual(key, name) Lookup(rest, name, found) } -clause Check(ctx, Exp::Var(name), type) +relation Check(ctx, Exp::Var(name), type) ---------------------------- { Lookup(ctx, name, type) } -clause Check(ctx, Exp::Fn(name, ret), Type::Arrow(argType, retType)) +relation Check(ctx, Exp::Fn(name, ret), Type::Arrow(argType, retType)) --------------------------------------------------- { Check([[name, argType] | ctx], ret, retType) } -clause Check(ctx, Exp::Ap(target, arg), retType) +relation Check(ctx, Exp::Ap(target, arg), retType) ------------------------------------- { Check(ctx, target, Type::Arrow(argType, retType)) Check(ctx, arg, argType) diff --git a/docs/langs/lambda-simple-type.ch.out b/docs/examples/langs/lambda-simple-type.ch.out similarity index 100% rename from docs/langs/lambda-simple-type.ch.out rename to docs/examples/langs/lambda-simple-type.ch.out diff --git a/docs/examples/std/list/Append.ch b/docs/examples/std/list/Append.ch new file mode 100644 index 00000000..59351a51 --- /dev/null +++ b/docs/examples/std/list/Append.ch @@ -0,0 +1,6 @@ +export { Append } + +relation Append([], l, l) +relation Append([a | d], l, [a | r]) -- { + Append(d, l, r) +} diff --git a/docs/std/list/Append.test.ch b/docs/examples/std/list/Append.test.ch similarity index 100% rename from docs/std/list/Append.test.ch rename to docs/examples/std/list/Append.test.ch diff --git a/docs/std/list/Append.test.ch.out b/docs/examples/std/list/Append.test.ch.out similarity index 100% rename from docs/std/list/Append.test.ch.out rename to docs/examples/std/list/Append.test.ch.out diff --git a/docs/std/list/Lookup.ch b/docs/examples/std/list/Lookup.ch similarity index 79% rename from docs/std/list/Lookup.ch rename to docs/examples/std/list/Lookup.ch index 69017b61..0515e5e3 100644 --- a/docs/std/list/Lookup.ch +++ b/docs/examples/std/list/Lookup.ch @@ -1,13 +1,13 @@ export { Lookup } -clause Lookup(map, name, found) +relation Lookup(map, name, found) ------------------------- here { Equal(map, [[key, value] | _rest]) Equal(key, name) Equal(found, value) } -clause Lookup(map, name, found) +relation Lookup(map, name, found) ------------------------------- there { Equal(map, [[key, _value] | rest]) NotEqual(key, name) diff --git a/docs/std/list/Lookup.test.ch b/docs/examples/std/list/Lookup.test.ch similarity index 100% rename from docs/std/list/Lookup.test.ch rename to docs/examples/std/list/Lookup.test.ch diff --git a/docs/std/list/Lookup.test.ch.out b/docs/examples/std/list/Lookup.test.ch.out similarity index 100% rename from docs/std/list/Lookup.test.ch.out rename to docs/examples/std/list/Lookup.test.ch.out diff --git a/docs/std/list/index.ch b/docs/examples/std/list/index.ch similarity index 100% rename from docs/std/list/index.ch rename to docs/examples/std/list/index.ch diff --git a/docs/std/nat/Add.ch b/docs/examples/std/nat/Add.ch similarity index 57% rename from docs/std/nat/Add.ch rename to docs/examples/std/nat/Add.ch index 4e6c38ca..0201e679 100644 --- a/docs/std/nat/Add.ch +++ b/docs/examples/std/nat/Add.ch @@ -2,8 +2,8 @@ import { Zero, Add1, Nat } from "Nat.ch" export { Add } -clause Add(Nat::Zero(), y, y) -clause Add(Nat::Add1(prev), y, Nat::Add1(res)) +relation Add(Nat::Zero(), y, y) +relation Add(Nat::Add1(prev), y, Nat::Add1(res)) --------------------------- { Add(prev, y, res) } diff --git a/docs/std/nat/Add.test.ch b/docs/examples/std/nat/Add.test.ch similarity index 100% rename from docs/std/nat/Add.test.ch rename to docs/examples/std/nat/Add.test.ch diff --git a/docs/std/nat/Add.test.ch.out b/docs/examples/std/nat/Add.test.ch.out similarity index 100% rename from docs/std/nat/Add.test.ch.out rename to docs/examples/std/nat/Add.test.ch.out diff --git a/docs/std/nat/Mul.ch b/docs/examples/std/nat/Mul.ch similarity index 82% rename from docs/std/nat/Mul.ch rename to docs/examples/std/nat/Mul.ch index 1f499b68..cbf810dc 100644 --- a/docs/std/nat/Mul.ch +++ b/docs/examples/std/nat/Mul.ch @@ -3,20 +3,20 @@ import { Add } from "Add.ch" export { Mul } -clause Mul(x, _y, z) +relation Mul(x, _y, z) --------------- zero_left { Zero(x) Zero(z) } -clause Mul(x, y, z) +relation Mul(x, y, z) ----------------- add1_left_zero_right { Zero(y) Zero(z) Add1(_prev, x) } -clause Mul(x, y, out) +relation Mul(x, y, out) ----------------- add1_left_add1_right { Add1(prev, x) Add1(_prev, y) diff --git a/docs/std/nat/Mul.test.ch b/docs/examples/std/nat/Mul.test.ch similarity index 100% rename from docs/std/nat/Mul.test.ch rename to docs/examples/std/nat/Mul.test.ch diff --git a/docs/std/nat/Mul.test.ch.out b/docs/examples/std/nat/Mul.test.ch.out similarity index 100% rename from docs/std/nat/Mul.test.ch.out rename to docs/examples/std/nat/Mul.test.ch.out diff --git a/docs/examples/std/nat/Nat.ch b/docs/examples/std/nat/Nat.ch new file mode 100644 index 00000000..42b8cd46 --- /dev/null +++ b/docs/examples/std/nat/Nat.ch @@ -0,0 +1,7 @@ +export { Nat, Zero, Add1 } + +relation Nat(Nat::Zero()) +relation Nat(Nat::Add1(prev)) -- { Nat(prev) } + +relation Zero(Nat::Zero()) +relation Add1(prev, Nat::Add1(prev)) diff --git a/docs/std/nat/index.ch b/docs/examples/std/nat/index.ch similarity index 100% rename from docs/std/nat/index.ch rename to docs/examples/std/nat/index.ch diff --git a/docs/examples/std/nat/numbers.ch b/docs/examples/std/nat/numbers.ch new file mode 100644 index 00000000..73ff293b --- /dev/null +++ b/docs/examples/std/nat/numbers.ch @@ -0,0 +1,14 @@ +import { Zero, Add1 } from "Nat.ch" + +export relation One(n) -- { Add1(prev, n) Zero(prev) } +export relation Two(n) -- { Add1(prev, n) One(prev) } +export relation Three(n) -- { Add1(prev, n) Two(prev) } +export relation Four(n) -- { Add1(prev, n) Three(prev) } +export relation Five(n) -- { Add1(prev, n) Four(prev) } +export relation Six(n) -- { Add1(prev, n) Five(prev) } +export relation Seven(n) -- { Add1(prev, n) Six(prev) } +export relation Eight(n) -- { Add1(prev, n) Seven(prev) } +export relation Nine(n) -- { Add1(prev, n) Eight(prev) } +export relation Ten(n) -- { Add1(prev, n) Nine(prev) } +export relation Eleven(n) -- { Add1(prev, n) Ten(prev) } +export relation Twelve(n) -- { Add1(prev, n) Eleven(prev) } diff --git a/docs/std/nat/play.ch b/docs/examples/std/nat/play.ch similarity index 94% rename from docs/std/nat/play.ch rename to docs/examples/std/nat/play.ch index c9d6267a..11162628 100644 --- a/docs/std/nat/play.ch +++ b/docs/examples/std/nat/play.ch @@ -1,4 +1,4 @@ -clause LtEqThree(n) +relation LtEqThree(n) -------------- { NotEqual(n, Nat::Add1(Nat::Add1(Nat::Add1(Nat::Zero())))) } diff --git a/docs/std/nat/play.ch.out b/docs/examples/std/nat/play.ch.out similarity index 100% rename from docs/std/nat/play.ch.out rename to docs/examples/std/nat/play.ch.out diff --git a/docs/examples/std/trilean/Trilean.ch b/docs/examples/std/trilean/Trilean.ch new file mode 100644 index 00000000..7a5fc66e --- /dev/null +++ b/docs/examples/std/trilean/Trilean.ch @@ -0,0 +1,62 @@ +// Use logic programming to play with many-valued logic. + +relation Trilean(0) +relation Trilean(0.5) +relation Trilean(1) + +// Name of the three values: + +relation TrileanFalse(0) +relation TrileanMiddle(0.5) +relation TrileanTrue(1) + +relation TrileanMin(0, 0, 0) +relation TrileanMin(0, 0.5, 0) +relation TrileanMin(0, 1, 0) +relation TrileanMin(0.5, 0, 0) +relation TrileanMin(0.5, 0.5, 0.5) +relation TrileanMin(0.5, 1, 0.5) +relation TrileanMin(1, 0, 0) +relation TrileanMin(1, 0.5, 0.5) +relation TrileanMin(1, 1, 1) + +relation TrileanMax(0, 0, 0) +relation TrileanMax(0, 0.5, 0.5) +relation TrileanMax(0, 1, 1) +relation TrileanMax(0.5, 0, 0.5) +relation TrileanMax(0.5, 0.5, 0.5) +relation TrileanMax(0.5, 1, 1) +relation TrileanMax(1, 0, 1) +relation TrileanMax(1, 0.5, 1) +relation TrileanMax(1, 1, 1) + +relation TrileanPositive(0.5) +relation TrileanPositive(1) + +// Use mutually exclusive cases. + +relation TrileanMul(0, y, 0) -- { Trilean(y) } +relation TrileanMul(x, 0, 0) -- { TrileanPositive(x) } +relation TrileanMul(x, y, z) -- { + TrileanPositive(x) + TrileanPositive(y) + TrileanMax(x, y, z) +} + +// See how `TrileanMax` is different from `TrileanMul`: + +print find [x, y, z] { TrileanMax(x, y, z) } +print find [x, y, z] { TrileanMul(x, y, z) } + +// What returns 0? +print find [x, y] { TrileanMul(x, y, 0) } + +// [question] Can `TrileansMul` be defined by +// composition of other connectives (not, min, max)? +// Does this means to use only one clause? + +// [question] How to search high-order things +// like connective in logic programming? +// We want to search how to construct truth function +// by composition of given set of connectives. +// Maybe we must define first order expressions first. diff --git a/docs/std/trilean/Trilean.ch.out b/docs/examples/std/trilean/Trilean.ch.out similarity index 100% rename from docs/std/trilean/Trilean.ch.out rename to docs/examples/std/trilean/Trilean.ch.out diff --git a/docs/tests/basic/assert-false.error.ch b/docs/examples/tests/basic/assert-false.error.ch similarity index 100% rename from docs/tests/basic/assert-false.error.ch rename to docs/examples/tests/basic/assert-false.error.ch diff --git a/docs/tests/basic/assert-false.error.ch.err b/docs/examples/tests/basic/assert-false.error.ch.err similarity index 100% rename from docs/tests/basic/assert-false.error.ch.err rename to docs/examples/tests/basic/assert-false.error.ch.err diff --git a/docs/tests/basic/assert-non-boolean.error.ch b/docs/examples/tests/basic/assert-non-boolean.error.ch similarity index 100% rename from docs/tests/basic/assert-non-boolean.error.ch rename to docs/examples/tests/basic/assert-non-boolean.error.ch diff --git a/docs/tests/basic/assert-non-boolean.error.ch.err b/docs/examples/tests/basic/assert-non-boolean.error.ch.err similarity index 100% rename from docs/tests/basic/assert-non-boolean.error.ch.err rename to docs/examples/tests/basic/assert-non-boolean.error.ch.err diff --git a/docs/tests/basic/assert.ch b/docs/examples/tests/basic/assert.ch similarity index 100% rename from docs/tests/basic/assert.ch rename to docs/examples/tests/basic/assert.ch diff --git a/docs/tests/basic/compute.ch b/docs/examples/tests/basic/compute.ch similarity index 100% rename from docs/tests/basic/compute.ch rename to docs/examples/tests/basic/compute.ch diff --git a/docs/tests/basic/compute.ch.out b/docs/examples/tests/basic/compute.ch.out similarity index 100% rename from docs/tests/basic/compute.ch.out rename to docs/examples/tests/basic/compute.ch.out diff --git a/docs/tests/basic/currying.ch b/docs/examples/tests/basic/currying.ch similarity index 100% rename from docs/tests/basic/currying.ch rename to docs/examples/tests/basic/currying.ch diff --git a/docs/tests/basic/currying.ch.out b/docs/examples/tests/basic/currying.ch.out similarity index 100% rename from docs/tests/basic/currying.ch.out rename to docs/examples/tests/basic/currying.ch.out diff --git a/docs/tests/basic/dot.ch b/docs/examples/tests/basic/dot.ch similarity index 100% rename from docs/tests/basic/dot.ch rename to docs/examples/tests/basic/dot.ch diff --git a/docs/tests/basic/function-print.ch b/docs/examples/tests/basic/function-print.ch similarity index 100% rename from docs/tests/basic/function-print.ch rename to docs/examples/tests/basic/function-print.ch diff --git a/docs/tests/basic/function-print.ch.out b/docs/examples/tests/basic/function-print.ch.out similarity index 100% rename from docs/tests/basic/function-print.ch.out rename to docs/examples/tests/basic/function-print.ch.out diff --git a/docs/tests/basic/function-with-clause.ch b/docs/examples/tests/basic/function-with-clause.ch similarity index 91% rename from docs/tests/basic/function-with-clause.ch rename to docs/examples/tests/basic/function-with-clause.ch index a6ab2960..5b2e113a 100644 --- a/docs/tests/basic/function-with-clause.ch +++ b/docs/examples/tests/basic/function-with-clause.ch @@ -1,5 +1,5 @@ function greet(x) { - clause Hi("hi") + relation Hi("hi") // The expressions in `find` are implicitly `quote`d. diff --git a/docs/tests/basic/function-with-clause.ch.out b/docs/examples/tests/basic/function-with-clause.ch.out similarity index 100% rename from docs/tests/basic/function-with-clause.ch.out rename to docs/examples/tests/basic/function-with-clause.ch.out diff --git a/docs/tests/basic/function-with-early-return.ch b/docs/examples/tests/basic/function-with-early-return.ch similarity index 100% rename from docs/tests/basic/function-with-early-return.ch rename to docs/examples/tests/basic/function-with-early-return.ch diff --git a/docs/tests/basic/function-with-early-return.ch.out b/docs/examples/tests/basic/function-with-early-return.ch.out similarity index 100% rename from docs/tests/basic/function-with-early-return.ch.out rename to docs/examples/tests/basic/function-with-early-return.ch.out diff --git a/docs/tests/basic/function-with-return-expression.ch b/docs/examples/tests/basic/function-with-return-expression.ch similarity index 100% rename from docs/tests/basic/function-with-return-expression.ch rename to docs/examples/tests/basic/function-with-return-expression.ch diff --git a/docs/tests/basic/function-with-return-expression.ch.out b/docs/examples/tests/basic/function-with-return-expression.ch.out similarity index 100% rename from docs/tests/basic/function-with-return-expression.ch.out rename to docs/examples/tests/basic/function-with-return-expression.ch.out diff --git a/docs/tests/basic/function-with-return-null.ch b/docs/examples/tests/basic/function-with-return-null.ch similarity index 100% rename from docs/tests/basic/function-with-return-null.ch rename to docs/examples/tests/basic/function-with-return-null.ch diff --git a/docs/tests/basic/function-with-return-null.ch.out b/docs/examples/tests/basic/function-with-return-null.ch.out similarity index 100% rename from docs/tests/basic/function-with-return-null.ch.out rename to docs/examples/tests/basic/function-with-return-null.ch.out diff --git a/docs/tests/basic/function.ch b/docs/examples/tests/basic/function.ch similarity index 100% rename from docs/tests/basic/function.ch rename to docs/examples/tests/basic/function.ch diff --git a/docs/tests/basic/function.ch.out b/docs/examples/tests/basic/function.ch.out similarity index 100% rename from docs/tests/basic/function.ch.out rename to docs/examples/tests/basic/function.ch.out diff --git a/docs/tests/basic/if-else-if.ch b/docs/examples/tests/basic/if-else-if.ch similarity index 100% rename from docs/tests/basic/if-else-if.ch rename to docs/examples/tests/basic/if-else-if.ch diff --git a/docs/tests/basic/if-else-if.ch.out b/docs/examples/tests/basic/if-else-if.ch.out similarity index 100% rename from docs/tests/basic/if-else-if.ch.out rename to docs/examples/tests/basic/if-else-if.ch.out diff --git a/docs/tests/basic/if-exp-without-else.ch b/docs/examples/tests/basic/if-exp-without-else.ch similarity index 100% rename from docs/tests/basic/if-exp-without-else.ch rename to docs/examples/tests/basic/if-exp-without-else.ch diff --git a/docs/tests/basic/if-exp-without-else.ch.out b/docs/examples/tests/basic/if-exp-without-else.ch.out similarity index 100% rename from docs/tests/basic/if-exp-without-else.ch.out rename to docs/examples/tests/basic/if-exp-without-else.ch.out diff --git a/docs/tests/basic/if-exp.ch b/docs/examples/tests/basic/if-exp.ch similarity index 100% rename from docs/tests/basic/if-exp.ch rename to docs/examples/tests/basic/if-exp.ch diff --git a/docs/tests/basic/if-exp.ch.out b/docs/examples/tests/basic/if-exp.ch.out similarity index 100% rename from docs/tests/basic/if-exp.ch.out rename to docs/examples/tests/basic/if-exp.ch.out diff --git a/docs/tests/basic/if-non-boolean-target.error.ch b/docs/examples/tests/basic/if-non-boolean-target.error.ch similarity index 100% rename from docs/tests/basic/if-non-boolean-target.error.ch rename to docs/examples/tests/basic/if-non-boolean-target.error.ch diff --git a/docs/tests/basic/if-non-boolean-target.error.ch.err b/docs/examples/tests/basic/if-non-boolean-target.error.ch.err similarity index 100% rename from docs/tests/basic/if-non-boolean-target.error.ch.err rename to docs/examples/tests/basic/if-non-boolean-target.error.ch.err diff --git a/docs/tests/basic/if-without-else.ch b/docs/examples/tests/basic/if-without-else.ch similarity index 100% rename from docs/tests/basic/if-without-else.ch rename to docs/examples/tests/basic/if-without-else.ch diff --git a/docs/tests/basic/if-without-else.ch.out b/docs/examples/tests/basic/if-without-else.ch.out similarity index 100% rename from docs/tests/basic/if-without-else.ch.out rename to docs/examples/tests/basic/if-without-else.ch.out diff --git a/docs/tests/basic/if.ch b/docs/examples/tests/basic/if.ch similarity index 100% rename from docs/tests/basic/if.ch rename to docs/examples/tests/basic/if.ch diff --git a/docs/tests/basic/if.ch.out b/docs/examples/tests/basic/if.ch.out similarity index 100% rename from docs/tests/basic/if.ch.out rename to docs/examples/tests/basic/if.ch.out diff --git a/docs/tests/basic/let.ch b/docs/examples/tests/basic/let.ch similarity index 100% rename from docs/tests/basic/let.ch rename to docs/examples/tests/basic/let.ch diff --git a/docs/tests/basic/print.ch b/docs/examples/tests/basic/print.ch similarity index 100% rename from docs/tests/basic/print.ch rename to docs/examples/tests/basic/print.ch diff --git a/docs/tests/basic/print.ch.out b/docs/examples/tests/basic/print.ch.out similarity index 100% rename from docs/tests/basic/print.ch.out rename to docs/examples/tests/basic/print.ch.out diff --git a/docs/tests/constraints/not-equal.ch b/docs/examples/tests/constraints/not-equal.ch similarity index 100% rename from docs/tests/constraints/not-equal.ch rename to docs/examples/tests/constraints/not-equal.ch diff --git a/docs/tests/constraints/not-equal.ch.out b/docs/examples/tests/constraints/not-equal.ch.out similarity index 100% rename from docs/tests/constraints/not-equal.ch.out rename to docs/examples/tests/constraints/not-equal.ch.out diff --git a/docs/tests/constraints/number-types.ch b/docs/examples/tests/constraints/number-types.ch similarity index 100% rename from docs/tests/constraints/number-types.ch rename to docs/examples/tests/constraints/number-types.ch diff --git a/docs/tests/constraints/number-types.ch.out b/docs/examples/tests/constraints/number-types.ch.out similarity index 100% rename from docs/tests/constraints/number-types.ch.out rename to docs/examples/tests/constraints/number-types.ch.out diff --git a/docs/tests/constraints/string-types.ch b/docs/examples/tests/constraints/string-types.ch similarity index 100% rename from docs/tests/constraints/string-types.ch rename to docs/examples/tests/constraints/string-types.ch diff --git a/docs/tests/constraints/string-types.ch.out b/docs/examples/tests/constraints/string-types.ch.out similarity index 100% rename from docs/tests/constraints/string-types.ch.out rename to docs/examples/tests/constraints/string-types.ch.out diff --git a/docs/tests/conventions/no-misused-variable-name.error.ch b/docs/examples/tests/conventions/no-misused-variable-name.error.ch similarity index 64% rename from docs/tests/conventions/no-misused-variable-name.error.ch rename to docs/examples/tests/conventions/no-misused-variable-name.error.ch index e8f957dc..de4bd6c9 100644 --- a/docs/tests/conventions/no-misused-variable-name.error.ch +++ b/docs/examples/tests/conventions/no-misused-variable-name.error.ch @@ -1,4 +1,4 @@ -clause Car(p, _a) +relation Car(p, _a) ---------- { Equal([_a | _d], p) } diff --git a/docs/tests/conventions/no-misused-variable-name.error.ch.err b/docs/examples/tests/conventions/no-misused-variable-name.error.ch.err similarity index 92% rename from docs/tests/conventions/no-misused-variable-name.error.ch.err rename to docs/examples/tests/conventions/no-misused-variable-name.error.ch.err index 514312c3..3949f27c 100644 --- a/docs/tests/conventions/no-misused-variable-name.error.ch.err +++ b/docs/examples/tests/conventions/no-misused-variable-name.error.ch.err @@ -2,6 +2,6 @@ pattern variable name: _a [note] This policy about unused pattern variable name is important for finding bugs caused by typo. - 1 |clause Car(p, _a) + 1 |relation Car(p, _a) 2 |---------- { 3 | Equal([_a | _d], p) diff --git a/docs/tests/conventions/no-unused-variable-name.error.ch b/docs/examples/tests/conventions/no-unused-variable-name.error.ch similarity index 64% rename from docs/tests/conventions/no-unused-variable-name.error.ch rename to docs/examples/tests/conventions/no-unused-variable-name.error.ch index d0ef9e6b..98e82787 100644 --- a/docs/tests/conventions/no-unused-variable-name.error.ch +++ b/docs/examples/tests/conventions/no-unused-variable-name.error.ch @@ -1,4 +1,4 @@ -clause Car(p, a) +relation Car(p, a) ---------- { Equal([a | d], p) } diff --git a/docs/tests/conventions/no-unused-variable-name.error.ch.err b/docs/examples/tests/conventions/no-unused-variable-name.error.ch.err similarity index 92% rename from docs/tests/conventions/no-unused-variable-name.error.ch.err rename to docs/examples/tests/conventions/no-unused-variable-name.error.ch.err index 81b4d136..4636d213 100644 --- a/docs/tests/conventions/no-unused-variable-name.error.ch.err +++ b/docs/examples/tests/conventions/no-unused-variable-name.error.ch.err @@ -2,7 +2,7 @@ pattern variable name: d [note] This policy about unused pattern variable name is important for finding bugs caused by typo. - 1 |clause Car(p, a) + 1 |relation Car(p, a) 2 |---------- { 3 | Equal([a | d], p) 4 |} diff --git a/docs/tests/conventions/pattern-variable-name-can-starts-with-uppercase.ch b/docs/examples/tests/conventions/pattern-variable-name-can-starts-with-uppercase.ch similarity index 100% rename from docs/tests/conventions/pattern-variable-name-can-starts-with-uppercase.ch rename to docs/examples/tests/conventions/pattern-variable-name-can-starts-with-uppercase.ch diff --git a/docs/tests/conventions/pattern-variable-name-can-starts-with-uppercase.ch.out b/docs/examples/tests/conventions/pattern-variable-name-can-starts-with-uppercase.ch.out similarity index 100% rename from docs/tests/conventions/pattern-variable-name-can-starts-with-uppercase.ch.out rename to docs/examples/tests/conventions/pattern-variable-name-can-starts-with-uppercase.ch.out diff --git a/docs/tests/conventions/preserved-name-false.error.ch b/docs/examples/tests/conventions/preserved-name-false.error.ch similarity index 100% rename from docs/tests/conventions/preserved-name-false.error.ch rename to docs/examples/tests/conventions/preserved-name-false.error.ch diff --git a/docs/tests/conventions/preserved-name-false.error.ch.err b/docs/examples/tests/conventions/preserved-name-false.error.ch.err similarity index 100% rename from docs/tests/conventions/preserved-name-false.error.ch.err rename to docs/examples/tests/conventions/preserved-name-false.error.ch.err diff --git a/docs/tests/conventions/preserved-name-null.error.ch b/docs/examples/tests/conventions/preserved-name-null.error.ch similarity index 100% rename from docs/tests/conventions/preserved-name-null.error.ch rename to docs/examples/tests/conventions/preserved-name-null.error.ch diff --git a/docs/tests/conventions/preserved-name-null.error.ch.err b/docs/examples/tests/conventions/preserved-name-null.error.ch.err similarity index 100% rename from docs/tests/conventions/preserved-name-null.error.ch.err rename to docs/examples/tests/conventions/preserved-name-null.error.ch.err diff --git a/docs/tests/conventions/preserved-name-true.error.ch b/docs/examples/tests/conventions/preserved-name-true.error.ch similarity index 100% rename from docs/tests/conventions/preserved-name-true.error.ch rename to docs/examples/tests/conventions/preserved-name-true.error.ch diff --git a/docs/tests/conventions/preserved-name-true.error.ch.err b/docs/examples/tests/conventions/preserved-name-true.error.ch.err similarity index 100% rename from docs/tests/conventions/preserved-name-true.error.ch.err rename to docs/examples/tests/conventions/preserved-name-true.error.ch.err diff --git a/docs/examples/tests/conventions/relation-arity-mismatch.error.ch b/docs/examples/tests/conventions/relation-arity-mismatch.error.ch new file mode 100644 index 00000000..9d3403ea --- /dev/null +++ b/docs/examples/tests/conventions/relation-arity-mismatch.error.ch @@ -0,0 +1,2 @@ +relation F(1) +relation F(1, 2) diff --git a/docs/tests/conventions/relation-arity-mismatch.error.ch.err b/docs/examples/tests/conventions/relation-arity-mismatch.error.ch.err similarity index 100% rename from docs/tests/conventions/relation-arity-mismatch.error.ch.err rename to docs/examples/tests/conventions/relation-arity-mismatch.error.ch.err diff --git a/docs/examples/tests/conventions/relation-name-must-starts-with-uppercase.error.ch b/docs/examples/tests/conventions/relation-name-must-starts-with-uppercase.error.ch new file mode 100644 index 00000000..6d89dc44 --- /dev/null +++ b/docs/examples/tests/conventions/relation-name-must-starts-with-uppercase.error.ch @@ -0,0 +1 @@ +relation border("sussex", "kent") diff --git a/docs/examples/tests/conventions/relation-name-must-starts-with-uppercase.error.ch.err b/docs/examples/tests/conventions/relation-name-must-starts-with-uppercase.error.ch.err new file mode 100644 index 00000000..f00c2803 --- /dev/null +++ b/docs/examples/tests/conventions/relation-name-must-starts-with-uppercase.error.ch.err @@ -0,0 +1,14 @@ +I found syntax error in code: + + 1 |relation border("sussex", "kent") + 2 | + + +Found the identifier "border" in [9, 15], while expecting: + ["identifier"]: + stmt:clause_no_goals_no_name@0 -> "relation"@1 > (name: identifier) (args: args) + ["identifier"]: + stmt:clause_no_goals@0 -> "relation"@1 > (name: identifier) (args: args) dashline (clause_name: identifier) + ["identifier"]: + stmt:clause_no_name@0 -> "relation"@1 > (name: identifier) (args: args) dashline "{" (goals: goals) "}" + and so on ... diff --git a/docs/tests/globals/boolean.ch b/docs/examples/tests/globals/boolean.ch similarity index 100% rename from docs/tests/globals/boolean.ch rename to docs/examples/tests/globals/boolean.ch diff --git a/docs/tests/globals/boolean.ch.out b/docs/examples/tests/globals/boolean.ch.out similarity index 100% rename from docs/tests/globals/boolean.ch.out rename to docs/examples/tests/globals/boolean.ch.out diff --git a/docs/tests/globals/equal.ch b/docs/examples/tests/globals/equal.ch similarity index 100% rename from docs/tests/globals/equal.ch rename to docs/examples/tests/globals/equal.ch diff --git a/docs/tests/globals/equal.ch.out b/docs/examples/tests/globals/equal.ch.out similarity index 100% rename from docs/tests/globals/equal.ch.out rename to docs/examples/tests/globals/equal.ch.out diff --git a/docs/tests/globals/not-equal.ch b/docs/examples/tests/globals/not-equal.ch similarity index 100% rename from docs/tests/globals/not-equal.ch rename to docs/examples/tests/globals/not-equal.ch diff --git a/docs/tests/globals/not-equal.ch.out b/docs/examples/tests/globals/not-equal.ch.out similarity index 100% rename from docs/tests/globals/not-equal.ch.out rename to docs/examples/tests/globals/not-equal.ch.out diff --git a/docs/tests/globals/null-shadowed.ch b/docs/examples/tests/globals/null-shadowed.ch similarity index 57% rename from docs/tests/globals/null-shadowed.ch rename to docs/examples/tests/globals/null-shadowed.ch index 71a23470..f07d7b59 100644 --- a/docs/tests/globals/null-shadowed.ch +++ b/docs/examples/tests/globals/null-shadowed.ch @@ -2,7 +2,7 @@ print find x { Null(x) } -clause Null(x) -- { Equal(x, "null") } +relation Null(x) -- { Equal(x, "null") } print find x { Null(x) diff --git a/docs/tests/globals/null-shadowed.ch.out b/docs/examples/tests/globals/null-shadowed.ch.out similarity index 100% rename from docs/tests/globals/null-shadowed.ch.out rename to docs/examples/tests/globals/null-shadowed.ch.out diff --git a/docs/tests/globals/null.ch b/docs/examples/tests/globals/null.ch similarity index 100% rename from docs/tests/globals/null.ch rename to docs/examples/tests/globals/null.ch diff --git a/docs/tests/globals/null.ch.out b/docs/examples/tests/globals/null.ch.out similarity index 100% rename from docs/tests/globals/null.ch.out rename to docs/examples/tests/globals/null.ch.out diff --git a/docs/tests/goal/goal-apply-too-many-arguments.error.ch b/docs/examples/tests/goal/goal-apply-too-many-arguments.error.ch similarity index 100% rename from docs/tests/goal/goal-apply-too-many-arguments.error.ch rename to docs/examples/tests/goal/goal-apply-too-many-arguments.error.ch diff --git a/docs/tests/goal/goal-apply-too-many-arguments.error.ch.err b/docs/examples/tests/goal/goal-apply-too-many-arguments.error.ch.err similarity index 100% rename from docs/tests/goal/goal-apply-too-many-arguments.error.ch.err rename to docs/examples/tests/goal/goal-apply-too-many-arguments.error.ch.err diff --git a/docs/tests/goal/goal.ch b/docs/examples/tests/goal/goal.ch similarity index 100% rename from docs/tests/goal/goal.ch rename to docs/examples/tests/goal/goal.ch diff --git a/docs/tests/goal/goal.ch.out b/docs/examples/tests/goal/goal.ch.out similarity index 100% rename from docs/tests/goal/goal.ch.out rename to docs/examples/tests/goal/goal.ch.out diff --git a/docs/tests/json/array.ch b/docs/examples/tests/json/array.ch similarity index 100% rename from docs/tests/json/array.ch rename to docs/examples/tests/json/array.ch diff --git a/docs/tests/json/array.ch.out b/docs/examples/tests/json/array.ch.out similarity index 100% rename from docs/tests/json/array.ch.out rename to docs/examples/tests/json/array.ch.out diff --git a/docs/tests/json/boolean.ch b/docs/examples/tests/json/boolean.ch similarity index 100% rename from docs/tests/json/boolean.ch rename to docs/examples/tests/json/boolean.ch diff --git a/docs/tests/json/boolean.ch.out b/docs/examples/tests/json/boolean.ch.out similarity index 100% rename from docs/tests/json/boolean.ch.out rename to docs/examples/tests/json/boolean.ch.out diff --git a/docs/tests/json/null.ch b/docs/examples/tests/json/null.ch similarity index 100% rename from docs/tests/json/null.ch rename to docs/examples/tests/json/null.ch diff --git a/docs/tests/json/null.ch.out b/docs/examples/tests/json/null.ch.out similarity index 100% rename from docs/tests/json/null.ch.out rename to docs/examples/tests/json/null.ch.out diff --git a/docs/tests/json/number.ch b/docs/examples/tests/json/number.ch similarity index 100% rename from docs/tests/json/number.ch rename to docs/examples/tests/json/number.ch diff --git a/docs/tests/json/number.ch.out b/docs/examples/tests/json/number.ch.out similarity index 100% rename from docs/tests/json/number.ch.out rename to docs/examples/tests/json/number.ch.out diff --git a/docs/tests/json/object.ch b/docs/examples/tests/json/object.ch similarity index 100% rename from docs/tests/json/object.ch rename to docs/examples/tests/json/object.ch diff --git a/docs/tests/json/object.ch.out b/docs/examples/tests/json/object.ch.out similarity index 100% rename from docs/tests/json/object.ch.out rename to docs/examples/tests/json/object.ch.out diff --git a/docs/tests/json/string.ch b/docs/examples/tests/json/string.ch similarity index 100% rename from docs/tests/json/string.ch rename to docs/examples/tests/json/string.ch diff --git a/docs/tests/json/string.ch.out b/docs/examples/tests/json/string.ch.out similarity index 100% rename from docs/tests/json/string.ch.out rename to docs/examples/tests/json/string.ch.out diff --git a/docs/tests/module/A.ch b/docs/examples/tests/module/A.ch similarity index 72% rename from docs/tests/module/A.ch rename to docs/examples/tests/module/A.ch index f5e1ee32..42ea7bb4 100644 --- a/docs/tests/module/A.ch +++ b/docs/examples/tests/module/A.ch @@ -1,4 +1,4 @@ -export clause A(a) +export relation A(a) ------ { Equal(a, "a") } diff --git a/docs/tests/module/A.ch.out b/docs/examples/tests/module/A.ch.out similarity index 100% rename from docs/tests/module/A.ch.out rename to docs/examples/tests/module/A.ch.out diff --git a/docs/tests/module/AB.ch b/docs/examples/tests/module/AB.ch similarity index 80% rename from docs/tests/module/AB.ch rename to docs/examples/tests/module/AB.ch index f85e6d36..23b90d5b 100644 --- a/docs/tests/module/AB.ch +++ b/docs/examples/tests/module/AB.ch @@ -1,6 +1,6 @@ import { A } from "./A.ch" -export clause AB(a, b) +export relation AB(a, b) ---------- { A(a) Equal(b, "b") diff --git a/docs/tests/module/AB.ch.out b/docs/examples/tests/module/AB.ch.out similarity index 100% rename from docs/tests/module/AB.ch.out rename to docs/examples/tests/module/AB.ch.out diff --git a/docs/tests/module/ABC.ch b/docs/examples/tests/module/ABC.ch similarity index 80% rename from docs/tests/module/ABC.ch rename to docs/examples/tests/module/ABC.ch index f88459d3..64a59beb 100644 --- a/docs/tests/module/ABC.ch +++ b/docs/examples/tests/module/ABC.ch @@ -1,6 +1,6 @@ import { AB } from "./AB.ch" -export clause ABC(a, b, c) +export relation ABC(a, b, c) -------------- { AB(a, b) Equal(c, "c") diff --git a/docs/tests/module/ABC.ch.out b/docs/examples/tests/module/ABC.ch.out similarity index 100% rename from docs/tests/module/ABC.ch.out rename to docs/examples/tests/module/ABC.ch.out diff --git a/docs/examples/tests/module/example.ch b/docs/examples/tests/module/example.ch new file mode 100644 index 00000000..052b5c4e --- /dev/null +++ b/docs/examples/tests/module/example.ch @@ -0,0 +1,5 @@ +export relation Hello("Hello, World!") + +export relation Hi("Hi there!") + +relation Hiya("Hiya!") diff --git a/docs/tests/module/import-all-as.ch b/docs/examples/tests/module/import-all-as.ch similarity index 100% rename from docs/tests/module/import-all-as.ch rename to docs/examples/tests/module/import-all-as.ch diff --git a/docs/tests/module/import-all-as.ch.out b/docs/examples/tests/module/import-all-as.ch.out similarity index 100% rename from docs/tests/module/import-all-as.ch.out rename to docs/examples/tests/module/import-all-as.ch.out diff --git a/docs/tests/module/import-all-private.error.ch b/docs/examples/tests/module/import-all-private.error.ch similarity index 100% rename from docs/tests/module/import-all-private.error.ch rename to docs/examples/tests/module/import-all-private.error.ch diff --git a/docs/tests/module/import-all-private.error.ch.err b/docs/examples/tests/module/import-all-private.error.ch.err similarity index 100% rename from docs/tests/module/import-all-private.error.ch.err rename to docs/examples/tests/module/import-all-private.error.ch.err diff --git a/docs/tests/module/import-all.ch b/docs/examples/tests/module/import-all.ch similarity index 100% rename from docs/tests/module/import-all.ch rename to docs/examples/tests/module/import-all.ch diff --git a/docs/tests/module/import-all.ch.out b/docs/examples/tests/module/import-all.ch.out similarity index 100% rename from docs/tests/module/import-all.ch.out rename to docs/examples/tests/module/import-all.ch.out diff --git a/docs/tests/module/import-private.error.ch b/docs/examples/tests/module/import-private.error.ch similarity index 100% rename from docs/tests/module/import-private.error.ch rename to docs/examples/tests/module/import-private.error.ch diff --git a/docs/tests/module/import-private.error.ch.err b/docs/examples/tests/module/import-private.error.ch.err similarity index 100% rename from docs/tests/module/import-private.error.ch.err rename to docs/examples/tests/module/import-private.error.ch.err diff --git a/docs/tests/module/imported-name-can-be-shadowed.ch b/docs/examples/tests/module/imported-name-can-be-shadowed.ch similarity index 84% rename from docs/tests/module/imported-name-can-be-shadowed.ch rename to docs/examples/tests/module/imported-name-can-be-shadowed.ch index da90cbba..f8b15f14 100644 --- a/docs/tests/module/imported-name-can-be-shadowed.ch +++ b/docs/examples/tests/module/imported-name-can-be-shadowed.ch @@ -4,7 +4,7 @@ print find [x] { A(x) } -clause A(x) -- { +relation A(x) -- { Equal(x, "b") } diff --git a/docs/tests/module/imported-name-can-be-shadowed.ch.out b/docs/examples/tests/module/imported-name-can-be-shadowed.ch.out similarity index 100% rename from docs/tests/module/imported-name-can-be-shadowed.ch.out rename to docs/examples/tests/module/imported-name-can-be-shadowed.ch.out diff --git a/docs/tests/object/construct-object-by-relation.ch b/docs/examples/tests/object/construct-object-by-relation.ch similarity index 82% rename from docs/tests/object/construct-object-by-relation.ch rename to docs/examples/tests/object/construct-object-by-relation.ch index 0f5cc4d1..3f966db9 100644 --- a/docs/tests/object/construct-object-by-relation.ch +++ b/docs/examples/tests/object/construct-object-by-relation.ch @@ -1,4 +1,4 @@ -clause Var(exp, name) +relation Var(exp, name) --------------- { Equal(exp, { "@type": "Exp", "@kind": "Var", name }) } diff --git a/docs/tests/object/construct-object-by-relation.ch.out b/docs/examples/tests/object/construct-object-by-relation.ch.out similarity index 100% rename from docs/tests/object/construct-object-by-relation.ch.out rename to docs/examples/tests/object/construct-object-by-relation.ch.out diff --git a/docs/tests/object/merge-properties-to-object.ch b/docs/examples/tests/object/merge-properties-to-object.ch similarity index 100% rename from docs/tests/object/merge-properties-to-object.ch rename to docs/examples/tests/object/merge-properties-to-object.ch diff --git a/docs/tests/object/merge-properties-to-object.ch.out b/docs/examples/tests/object/merge-properties-to-object.ch.out similarity index 100% rename from docs/tests/object/merge-properties-to-object.ch.out rename to docs/examples/tests/object/merge-properties-to-object.ch.out diff --git a/docs/tests/relation/conj.ch b/docs/examples/tests/relation/conj.ch similarity index 100% rename from docs/tests/relation/conj.ch rename to docs/examples/tests/relation/conj.ch diff --git a/docs/tests/relation/conj.ch.out b/docs/examples/tests/relation/conj.ch.out similarity index 100% rename from docs/tests/relation/conj.ch.out rename to docs/examples/tests/relation/conj.ch.out diff --git a/docs/examples/tests/relation/datom.ch b/docs/examples/tests/relation/datom.ch new file mode 100644 index 00000000..7436bd84 --- /dev/null +++ b/docs/examples/tests/relation/datom.ch @@ -0,0 +1,9 @@ +relation Datom(1, "name", "A") +relation Datom(1, "age", 45) +relation Datom(2, "name", "X") +relation Datom(2, "age", 2) + +print find n { + Datom(e, "age", 2) + Datom(e, "name", n) +} diff --git a/docs/tests/relation/datom.ch.out b/docs/examples/tests/relation/datom.ch.out similarity index 100% rename from docs/tests/relation/datom.ch.out rename to docs/examples/tests/relation/datom.ch.out diff --git a/docs/tests/relation/disj.ch b/docs/examples/tests/relation/disj.ch similarity index 100% rename from docs/tests/relation/disj.ch rename to docs/examples/tests/relation/disj.ch diff --git a/docs/tests/relation/disj.ch.out b/docs/examples/tests/relation/disj.ch.out similarity index 100% rename from docs/tests/relation/disj.ch.out rename to docs/examples/tests/relation/disj.ch.out diff --git a/docs/tests/relation/lookup-inline-disj.ch b/docs/examples/tests/relation/lookup-inline-disj.ch similarity index 88% rename from docs/tests/relation/lookup-inline-disj.ch rename to docs/examples/tests/relation/lookup-inline-disj.ch index 1361c594..b1673912 100644 --- a/docs/tests/relation/lookup-inline-disj.ch +++ b/docs/examples/tests/relation/lookup-inline-disj.ch @@ -1,11 +1,11 @@ -clause Lookup(map, name, found) +relation Lookup(map, name, found) ------------------------- here { Equal(map, [[key, value] | _rest]) Equal(key, name) Equal(found, value) } -clause Lookup(map, name, found) +relation Lookup(map, name, found) ------------------------------- there { Equal(map, [[key, _value] | rest]) NotEqual(key, name) @@ -24,7 +24,7 @@ print find map limit 3 { // TODO We need to improve our search strategy // to make the following perform the same as the above. -clause LookupInlinedisj(map, name, found) +relation LookupInlinedisj(map, name, found) ------------------------------------ { Equal(map, [[key, value] | rest]) disj { diff --git a/docs/tests/relation/lookup-inline-disj.ch.out b/docs/examples/tests/relation/lookup-inline-disj.ch.out similarity index 100% rename from docs/tests/relation/lookup-inline-disj.ch.out rename to docs/examples/tests/relation/lookup-inline-disj.ch.out diff --git a/docs/tests/relation/multiset-arithmetic.ch b/docs/examples/tests/relation/multiset-arithmetic.ch similarity index 64% rename from docs/tests/relation/multiset-arithmetic.ch rename to docs/examples/tests/relation/multiset-arithmetic.ch index 294ad572..e57602d2 100644 --- a/docs/tests/relation/multiset-arithmetic.ch +++ b/docs/examples/tests/relation/multiset-arithmetic.ch @@ -1,47 +1,47 @@ // "A multiset approach to arithmetic" // https://www.youtube.com/watch?v=4xoF2SRp194 -clause Multiset([]) -clause Multiset([car | cdr]) -- { Multiset(car) Multiset(cdr) } +relation Multiset([]) +relation Multiset([car | cdr]) -- { Multiset(car) Multiset(cdr) } // print find x limit 10 { // Multiset(x) // } -clause Zero([]) +relation Zero([]) -clause Nat([]) -clause Nat([car | cdr]) -- { Zero(car) Nat(cdr) } +relation Nat([]) +relation Nat([car | cdr]) -- { Zero(car) Nat(cdr) } // print find x limit 10 { // Nat(x) // } -clause Poly([]) -clause Poly([car | cdr]) -- { Nat(car) Poly(cdr) } +relation Poly([]) +relation Poly([car | cdr]) -- { Nat(car) Poly(cdr) } // print find x limit 10 { // Poly(x) // } -clause Multi([]) -clause Multi([car | cdr]) -- { Poly(car) Multi(cdr) } +relation Multi([]) +relation Multi([car | cdr]) -- { Poly(car) Multi(cdr) } // print find x limit 10 { // Multi(x) // } -clause Append([], t, t) -clause Append([a | d], t, out) -- { +relation Append([], t, t) +relation Append([a | d], t, out) -- { Equal(out, [a | res]) Append(d, t, res) } -clause Add(x, y, z) -- { Append(x, y, z) } +relation Add(x, y, z) -- { Append(x, y, z) } -clause AddMany([], []) -clause AddMany([x], x) -clause AddMany([x, y | rest], out) -- { +relation AddMany([], []) +relation AddMany([x], x) +relation AddMany([x, y | rest], out) -- { Add(x, y, z) AddMany([z | rest], out) } @@ -57,9 +57,9 @@ clause AddMany([x, y | rest], out) -- { // AddMany(xs, out) // } -clause Product([], _, []) -clause Product([_x | _xs], [], []) -clause Product([x | xs], [y | ys], out) -- { +relation Product([], _, []) +relation Product([_x | _xs], [], []) +relation Product([x | xs], [y | ys], out) -- { Product([x], ys, xSide) Product(xs, [y], ySide) Product(xs, ys, body) @@ -80,13 +80,13 @@ print find q { Product([1, 2, 3], ["a", "b", "c"], q) } -clause AddPairs([], []) -clause AddPairs([[x, y] | ps], [z | res]) -- { +relation AddPairs([], []) +relation AddPairs([[x, y] | ps], [z | res]) -- { Add(x, y, z) AddPairs(ps, res) } -clause Mul(x, y, z) -- { +relation Mul(x, y, z) -- { Product(x, y, pairs) AddPairs(pairs, z) } @@ -105,9 +105,9 @@ print find [x, y, z] limit 10 { Mul(x, y, z) } -clause MulMany([], []) -clause MulMany([x], x) -clause MulMany([x, y | rest], out) -- { +relation MulMany([], []) +relation MulMany([x], x) +relation MulMany([x, y | rest], out) -- { Mul(x, y, z) MulMany([z | rest], out) } diff --git a/docs/tests/relation/multiset-arithmetic.ch.out b/docs/examples/tests/relation/multiset-arithmetic.ch.out similarity index 100% rename from docs/tests/relation/multiset-arithmetic.ch.out rename to docs/examples/tests/relation/multiset-arithmetic.ch.out diff --git a/docs/tests/relation/sat-clause.ch b/docs/examples/tests/relation/sat-clause.ch similarity index 60% rename from docs/tests/relation/sat-clause.ch rename to docs/examples/tests/relation/sat-clause.ch index 5b76b8d6..f759215e 100644 --- a/docs/tests/relation/sat-clause.ch +++ b/docs/examples/tests/relation/sat-clause.ch @@ -2,25 +2,25 @@ // for `false` and `true`, // because the code looks tidier. -clause Bit(x) -- { Equal(x, 0) } -clause Bit(x) -- { Equal(x, 1) } +relation Bit(x) -- { Equal(x, 0) } +relation Bit(x) -- { Equal(x, 1) } -clause Not(0, 1) -clause Not(1, 0) +relation Not(0, 1) +relation Not(1, 0) -clause Or(0, 0, 0) -clause Or(0, 1, 1) -clause Or(1, 0, 1) -clause Or(1, 1, 1) +relation Or(0, 0, 0) +relation Or(0, 1, 1) +relation Or(1, 0, 1) +relation Or(1, 1, 1) -clause BitList([]) -clause BitList([car | cdr]) -- { +relation BitList([]) +relation BitList([car | cdr]) -- { Bit(car) BitList(cdr) } -clause ListNot([], []) -clause ListNot([x | xs], [y | ys]) -- { +relation ListNot([], []) +relation ListNot([x | xs], [y | ys]) -- { Not(x, y) ListNot(xs, ys) } @@ -30,7 +30,7 @@ clause ListNot([x | xs], [y | ys]) -- { // which is equivalent to disjunction from // c1 ∨ c2 ∨ ... ¬p1 ∨ ¬p2 ∨ ... -clause Clause(conclusions, premises) -- { +relation Clause(conclusions, premises) -- { BitList(conclusions) BitList(premises) ListNot(premises, negPremises) @@ -41,13 +41,13 @@ clause Clause(conclusions, premises) -- { ContainsOne(disjunction) } -clause ContainsOne([1 | _rest]) -clause ContainsOne([0 | rest]) -- { +relation ContainsOne([1 | _rest]) +relation ContainsOne([0 | rest]) -- { ContainsOne(rest) } -clause Append([], t, t) -clause Append([a | d], t, [a | res]) -- { +relation Append([], t, t) +relation Append([a | d], t, [a | res]) -- { Append(d, t, res) } diff --git a/docs/tests/relation/sat-clause.ch.out b/docs/examples/tests/relation/sat-clause.ch.out similarity index 100% rename from docs/tests/relation/sat-clause.ch.out rename to docs/examples/tests/relation/sat-clause.ch.out diff --git a/docs/examples/tests/relation/sequencing-of-procedure-calls.ch b/docs/examples/tests/relation/sequencing-of-procedure-calls.ch new file mode 100644 index 00000000..5702fcf1 --- /dev/null +++ b/docs/examples/tests/relation/sequencing-of-procedure-calls.ch @@ -0,0 +1,35 @@ +// Example taken from Robert Kowalski's paper +// "Predicate logic as a programming language" +// Chapter "11. SEQUENCING OF PROCEDURE CALLS" + +// The point is that doing `Ord` before `Perm` +// is more efficient. + +// relation Sort(x, y) -- s1 { Perm(x, y) Ord(y) } +relation Sort(x, y) -- s1 { Ord(y) Perm(x, y) } +relation Perm([], []) -- s2 +relation Perm(z, [x | y]) -- s3 { Perm(z2, y) Del(x, z, z2) } +relation Del(x, [x | y], y) -- s4 +relation Del(x, [y | z], [y | z2]) -- s5 { Del(x, z, z2) } +relation Ord([]) -- s6 +relation Ord([_x]) -- s7 +relation Ord([x, y | z]) -- s8 { LE(x, y) Ord([y | z]) } +relation LE(1, 2) -- s9 +relation LE(1, 3) -- s10 +relation LE(2, 3) -- s11 +relation LE(x, x) -- s12 + +print find u limit 1 { + Sort([2, 1, 3], u) +} + +print find [x, y] limit 10 { + Sort(x, y) +} + +// The difference between performance +// become clear when we ask for 2000 answers. + +// print find [x, y] limit 2000 { +// Sort(x, y) +// } diff --git a/docs/tests/relation/sequencing-of-procedure-calls.ch.out b/docs/examples/tests/relation/sequencing-of-procedure-calls.ch.out similarity index 100% rename from docs/tests/relation/sequencing-of-procedure-calls.ch.out rename to docs/examples/tests/relation/sequencing-of-procedure-calls.ch.out diff --git a/docs/tests/term/my-list.ch b/docs/examples/tests/term/my-list.ch similarity index 82% rename from docs/tests/term/my-list.ch rename to docs/examples/tests/term/my-list.ch index 78a3abaf..8bbd9f21 100644 --- a/docs/tests/term/my-list.ch +++ b/docs/examples/tests/term/my-list.ch @@ -1,5 +1,5 @@ -clause List(List::Null()) -clause List(List::Cons(_head, tail)) -- { List(tail) } +relation List(List::Null()) +relation List(List::Cons(_head, tail)) -- { List(tail) } print find _ { List(List::Null()) diff --git a/docs/tests/term/my-list.ch.out b/docs/examples/tests/term/my-list.ch.out similarity index 100% rename from docs/tests/term/my-list.ch.out rename to docs/examples/tests/term/my-list.ch.out diff --git a/docs/tests/termination/always.ch b/docs/examples/tests/termination/always.ch similarity index 95% rename from docs/tests/termination/always.ch rename to docs/examples/tests/termination/always.ch index a0d661d1..10d50ebb 100644 --- a/docs/tests/termination/always.ch +++ b/docs/examples/tests/termination/always.ch @@ -1,5 +1,5 @@ -clause Always() -- base -clause Always() -- loop { Always() } +relation Always() -- base +relation Always() -- loop { Always() } print find _ limit 3 { Always() diff --git a/docs/tests/termination/always.ch.out b/docs/examples/tests/termination/always.ch.out similarity index 100% rename from docs/tests/termination/always.ch.out rename to docs/examples/tests/termination/always.ch.out diff --git a/docs/tests/termination/append.ch b/docs/examples/tests/termination/append.ch similarity index 84% rename from docs/tests/termination/append.ch rename to docs/examples/tests/termination/append.ch index 0c2702d1..308cd334 100644 --- a/docs/tests/termination/append.ch +++ b/docs/examples/tests/termination/append.ch @@ -1,6 +1,6 @@ -clause Append([], t, t) +relation Append([], t, t) -clause Append([a | d], t, out) +relation Append([a | d], t, out) ------------------------- { Append(d, t, res) Equal(out, [a | res]) @@ -19,9 +19,9 @@ print find [x, y] limit 6 { // We can avoid this problem if we swap the last two lines of `Append`. // "FF" means finite failure. -clause AppendFF([], t, t) +relation AppendFF([], t, t) -clause AppendFF([a | d], t, out) +relation AppendFF([a | d], t, out) -------------------------------------- { Equal(out, [a | res]) AppendFF(d, t, res) diff --git a/docs/tests/termination/append.ch.out b/docs/examples/tests/termination/append.ch.out similarity index 100% rename from docs/tests/termination/append.ch.out rename to docs/examples/tests/termination/append.ch.out diff --git a/docs/examples/tests/termination/never.ch b/docs/examples/tests/termination/never.ch new file mode 100644 index 00000000..17033e3e --- /dev/null +++ b/docs/examples/tests/termination/never.ch @@ -0,0 +1,23 @@ +relation Never(x) +--------- { + Never(x) +} + +relation OneTwoThreeThenNever(1) +relation OneTwoThreeThenNever(x) -- { Never(x) } +relation OneTwoThreeThenNever(2) +relation OneTwoThreeThenNever(x) -- { Never(x) } +relation OneTwoThreeThenNever(3) +relation OneTwoThreeThenNever(x) -- { Never(x) } + +// Ok: + +print find x limit 3 { + OneTwoThreeThenNever(x) +} + +// Loop forever: + +// print find x limit 4 { +// OneTwoThreeThenNever(x) +// } diff --git a/docs/tests/termination/never.ch.out b/docs/examples/tests/termination/never.ch.out similarity index 100% rename from docs/tests/termination/never.ch.out rename to docs/examples/tests/termination/never.ch.out diff --git a/docs/tests/unification/infix-notation-equal.ch b/docs/examples/tests/unification/infix-notation-equal.ch similarity index 100% rename from docs/tests/unification/infix-notation-equal.ch rename to docs/examples/tests/unification/infix-notation-equal.ch diff --git a/docs/tests/unification/infix-notation-equal.ch.out b/docs/examples/tests/unification/infix-notation-equal.ch.out similarity index 100% rename from docs/tests/unification/infix-notation-equal.ch.out rename to docs/examples/tests/unification/infix-notation-equal.ch.out diff --git a/docs/tests/unification/infix-notation-not-equal.ch b/docs/examples/tests/unification/infix-notation-not-equal.ch similarity index 100% rename from docs/tests/unification/infix-notation-not-equal.ch rename to docs/examples/tests/unification/infix-notation-not-equal.ch diff --git a/docs/tests/unification/infix-notation-not-equal.ch.out b/docs/examples/tests/unification/infix-notation-not-equal.ch.out similarity index 100% rename from docs/tests/unification/infix-notation-not-equal.ch.out rename to docs/examples/tests/unification/infix-notation-not-equal.ch.out diff --git a/docs/tests/unification/occur-check.ch b/docs/examples/tests/unification/occur-check.ch similarity index 100% rename from docs/tests/unification/occur-check.ch rename to docs/examples/tests/unification/occur-check.ch diff --git a/docs/tests/unification/occur-check.ch.out b/docs/examples/tests/unification/occur-check.ch.out similarity index 100% rename from docs/tests/unification/occur-check.ch.out rename to docs/examples/tests/unification/occur-check.ch.out diff --git a/docs/std/list/Append.ch b/docs/std/list/Append.ch deleted file mode 100644 index 13b3a14b..00000000 --- a/docs/std/list/Append.ch +++ /dev/null @@ -1,6 +0,0 @@ -export { Append } - -clause Append([], l, l) -clause Append([a | d], l, [a | r]) -- { - Append(d, l, r) -} diff --git a/docs/std/nat/Nat.ch b/docs/std/nat/Nat.ch deleted file mode 100644 index 3f1ebbf4..00000000 --- a/docs/std/nat/Nat.ch +++ /dev/null @@ -1,7 +0,0 @@ -export { Nat, Zero, Add1 } - -clause Nat(Nat::Zero()) -clause Nat(Nat::Add1(prev)) -- { Nat(prev) } - -clause Zero(Nat::Zero()) -clause Add1(prev, Nat::Add1(prev)) diff --git a/docs/std/nat/numbers.ch b/docs/std/nat/numbers.ch deleted file mode 100644 index 46729ce2..00000000 --- a/docs/std/nat/numbers.ch +++ /dev/null @@ -1,14 +0,0 @@ -import { Zero, Add1 } from "Nat.ch" - -export clause One(n) -- { Add1(prev, n) Zero(prev) } -export clause Two(n) -- { Add1(prev, n) One(prev) } -export clause Three(n) -- { Add1(prev, n) Two(prev) } -export clause Four(n) -- { Add1(prev, n) Three(prev) } -export clause Five(n) -- { Add1(prev, n) Four(prev) } -export clause Six(n) -- { Add1(prev, n) Five(prev) } -export clause Seven(n) -- { Add1(prev, n) Six(prev) } -export clause Eight(n) -- { Add1(prev, n) Seven(prev) } -export clause Nine(n) -- { Add1(prev, n) Eight(prev) } -export clause Ten(n) -- { Add1(prev, n) Nine(prev) } -export clause Eleven(n) -- { Add1(prev, n) Ten(prev) } -export clause Twelve(n) -- { Add1(prev, n) Eleven(prev) } diff --git a/docs/std/trilean/Trilean.ch b/docs/std/trilean/Trilean.ch deleted file mode 100644 index 1d3421f9..00000000 --- a/docs/std/trilean/Trilean.ch +++ /dev/null @@ -1,62 +0,0 @@ -// Use logic programming to play with many-valued logic. - -clause Trilean(0) -clause Trilean(0.5) -clause Trilean(1) - -// Name of the three values: - -clause TrileanFalse(0) -clause TrileanMiddle(0.5) -clause TrileanTrue(1) - -clause TrileanMin(0, 0, 0) -clause TrileanMin(0, 0.5, 0) -clause TrileanMin(0, 1, 0) -clause TrileanMin(0.5, 0, 0) -clause TrileanMin(0.5, 0.5, 0.5) -clause TrileanMin(0.5, 1, 0.5) -clause TrileanMin(1, 0, 0) -clause TrileanMin(1, 0.5, 0.5) -clause TrileanMin(1, 1, 1) - -clause TrileanMax(0, 0, 0) -clause TrileanMax(0, 0.5, 0.5) -clause TrileanMax(0, 1, 1) -clause TrileanMax(0.5, 0, 0.5) -clause TrileanMax(0.5, 0.5, 0.5) -clause TrileanMax(0.5, 1, 1) -clause TrileanMax(1, 0, 1) -clause TrileanMax(1, 0.5, 1) -clause TrileanMax(1, 1, 1) - -clause TrileanPositive(0.5) -clause TrileanPositive(1) - -// Use mutually exclusive cases. - -clause TrileanMul(0, y, 0) -- { Trilean(y) } -clause TrileanMul(x, 0, 0) -- { TrileanPositive(x) } -clause TrileanMul(x, y, z) -- { - TrileanPositive(x) - TrileanPositive(y) - TrileanMax(x, y, z) -} - -// See how `TrileanMax` is different from `TrileanMul`: - -print find [x, y, z] { TrileanMax(x, y, z) } -print find [x, y, z] { TrileanMul(x, y, z) } - -// What returns 0? -print find [x, y] { TrileanMul(x, y, 0) } - -// [question] Can `TrileansMul` be defined by -// composition of other connectives (not, min, max)? -// Does this means to use only one clause? - -// [question] How to search high-order things -// like connective in logic programming? -// We want to search how to construct truth function -// by composition of given set of connectives. -// Maybe we must define first order expressions first. diff --git a/docs/tests/conventions/relation-arity-mismatch.error.ch b/docs/tests/conventions/relation-arity-mismatch.error.ch deleted file mode 100644 index 1c43f45f..00000000 --- a/docs/tests/conventions/relation-arity-mismatch.error.ch +++ /dev/null @@ -1,2 +0,0 @@ -clause F(1) -clause F(1, 2) diff --git a/docs/tests/conventions/relation-name-must-starts-with-uppercase.error.ch b/docs/tests/conventions/relation-name-must-starts-with-uppercase.error.ch deleted file mode 100644 index caf26d2b..00000000 --- a/docs/tests/conventions/relation-name-must-starts-with-uppercase.error.ch +++ /dev/null @@ -1 +0,0 @@ -clause border("sussex", "kent") diff --git a/docs/tests/conventions/relation-name-must-starts-with-uppercase.error.ch.err b/docs/tests/conventions/relation-name-must-starts-with-uppercase.error.ch.err deleted file mode 100644 index e5b356f2..00000000 --- a/docs/tests/conventions/relation-name-must-starts-with-uppercase.error.ch.err +++ /dev/null @@ -1,14 +0,0 @@ -I found syntax error in code: - - 1 |clause border("sussex", "kent") - 2 | - - -Found the identifier "border" in [7, 13], while expecting: - ["identifier"]: - stmt:clause_no_goals_no_name@0 -> "clause"@1 > (name: identifier) (args: args) - ["identifier"]: - stmt:clause_no_goals@0 -> "clause"@1 > (name: identifier) (args: args) dashline (clause_name: identifier) - ["identifier"]: - stmt:clause_no_name@0 -> "clause"@1 > (name: identifier) (args: args) dashline "{" (goals: goals) "}" - and so on ... diff --git a/docs/tests/module/example.ch b/docs/tests/module/example.ch deleted file mode 100644 index bfbd4866..00000000 --- a/docs/tests/module/example.ch +++ /dev/null @@ -1,5 +0,0 @@ -export clause Hello("Hello, World!") - -export clause Hi("Hi there!") - -clause Hiya("Hiya!") diff --git a/docs/tests/relation/datom.ch b/docs/tests/relation/datom.ch deleted file mode 100644 index 3a94878e..00000000 --- a/docs/tests/relation/datom.ch +++ /dev/null @@ -1,9 +0,0 @@ -clause Datom(1, "name", "A") -clause Datom(1, "age", 45) -clause Datom(2, "name", "X") -clause Datom(2, "age", 2) - -print find n { - Datom(e, "age", 2) - Datom(e, "name", n) -} diff --git a/docs/tests/relation/sequencing-of-procedure-calls.ch b/docs/tests/relation/sequencing-of-procedure-calls.ch deleted file mode 100644 index d9b22840..00000000 --- a/docs/tests/relation/sequencing-of-procedure-calls.ch +++ /dev/null @@ -1,35 +0,0 @@ -// Example taken from Robert Kowalski's paper -// "Predicate logic as a programming language" -// Chapter "11. SEQUENCING OF PROCEDURE CALLS" - -// The point is that doing `Ord` before `Perm` -// is more efficient. - -// clause Sort(x, y) -- s1 { Perm(x, y) Ord(y) } -clause Sort(x, y) -- s1 { Ord(y) Perm(x, y) } -clause Perm([], []) -- s2 -clause Perm(z, [x | y]) -- s3 { Perm(z2, y) Del(x, z, z2) } -clause Del(x, [x | y], y) -- s4 -clause Del(x, [y | z], [y | z2]) -- s5 { Del(x, z, z2) } -clause Ord([]) -- s6 -clause Ord([_x]) -- s7 -clause Ord([x, y | z]) -- s8 { LE(x, y) Ord([y | z]) } -clause LE(1, 2) -- s9 -clause LE(1, 3) -- s10 -clause LE(2, 3) -- s11 -clause LE(x, x) -- s12 - -print find u limit 1 { - Sort([2, 1, 3], u) -} - -print find [x, y] limit 10 { - Sort(x, y) -} - -// The difference between performance -// become clear when we ask for 2000 answers. - -// print find [x, y] limit 2000 { -// Sort(x, y) -// } diff --git a/docs/tests/termination/never.ch b/docs/tests/termination/never.ch deleted file mode 100644 index 5718a4b3..00000000 --- a/docs/tests/termination/never.ch +++ /dev/null @@ -1,23 +0,0 @@ -clause Never(x) ---------- { - Never(x) -} - -clause OneTwoThreeThenNever(1) -clause OneTwoThreeThenNever(x) -- { Never(x) } -clause OneTwoThreeThenNever(2) -clause OneTwoThreeThenNever(x) -- { Never(x) } -clause OneTwoThreeThenNever(3) -clause OneTwoThreeThenNever(x) -- { Never(x) } - -// Ok: - -print find x limit 3 { - OneTwoThreeThenNever(x) -} - -// Loop forever: - -// print find x limit 4 { -// OneTwoThreeThenNever(x) -// } diff --git a/src/lang/globals/aboutBoolean.ts b/src/lang/globals/aboutBoolean.ts index eab10488..54efa4ec 100644 --- a/src/lang/globals/aboutBoolean.ts +++ b/src/lang/globals/aboutBoolean.ts @@ -5,8 +5,8 @@ import type { GlobalStore } from "./GlobalStore.js" export function aboutBoolean(globals: GlobalStore): void { globals.code(` -clause Boolean(x) -- { Equal(x, false) } -clause Boolean(x) -- { Equal(x, true) } +relation Boolean(x) -- { Equal(x, false) } +relation Boolean(x) -- { Equal(x, true) } `) } diff --git a/src/lang/globals/aboutNull.ts b/src/lang/globals/aboutNull.ts index db0a652d..fc587d27 100644 --- a/src/lang/globals/aboutNull.ts +++ b/src/lang/globals/aboutNull.ts @@ -3,7 +3,7 @@ import type { GlobalStore } from "./GlobalStore.js" export function aboutNull(globals: GlobalStore): void { globals.code(` -clause Null(x) -- { Equal(x, null) } +relation Null(x) -- { Equal(x, null) } `) } diff --git a/src/lang/syntax/grammars/stmt.ts b/src/lang/syntax/grammars/stmt.ts index 984e1635..99973be8 100644 --- a/src/lang/syntax/grammars/stmt.ts +++ b/src/lang/syntax/grammars/stmt.ts @@ -1,19 +1,19 @@ export const stmt = { $grammar: { "stmt:clause_no_goals_no_name": [ - '"clause"', + '"relation"', { name: "relation_name" }, { args: "args" }, ], "stmt:clause_no_goals": [ - '"clause"', + '"relation"', { name: "relation_name" }, { args: "args" }, "dashline", { clause_name: "clause_name" }, ], "stmt:clause_no_name": [ - '"clause"', + '"relation"', { name: "relation_name" }, { args: "args" }, "dashline", @@ -22,7 +22,7 @@ export const stmt = { '"}"', ], "stmt:clause": [ - '"clause"', + '"relation"', { name: "relation_name" }, { args: "args" }, "dashline", diff --git a/src/test.ts b/src/test.ts index ec202e16..9176f196 100644 --- a/src/test.ts +++ b/src/test.ts @@ -9,8 +9,8 @@ import { stripAnsi } from "./utils/ansi.js" const __filename = fileURLToPath(import.meta.url) const __dirname = Path.dirname(__filename) -test("snapshot docs/**/*.ch", async () => { - const files = await glob(`${__dirname}/../docs/**/*.ch`) +test("snapshot docs/examples/**/*.ch", async () => { + const files = await glob(`${__dirname}/../docs/examples/**/*.ch`) for (const file of files) { if (file.endsWith(".error.ch")) { await snapshotError(new URL(`file:${file}`))