-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequirements.txt
More file actions
185 lines (121 loc) · 5.38 KB
/
Copy pathRequirements.txt
File metadata and controls
185 lines (121 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
Requirements Document: Starlog-in-Prolog Repository
1. Purpose
Create a new SWI-Prolog repository that lets a developer write Starlog syntax directly inside normal .pl files and run it immediately, without converting files.
The repository must support Starlog’s “value-returning” style using is (e.g., C is A:B) and operator syntax (:, &, •), while transparently expanding it into equivalent Prolog goals at load-time (or goal-call-time).
2. Scope
In scope
• Direct entry of Starlog goals in Prolog source files.
• Automatic expansion of Starlog “is-expressions” into normal Prolog predicates.
• Optional decompression of nested expressions into sequential goals (like your decompressor).
• Compatibility with SWI-Prolog module system and normal Prolog code.
Out of scope (v1)
• Full Starlog parser independent of Prolog reader.
• Cross-file conversion CLI (that’s the old workflow).
• Supporting every Prolog predicate as a value-returning function (limit to a defined builtin table + extensibility hooks).
3. Target Environment
• SWI-Prolog 8.x+.
• Must work in both:
• interactive queries (?- ...)
• loaded modules/files (consult/1, use_module/1)
4. User Stories
1. As a developer, I want to write:
E is •(A:(B:(D•F)), C),
and have it behave as if I wrote a sequence of string_concat/3 + atom_concat/3 calls.
2. As a developer, I want to write:
X is A & B
and have it execute append(A,B,X).
3. As a developer, I want Starlog syntax to coexist with ordinary Prolog in the same file, without special file suffixes.
5. Core Syntax Requirements
5.1 Operators
The library must define Starlog operators (configurable, but these defaults):
:- op(700, xfx, is). % keep Prolog’s is token, but treat as Starlog in specific patterns
:- op(600, yfx, ':'). % string concat expression form
:- op(600, yfx, '&'). % list append expression form
:- op(600, yfx, '•'). % atom concat expression form
5.2 Allowed Starlog “is” Forms (v1)
The expander must recognize and rewrite these patterns in goal position:
• Out is (A : B) → string_concat(A,B,Out)
• Out is (A & B) → append(A,B,Out)
• Out is (A • B) → atom_concat(A,B,Out)
• Out is string_length(A) → string_length(A,Out)
• Out is atom_length(A) → atom_length(A,Out)
• Out is number_string(A) → number_string(A,Out)
• etc. (extendable table)
5.3 Nested Expressions
Nested expressions like:
E is •(A:(B:(D•F)), C)
must be supported by expanding into a safe execution order using fresh temporaries, e.g.:
atom_concat(D, F, T1),
string_concat(B, T1, T2),
string_concat(A, T2, T3),
atom_concat(T3, C, E).
6. Expansion Mechanism Requirements
6.1 Primary mechanism
Implement Starlog-in-Prolog using goal expansion and/or term expansion:
• goal_expansion/2 for bodies of clauses.
• term_expansion/2 for rewriting whole clauses when needed.
6.2 Where expansion applies
Expansion must apply to:
• clause bodies: Head :- Body
• directives :- Goal (optional but strongly desired)
• interactive use: provide a helper predicate starlog_call/1 so users can do:
?- starlog_call(A is [1]:[2]).
and have it expanded then executed.
6.3 Safety rule
Do not rewrite standard arithmetic is/2 unless the RHS matches Starlog expression patterns or registered Starlog value-builtin patterns.
Example:
• Keep: X is Y+1 as arithmetic.
• Rewrite: X is A:B as string_concat/3.
7. Extensibility Requirements
7.1 Registering new value-builtin mappings
Provide an API to register new “value-returning” predicate expansions, e.g.:
:- starlog_register_value_builtin(foo/2, foo). % meaning: Out is foo(A,B) -> foo(A,B,Out)
or a more explicit mapping form.
7.2 Operator set configuration
Allow users to opt-in/out of operators (especially if : conflicts with other code).
8. Diagnostics & Debugging
• Provide a flag like starlog_debug(true/false).
• When enabled, print:
• original Starlog goal
• expanded Prolog goal list
• temp vars introduced (optionally)
9. Non-Functional Requirements
• Must not break normal module loading.
• Must preserve determinism characteristics as much as possible.
• Must avoid rewriting inside quoted terms unless explicitly requested.
• Must be robust: if a pattern isn’t recognized, leave it unchanged.
10. Repository Layout Requirements
starlog/
README.md
LICENSE (BSD-3)
starlog.pl % main library module
starlog_expand.pl % expander: compile Starlog -> list of Prolog goals
starlog_registry.pl % builtin mapping registry + user extension hooks
tests/
test_basic.pl
test_nested.pl
test_arithmetic_is.pl
test_mixed_prolog_starlog.pl
11. Acceptance Tests
1. Direct Starlog concat
• Input:
t(A) :- A is "x":"y".
• Behavior: t(A) yields "xy".
2. List append
• Input:
t(A) :- A is [1] & [2].
• Behavior: t([1,2]).
3. Nested expression decompression
• Input:
t(E) :- E is •("a":"b", "c").
• Behavior: E == 'abc' (or "abc" depending on atom/string choices).
4. Arithmetic is preserved
• Input:
t(X) :- X is 1+2.
• Behavior: X = 3 and no Starlog rewriting occurs.
12. README Requirements
README must include:
• “Quick start” example showing Starlog in a normal .pl file.
• Explanation of when is/2 is treated as Starlog vs arithmetic.
• How to call starlog_call/1 in the REPL for direct typing.
• List of builtins supported by default and how to add more.