public static QueryIterator retrieveBindings(Stella_Object query, int nofbindings) {
    { QueryIterator thequery = null;

      { Surrogate testValue000 = Stella_Object.safePrimaryType(query);

        if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_QUERY_ITERATOR)) {
          { QueryIterator query000 = ((QueryIterator)(query));

            thequery = query000;
          }
        }
        else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_PROPOSITION)) {
          { Proposition query000 = ((Proposition)(query));

            thequery = Logic.makeQuery(((Vector)(KeyValueList.dynamicSlotValue(query000.dynamicSlots, Logic.SYM_LOGIC_IO_VARIABLES, null))).consify(), Proposition.propositionToCons(query000), Stella.NIL, Cons.list$(Cons.cons(Logic.KWD_HOW_MANY, Cons.cons(IntegerWrapper.wrapInteger(nofbindings), Cons.cons(Stella.NIL, Stella.NIL)))));
          }
        }
        else if (testValue000 == Logic.SGT_STELLA_CONS) {
          { Cons query000 = ((Cons)(query));

            thequery = Logic.makeQuery(query000.value, query000.rest.value, Stella.NIL, query000.rest.rest);
          }
        }
        else {
          { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

            stream000.nativeStream.print("`" + testValue000 + "' is not a valid case option");
            throw ((StellaException)(StellaException.newStellaException(stream000.theStringReader()).fillInStackTrace()));
          }
        }
      }
      thequery.options.insertAt(Logic.KWD_HOW_MANY, IntegerWrapper.wrapInteger(nofbindings));
      return (Logic.callRetrieve(thequery));
    }
  }