Exemplo n.º 1
0
  /**
   * LambdaList constructor for {@link Subr}.
   *
   * @param reqCount Number of required parameters
   * @param optCount Number of optional parameters
   * @param rest if true, then a function uses rest parameter
   * @param keys List of keywords for keyword parameters
   * @param allowOtherKeys if true, then a function accepts a keyword not defined in <code>keys
   *     </code>
   */
  public LambdaList(int reqCount, int optCount, boolean rest, Object keys, boolean allowOtherKeys) {
    int keyCount = Lists.length(keys);

    // whole: not supported in SUBR
    this.whole = null;
    // req
    this.required = new Required[reqCount];
    for (int i = 0; i < reqCount; i++) {
      this.required[i] = new Required(genVar());
    }
    // opt
    this.optional = new Optional[optCount];
    for (int i = 0; i < optCount; i++) {
      this.optional[i] = new Optional(genVar(), Symbols.NIL, genVar());
    }
    // rest
    if (rest) {
      this.rest = new Rest(genVar());
    } else {
      this.rest = null;
    }
    // key
    this.keyword = new Keyword[keyCount];
    this.allowOtherKeys = false;
    for (int i = 0; i < keyCount; i++) {
      Symbol key = Data.symbol(Lists.car(keys));
      // System.out.println("key = "+key);
      // if (key == Symbols.LK_ALLOW_OTHER_KEYS) {
      //    //System.out.println("allowOtherKeys = true");
      //    this.allowOtherKeys = true;
      //    keys = Lists.cdr(keys);
      //    if (!Lists.isEnd(keys)) {
      //        throw new ProgramException
      //            ("no variable is allowed right after "+
      //             "&allow-other-keys: ~S.",
      //             Lists.list(keys));
      //    }
      // }
      // else {
      //    this.keyword[i] = new Keyword
      //        (genVar(), key, Symbols.NIL, genVar());
      //    keys = Lists.cdr(keys);
      // }
      this.keyword[i] = new Keyword(genVar(), key, Symbols.NIL, genVar());
      keys = Lists.cdr(keys);
    }
    //
    this.allowOtherKeys = allowOtherKeys;
    // aux: not supported in SUBR
    this.aux = new Aux[0];
  }