public static void cacheGoal(ControlFrame frame, boolean successP, boolean keepframeP, int clockticks) {
    keepframeP = keepframeP;
    if (frame.state == Logic.KWD_ATOMIC_GOAL) {
      if (frame.goalBindings == null) {
        return;
      }
      { Stella_Object binding = null;
        Cons iter000 = frame.goalBindings;

        for (;!(iter000 == Stella.NIL); iter000 = iter000.rest) {
          binding = iter000.value;
          if (binding != null) {
            if (Surrogate.subtypeOfP(Stella_Object.safePrimaryType(binding), Logic.SGT_LOGIC_DESCRIPTION)) {
              { Description binding000 = ((Description)(binding));

                if (((Vector)(KeyValueList.dynamicSlotValue(binding000.dynamicSlots, Logic.SYM_LOGIC_EXTERNAL_VARIABLES, null))) != null) {
                  return;
                }
              }
            }
            else {
            }
          }
        }
      }
      if (successP) {
        frame.dontCacheGoalFailureP = true;
      }
      if (frame.cachedGoalResultP) {
        return;
      }
      if (((clockticks - frame.startingClockTicks) >= Logic.$CACHE_GOAL_QUANTUM$) ||
          (false &&
           Logic.testPropertyP(Logic.surrogateToDescription(((Surrogate)(frame.proposition.operator))), Logic.SGT_PL_KERNEL_KB_FRAME_PREDICATE))) {
        { Keyword testValue000 = frame.proposition.kind;

          if ((testValue000 == Logic.KWD_ISA) ||
              ((testValue000 == Logic.KWD_PREDICATE) ||
               (testValue000 == Logic.KWD_FUNCTION))) {
            if (Stella.getQuotedTree("((/PL-KERNEL-KB/@FORK /PL-KERNEL-KB/@COLLECT-INTO-SET) \"/LOGIC\")", "/LOGIC").memberP(frame.proposition.operator)) {
              return;
            }
            if (Stella_Object.traceKeywordP(Logic.KWD_GOAL_CACHES)) {
              System.out.println("=========> CACHED " + ((successP ? "SUCCESS" : "FAILURE")) + " AT " + (((ControlFrame.goalHashCode(frame)) & 0x7FFFFFFF) % 1541) + ": " + frame.proposition);
            }
            Logic.updateNowTimestamp(Logic.KWD_EXECUTE_QUERY);
            KeyValueList.setDynamicSlotValue(Logic.surrogateToDescription(((Surrogate)(frame.proposition.operator))).dynamicSlots, Logic.SYM_LOGIC_CHECK_FOR_CACHED_GOALSp, Stella.TRUE_WRAPPER, Stella.FALSE_WRAPPER);
            { int index = Stella.NULL_INTEGER;
              AtomicGoalCache cachedgoal = null;

              if (successP) {
                if (!Logic.$CACHE_SUCCEEDED_GOALSp$) {
                  return;
                }
                index = (((ControlFrame.goalHashCode(frame)) & 0x7FFFFFFF) % 1541);
                cachedgoal = ((AtomicGoalCache)((Logic.$SUCCEEDED_GOALS_CACHE$.theArray)[index]));
                if ((cachedgoal == null) ||
                    ((!AtomicGoalCache.cacheMatchesGoalP(cachedgoal, frame, true, Logic.KWD_GOAL_INSTANTIATES_CACHE)) ||
                     (((Boolean)(Logic.$RECORD_JUSTIFICATIONSp$.get())).booleanValue() &&
                      (cachedgoal.justification == null)))) {
                  (Logic.$SUCCEEDED_GOALS_CACHE$.theArray)[index] = (ControlFrame.createAtomicGoalCache(frame, cachedgoal, true));
                }
                else if (cachedgoal != null) {
                  cachedgoal.truthValue = TruthValue.strengthenTruthValue(cachedgoal.truthValue, frame.truthValue);
                }
              }
              else {
                if ((!Logic.$CACHE_FAILED_GOALSp$) ||
                    frame.dontCacheGoalFailureP) {
                  return;
                }
                index = (((ControlFrame.goalHashCode(frame)) & 0x7FFFFFFF) % 1541);
                cachedgoal = ((AtomicGoalCache)((Logic.$FAILED_GOALS_CACHE$.theArray)[index]));
                if ((cachedgoal == null) ||
                    (!AtomicGoalCache.cacheMatchesGoalP(cachedgoal, frame, false, Logic.KWD_GOAL_INSTANTIATES_CACHE))) {
                  (Logic.$FAILED_GOALS_CACHE$.theArray)[index] = (ControlFrame.createAtomicGoalCache(frame, cachedgoal, false));
                }
              }
            }
          }
          else {
          }
        }
      }
    }
  }