Package erjang

Examples of erjang.ESeq


  @BIF
  static public EObject match_spec_test(EObject term, EObject matchSpec, EObject how)
  {
    EMatchSpec spec;
    ESeq seq;
    if ((matchSpec instanceof EMatchSpec)) {
      spec = (EMatchSpec) matchSpec;
    } else if ((seq=matchSpec.testSeq()) != null) {
      try {
        spec = EMatchSpec.compile(seq);
View Full Code Here


  }

  @BIF
  public static ESeq map(EProc proc, EObject f, EObject s) throws Pausable {
    EFun fun = f.testFunction2(1);
    ESeq seq = s.testSeq();
    if (fun == null || seq == null) throw ERT.badarg(f, s);
   
    EObject[] arg = new EObject[1];
   
    ESeq rev = ERT.NIL;
    for (; !seq.isNil(); seq = seq.tail()) {
      arg[0] = seq.head();
      EObject val = fun.invoke(proc, arg);
      rev = rev.cons( val );
    }

    return reverse(rev, ERT.NIL);
  }
View Full Code Here

    }
   
    if ((sm_e.value+1) < sm_s.value)
      throw ERT.badarg(start, end);
   
    ESeq l = ERT.NIL;
    int val = sm_e.value;
    int first = sm_s.value;
   
    while (val >= first) {
      l = l.cons(val);
      val -= 1;
    }
   
    return l;
  }
View Full Code Here

  static ESeq seq_big(EInteger start, EInteger end)
  {
    if ((end.inc()).is_lt(start))
      throw ERT.badarg(start, end);
   
    ESeq l = ERT.NIL;
    EInteger val = end;
    EInteger first = start;
   
    while (val.is_ge(first)) {
      l = l.cons(val);
      val = val.dec();
    }
   
    return l;
   
View Full Code Here

    }
    return array;
  }

  public static ESeq xregsSeq(EObject[] reg, int arity) {
    ESeq res = ERT.NIL;
    for (int i=arity-1; i>=0; i--) {
      res = res.cons(reg[i]);
    }
    return res;
  }
View Full Code Here

*/
public class ErlList {

  @BIF(name="--")
  public static ECons listDiff(EObject a1, EObject a2) {
    ESeq l1, l2;
    if ((l1 = a1.testSeq()) == null ||
      (l2 = a2.testSeq()) == null)
      throw ERT.badarg(a1,a2);

    if (l1.isNil()) return l1;

    // Step 1: Copy l1 to a temporary place.
    final EObject[] tmp = l1.toArray();

    // Step 2: Delete elements occurring l2 (but only once)
    int tmp_start = 0;
    for (ESeq cur = l2; !cur.isNil(); cur=cur.tail()) {
      EObject elm = cur.head();
View Full Code Here

  public static final EAtom am_mapfoldl = EAtom.intern("mapfoldl");
 
  @BIF
  public static EObject keymember(EObject key, EObject nth_arg, EObject list_arg) {
    ESmall nth = nth_arg.testSmall();
    ESeq list = list_arg.testSeq();
   
    if (key == null || nth == null | list == null)
        throw ERT.badarg(key, nth_arg, list_arg);

    while (!list.isNil()) {
      EObject elm = list.head();
      ETuple tup = elm.testTuple();

      // test that it is a tuple of the right size
      if (tup != null && tup.arity() >= nth.value) {       
        EObject val = tup.elm(nth.value);
        if (val.equals(key)) { return ERT.TRUE; }
      }
     
      list = list.tail();
    }

    return ERT.FALSE;
  }
View Full Code Here

  }
 
  @BIF
  public static EObject keyfind(EObject key, EObject nth_arg, EObject list_arg) {
    ESmall nth = nth_arg.testSmall();
    ESeq list = list_arg.testSeq();
   
    if (key == null || nth == null | list == null)
        throw ERT.badarg(key, nth_arg, list_arg);

    while (!list.isNil()) {
      EObject elm = list.head();
      ETuple tup = elm.testTuple();

      // test that it is a tuple of the right size
      if (tup != null && tup.arity() >= nth.value) {       
        EObject val = tup.elm(nth.value);
        if (val.equals(key)) { return tup; }
      }
     
      list = list.tail();
    }

    return ERT.FALSE;
  }
View Full Code Here

  }
 
  @BIF
  public static EObject keysearch(EObject k, EObject n, EObject list) {
    ESmall idx = n.testSmall();
    ESeq src = list.testSeq();
   
    if (k==null||idx==null||src==null||idx.value<1)
      throw ERT.badarg(k, n, list);
   
    int index = idx.value;

    while (!src.isNil()) {
      EObject elm = src.head();
     
      ETuple tup;
      if ((tup = elm.testTuple()) != null) {
        if (tup.arity() >= index) {
          if (tup.elm(index).equals(k)) {
            return new ETuple2(ERT.am_value, tup);
          }
        }
      }
     
      src = src.tail();
    }
   
    return ERT.FALSE;
  }
View Full Code Here

  // reimplement this to be iterative, not recursive...
  @BIF
  public static ETuple2 mapfoldl(EProc proc, EObject fun0, EObject acc, EObject list0) throws Pausable {
    EFun fun = fun0.testFunction2(2);
    ESeq list = list0.testSeq();
   
    if (fun == null || list == null) {
      ERT.func_info(am_lists, am_mapfoldl, 3);
    }
   
    ArrayList<EObject> map = new ArrayList<>();
    while (!list.isNil()) {
     
      EObject pair0;
     
      proc.arg0 = list.head();
      proc.arg1 = acc;
      proc.tail = fun;     
      do {
        pair0 = proc.tail.go(proc);
      } while (pair0 == EProc.TAIL_MARKER);
     
      ETuple2 out = ETuple2.cast(pair0);
     
      if (out == null) {
        throw new ErlangError(am_badmatch, pair0);
      }
     
      map.add(out.elem1);
      acc = out.elem2;
     
      list = list.tail();
    }
   
    ESeq res = ERT.NIL;
    for (int i = map.size()-1; i >= 0; i--) {
      res = res.cons(map.get(i));
    }
   
    return new ETuple2(res, acc);
  }
View Full Code Here

TOP

Related Classes of erjang.ESeq

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.