Download Jar. Libraryless. Click here for Pure Java version (7087L/50K).
1 | !7 |
2 | |
3 | replace SimpleStatements with MatchableRecords<Prop>. |
4 | replace Env with SimpleStatements. |
5 | |
6 | abstract sclass Prop implements IFieldsToList {} |
7 | |
8 | static withToList record Did$HappenBefore$<A, B>(A event1, B event2) {} |
9 | static withToList record WhenDid$Happen(O event) extends Prop {} |
10 | static withToList record $HappensAtSecond$<A, B>(A event, B y) extends Prop {} |
11 | |
12 | static O answer(Env env, O p) { |
13 | if p is WhenDid$Happen(O event) |
14 | ret env.fulfillVariable(var -> $HappensAtSecond$(event, var)); |
15 | |
16 | if p is Did$HappenBefore$(O event1, O event2) once { |
17 | Int time1 = opt cast answer(env, WhenDid$Happen(event1)); |
18 | if (time1 == null) break; |
19 | Int time2 = opt cast answer(env, WhenDid$Happen(event2)); |
20 | if (time2 == null) break; |
21 | ret time1 < time2; |
22 | } |
23 | |
24 | null; |
25 | } |
26 | |
27 | p-exp { |
28 | SimpleStatements env = new( |
29 | $HappensAtSecond$("stuff", 10), |
30 | $HappensAtSecond$("more stuff", 20)); |
31 | |
32 | assertEqualsVerbose(true, answer(env, print(Did$HappenBefore$("stuff", "more stuff")))); |
33 | assertEqualsVerbose(false, answer(env, print(Did$HappenBefore$("more stuff", "stuff")))); |
34 | assertEqualsVerbose(null, answer(env, print(Did$HappenBefore$("stuff", "any other stuff")))); |
35 | } |
Began life as a copy of #1025429
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, mqqgnosmbjvj, omdjrrnzbjjv, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1025431 |
Snippet name: | Propositions to objects, step 5 - multi-step procedure (OK) |
Eternal ID of this version: | #1025431/9 |
Text MD5: | 9958b974e288dba86191e92932809213 |
Transpilation MD5: | d84a146db582308e8cf839e0d8e771df |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-09-29 00:20:23 |
Source code size: | 1206 bytes / 35 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 300 / 943 |
Version history: | 8 change(s) |
Referenced in: | [show references] |