Coding in yscript

tags
yscript

Notes

Chapter 1: Introduction

NOTER_PAGE: (13 . 0.09801409352978858)

yscript1 (pronounced ‘why-script’) is a computer language for representing and manipulating propositions.

NOTER_PAGE: (13 . 0.15118513773222292)

When yscript code is executed, it results in a dialog or consultation.

NOTER_PAGE: (13 . 0.2338244714926329)

develop a form of representation that looked as much like natural language as possible.

NOTER_PAGE: (13 . 0.36707238949391413)

yscript code consists of rules that deal with facts.

NOTER_PAGE: (13 . 0.5188981422165279)

case-based reasoning

NOTER_PAGE: (13 . 0.6707238949391415)

yscript applications can generate documents

NOTER_PAGE: (13 . 0.689301729660474)

directly adopt the wording of a set of rules that you are trying to represent.

NOTER_PAGE: (14 . 0.16015374759769377)

isomorphism (that is, one- to-mapping) of real-word rules into yscript code

NOTER_PAGE: (14 . 0.27738629083920563)

A major environment that uses yscript is AustLII’s DataLex platform

NOTER_PAGE: (14 . 0.39461883408071746)

Chapter 2: Getting Started

NOTER_PAGE: (17 . 0.09673286354900704)

Chapter 3: Syntax, Types, Constants and Expressions

NOTER_PAGE: (25 . 0.09865470852017937)

very limited use of non-alphanumeric symbols.

NOTER_PAGE: (25 . 0.3196668802049968)

characters such as ‘=’, ‘+’ or ‘&’ have no special meaning

NOTER_PAGE: (25 . 0.32222934016655985)

keyword is a reserved term that is always written in upper case

NOTER_PAGE: (25 . 0.35618193465727094)

A descriptor is a sequence of letters and symbols that does not include a keyword and is used to refer to a constant, fact or text.

NOTER_PAGE: (25 . 0.7200512491992312)

Sequences of blanks (spaces, tabs, and newlines) containing more than one newline character are treated as a single newline. All other blank sequences are processed as though they were a single space.

NOTER_PAGE: (26 . 0.0903267136450993)

Upper and lower case is significant.

NOTER_PAGE: (26 . 0.12620115310698268)

Text may optionally be enclosed in single or double quotes.

NOTER_PAGE: (26 . 0.16143497757847533)

may be escaped by preceding it with a backslash

NOTER_PAGE: (26 . 0.2575272261370916)

Multi-line comments are introduced with the characters /* and finish with */

NOTER_PAGE: (27 . 0.17680973734785393)

comments nest

NOTER_PAGE: (27 . 0.19538757206918642)

You can also use C++ style single line // comments.

NOTER_PAGE: (27 . 0.32799487508007685)

Facts are dynamically typed and only need to be formally declared if their type is not implicit from their usage.

NOTER_PAGE: (27 . 0.5118513773222293)

special type of facts called - named subjects

NOTER_PAGE: (27 . 0.5470852017937219)

The basic types and associated constant forms

NOTER_PAGE: (29 . 0.09288917360666239)

GENDER facts may refer to any string value.

NOTER_PAGE: (29 . 0.6886611146700833)

god bless

A MONEY value cannot be associated with a non-currency unit

NOTER_PAGE: (30 . 0.11467008327994874)

The DATE type is used to refer to calendar dates.

NOTER_PAGE: (30 . 0.1832158872517617)

supported range of years is from AD 1 to 9999

NOTER_PAGE: (30 . 0.42280589365791155)

good practice to use a date format with a non-numerical month

NOTER_PAGE: (30 . 0.472773862908392)

TIME type is used to refer to time.

NOTER_PAGE: (30 . 0.600896860986547)

Numbers can be written in a variety of formats.

NOTER_PAGE: (31 . 0.25048046124279305)

Facts and constants with a numerical value can be associated with a unit of measurement or an international currency.

NOTER_PAGE: (31 . 0.7738629083920563)

An expression consists of fact or constant references, connected by operators.

NOTER_PAGE: (35 . 0.6841768097373478)

The PLUS and MINUS expression operators can be used to perform date arithmetic.

NOTER_PAGE: (40 . 0.30301089045483665)

where the day falls on the last day of the month, the resulting date will fall on the last day of the month

NOTER_PAGE: (40 . 0.4247277386290839)

Times are stored as the number of seconds since midnight in local time.

NOTER_PAGE: (41 . 0.14285714285714285)

The value of all facts and constants is stored in base-unit format.

NOTER_PAGE: (42 . 0.12235746316463804)

Chapter 4: Facts

NOTER_PAGE: (45 . 0.1005765534913517)

Facts are used to hold a value during execution and are referred to by a descriptor that is not a constant and that is not text.

NOTER_PAGE: (45 . 0.14606021780909673)

Facts cannot be declared as being local to a rule or procedure and are accessible from all rules in the context.

NOTER_PAGE: (46 . 0.10634208840486867)

yscript code generally involves manipulating facts in propositional form.

NOTER_PAGE: (46 . 0.21524663677130043)

this is one of the very interesting things about yscript to me - no predicate logic! comes with important limitations, of course, but the authors seem satisfied with it, and explicitly disavow predicates

fact names are also used to build elements of English dialogs

NOTER_PAGE: (46 . 0.35169762972453555)

information can be treated symbolically but with no requirement to provide a separate textual representation

NOTER_PAGE: (46 . 0.3843689942344651)

yscript uses a light-weight natural language parser

NOTER_PAGE: (46 . 0.5028827674567584)

heuristic rules that identify different parts of speech based around generally used word forms

NOTER_PAGE: (46 . 0.6931454196028186)

Before a fact is assigned a value or one is provided by the user, the fact value is unknown.

NOTER_PAGE: (54 . 0.38565022421524664)

FACT declaration can include a RANGE restriction.

NOTER_PAGE: (54 . 0.6925048046124279)

representation as contained in facts in the code to be different from the text that is used to communicate with the user.

NOTER_PAGE: (56 . 0.675208199871877)

Explanations are text descriptions that add further explanation about a fact

NOTER_PAGE: (61 . 0.6137091607943626)

Aliases are also used in document assembly and provide a way to specify a short name for a fact as used in document templates.

NOTER_PAGE: (63 . 0.43754003843689937)

Rules and facts within each context have their own separate namespace.

NOTER_PAGE: (64 . 0.30301089045483665)

if identically named facts or rules exist in two or more contexts, all are treated as referring to different facts.

NOTER_PAGE: (64 . 0.33568225496476617)

Chapter 5: Statements

NOTER_PAGE: (67 . 0.09865470852017937)

Assignments are used to set the value of a fact

NOTER_PAGE: (67 . 0.3267136450992953)

One of the side-effects of assignments is that they associate facts that are used to calculate the assigned value, as reasons

NOTER_PAGE: (68 . 0.09417040358744394)

Chapter 6: Rules

NOTER_PAGE: (75 . 0.09887640449438202)

Once the goal rule has started execution (or has been fired), the rule statements are executed in order.

NOTER_PAGE: (75 . 0.2404494382022472)

Rule names are in a different namespace from fact names

NOTER_PAGE: (76 . 0.21123595505617979)

explanation as to how each of these facts was determined

NOTER_PAGE: (77 . 0.6696629213483146)

Where the goal rule does not determine the value of any facts, the report will explain all determined facts in reverse order

NOTER_PAGE: (78 . 0.3962546816479401)

yscript will normally fire each rule in the order that they were declared

NOTER_PAGE: (78 . 0.4966292134831461)

The order in which rules are fired can be explicitly set

NOTER_PAGE: (78 . 0.5970037453183521)

Is this yscript's best defeasibility mechanism?

yscript is a declarative language. The order of execution is normally driven by goal-directed backward chaining or result-directed forward firing of rules. Rules and expressions themselves, however, are imperative.

NOTER_PAGE: (79 . 0.6704119850187266)

The rules engine will block attempts by rules to invoke themselves to stop loops and infinite recursion.

NOTER_PAGE: (79 . 0.8074906367041199)

interesting, recursion explicitly disallowed

executed from the starting rule to re-establish the current state and to use any new information

NOTER_PAGE: (80 . 0.09737827715355805)

When a CALL or NEXT statement attempts to execute a rule that is already being executed, the interpreter will automatically call FORGET to bring the system back to the state that it was in when the rule was originally called. The effect of this is that it is always safe to use CALL or NEXT to invoke any rule, and if necessary, the system will backtrack to produce a sensible result.

NOTER_PAGE: (81 . 0.3692883895131086)

a fact effectively becomes a very simple object in the sense that it can hold a value and that it also has associated code.

NOTER_PAGE: (82 . 0.42846441947565544)

Chapter 7: Examples

NOTER_PAGE: (85 . 0.09363295880149813)

yscript also supports simple analogous reasoning

NOTER_PAGE: (85 . 0.14756554307116104)

When yscript is trying to infer a value for a fact and no further rules can be found to assist, it will look to see if the fact is contained in an example set.

NOTER_PAGE: (85 . 0.2913857677902622)

Chapter 8: Document Assembly

NOTER_PAGE: (91 . 0.10037453183520599)

Chapter 9: Style Guide

NOTER_PAGE: (105 . 0.10262172284644196)

Relying upon the order of rule execution can lead to code that is cryptic and difficult to understand.

NOTER_PAGE: (105 . 0.8262172284644195)

Appendix 1: Units, Currencies and Time Zones

NOTER_PAGE: (107 . 0.10112359550561797)

Appendix 2: The cyscript Interpreter

NOTER_PAGE: (117 . 0.099625468164794)

1. Usage

NOTER_PAGE: (117 . 0.24794007490636705)

The -x flag produces a fact cross-reference.

NOTER_PAGE: (121 . 0.4958801498127341)

2. Interactive Sessions

NOTER_PAGE: (122 . 0.2052434456928839)

Appendix 3: yscript 2.x Language Changes

NOTER_PAGE: (143 . 0.09662921348314607)

Appendix 4: Formal Grammar

NOTER_PAGE: (151 . 0.099625468164794)

Appendix 5: The yscript API

NOTER_PAGE: (153 . 0.09588014981273409)

Appendix 6: Using cyscript as a Server

NOTER_PAGE: (161 . 0.09438202247191012)

Appendix 7: yscript Code Examples

NOTER_PAGE: (171 . 0.10112359550561797)

1. Commonwealth Constitution s44

NOTER_PAGE: (171 . 0.15205992509363297)

2. Modern Slavery Act 2018 (Cth)

NOTER_PAGE: (175 . 0.08764044943820225)

3. Community Gaming Regulations 2020 (NSW)

NOTER_PAGE: (191 . 0.08838951310861423)

Index

NOTER_PAGE: (211 . 0.10786516853932585)