* @param arity
   * @param module
   * @param environment
   * @return LogicObject
   */
  public static LogicObject createFunction(String name, int arity, Module module, Environment environment) {
    if (!(arity > 0)) {
      { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

        { Object old$PrintreadablyP$000 = Stella.$PRINTREADABLYp$.get();

          try {
            Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
            stream000.nativeStream.println("PARSING ERROR: Functions must have arity of at least 1.");
            Logic.helpSignalPropositionError(stream000, Logic.KWD_ERROR);

          } finally {
            Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$000);
          }
        }
        throw ((ParsingError)(ParsingError.newParsingError(stream000.theStringReader()).fillInStackTrace()));
      }
    }
    { Cons args = Stella.NIL;

      { Module mdl000 = module;
        Context cxt000 = mdl000;

        if (mdl000 == null) {
          mdl000 = ((Module)(Stella.$MODULE$.get()));
          cxt000 = ((Context)(Stella.$CONTEXT$.get()));
        }
        { Object old$Module$000 = Stella.$MODULE$.get();
          Object old$Context$000 = Stella.$CONTEXT$.get();

          try {
            Native.setSpecial(Stella.$MODULE$, mdl000);
            Native.setSpecial(Stella.$CONTEXT$, cxt000);
            environment = environment;
            synchronized (Logic.$POWERLOOM_LOCK$) {
              { int i = Stella.NULL_INTEGER;
                int iter000 = 0;
                int upperBound000 = arity - 1;
                Cons collect000 = null;

                for (;iter000 <= upperBound000; iter000 = iter000 + 1) {
                  i = iter000;
                  if (collect000 == null) {
                    {
                      collect000 = Cons.cons(Logic.yieldSystemDefinedParameterName(i, ((Module)(Stella.$MODULE$.get()))), Stella.NIL);
                      if (args == Stella.NIL) {
                        args = collect000;
                      }
                      else {
                        Cons.addConsToEndOfConsList(args, collect000);
                      }
                    }
                  }
                  else {
                    {
                      collect000.rest = Cons.cons(Logic.yieldSystemDefinedParameterName(i, ((Module)(Stella.$MODULE$.get()))), Stella.NIL);
                      collect000 = collect000.rest;
                    }
                  }
                }
              }
              return (Logic.callDeffunction(Cons.cons(Stella.internStellaName(name), Cons.cons(args, Stella.NIL))));
            }

          } finally {
            Stella.$CONTEXT$.set(old$Context$000);
            Stella.$MODULE$.set(old$Module$000);
          }
        }
      }
    }
  }