Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

35
LINES

< > BotCompany Repo | #1025431 - Propositions to objects, step 5 - multi-step procedure (OK)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (7087L/50K).

!7

replace SimpleStatements with MatchableRecords<Prop>.
replace Env with SimpleStatements.

abstract sclass Prop implements IFieldsToList {}

static withToList record Did$HappenBefore$<A, B>(A event1, B event2) {}
static withToList record WhenDid$Happen(O event) extends Prop {}
static withToList record $HappensAtSecond$<A, B>(A event, B y) extends Prop {}

static O answer(Env env, O p) {
  if p is WhenDid$Happen(O event)
    ret env.fulfillVariable(var -> $HappensAtSecond$(event, var));

  if p is Did$HappenBefore$(O event1, O event2) once {
    Int time1 = opt cast answer(env, WhenDid$Happen(event1));
    if (time1 == null) break;
    Int time2 = opt cast answer(env, WhenDid$Happen(event2));
    if (time2 == null) break;
    ret time1 < time2;
  }
  
  null;
}

p-exp {
  SimpleStatements env = new(
    $HappensAtSecond$("stuff", 10),
    $HappensAtSecond$("more stuff", 20));

  assertEqualsVerbose(true, answer(env, print(Did$HappenBefore$("stuff", "more stuff"))));
  assertEqualsVerbose(false, answer(env, print(Did$HappenBefore$("more stuff", "stuff"))));
  assertEqualsVerbose(null, answer(env, print(Did$HappenBefore$("stuff", "any other stuff"))));
}

Author comment

Began life as a copy of #1025429

download  show line numbers  debug dex   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, omdjrrnzbjjv, onxytkatvevr, pzhvpgtvlbxg, tvejysmllsmz

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: 54 / 132
Version history: 8 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1025431 & http://1025431.tinybrain.de