Class EsExpr


  • public final class EsExpr
    extends java.lang.Object
    The EsExpr class represents Lisp-like S-expressions using tuple notation. EsExpr can be atom, i.e. string literal, or expression of form (a . b . c ...) which is equivalent for traditional dotted-pair sequence (a . (b . (c . ...))). This kind of expressions is called tuples. Tuples with special atom NIL at the last position are called lists. NIL is a predefined atom which is considered as an empty tuple or list.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static EsExpr NIL  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static EsExpr cons​(EsExpr lhs, EsExpr rhs)
      Create dotted pair for given S-expressions.
      static EsExpr createAtom​(java.lang.String literal)
      Create atom for given string literal.
      static EsExpr createList​(java.util.List<EsExpr> items)
      Create list of given S-expressions.
      static EsExpr createTuple​(java.util.List<EsExpr> items)
      Create tuple of given S-expressions.
      boolean equals​(java.lang.Object obj)  
      java.util.List<EsExpr> getItems()
      Returns list of S-expressions contained in this expression.
      java.util.List<EsExpr> getListItems()
      Returns list of S-expressions contained in this list excluding last NIL.
      java.lang.String getLiteral()
      Returns string literal for given expression.
      boolean isAtom()
      Returns true if this expression is atom.
      boolean isList()
      Returns true if this expression is list.
      boolean isNil()
      Returns true if this expression is NIL atom.
      boolean isTuple()
      Returns true if this expression is tuple.
      EsExpr normalizePairs()
      Returns deepest equivalent of this expression.
      EsExpr normalizeTuples()
      Returns shallowest equivalent of this expression.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NIL

        public static final EsExpr NIL
    • Method Detail

      • isAtom

        public boolean isAtom()
        Returns true if this expression is atom.
        Returns:
        true if this expression is atom
      • isNil

        public boolean isNil()
        Returns true if this expression is NIL atom.
        Returns:
        true if this expression is NIL atom
      • isList

        public boolean isList()
        Returns true if this expression is list. List expression is NIL atom or tuple containing NIL at last position.
        Returns:
        true if this expression is list
      • isTuple

        public boolean isTuple()
        Returns true if this expression is tuple.
        Returns:
        true if this expression is tuple
      • getLiteral

        public java.lang.String getLiteral()
        Returns string literal for given expression. Atom string literal evaluates to itself, list and tuple literals are predefined strings denoting how expression has been created. If correct string representation required for S-expression, use toString() instead.
        Returns:
        string literal for this expression
      • getItems

        public java.util.List<EsExpr> getItems()
        Returns list of S-expressions contained in this expression.
        Returns:
        list of contained expressions, empty list for atoms
      • getListItems

        public java.util.List<EsExpr> getListItems()
        Returns list of S-expressions contained in this list excluding last NIL.
        Returns:
        list of contained expressions excluding last NIL
        Throws:
        java.lang.UnsupportedOperationException - if this expression is not list
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • normalizeTuples

        public EsExpr normalizeTuples()
        Returns shallowest equivalent of this expression. I.e. transforms recursively tuples like (a . b . (c . d)) into (a . b . c . d) form.
        Returns:
        shallowest equivalent of this expression.
      • normalizePairs

        public EsExpr normalizePairs()
        Returns deepest equivalent of this expression. I.e. returns expression consisting only of dotted pairs and atoms.
        Returns:
        deepest equivalent of this expression.
      • createAtom

        public static EsExpr createAtom​(java.lang.String literal)
        Create atom for given string literal.
        Parameters:
        literal - string literal for atom being created
        Returns:
        atom for given string literal
        Throws:
        java.lang.IllegalArgumentException - if literal is null
      • createList

        public static EsExpr createList​(java.util.List<EsExpr> items)
        Create list of given S-expressions. Adds NIL atom at the end of list.
        Parameters:
        items - list of S-expressions
        Returns:
        list containing all expressions from items list
        Throws:
        java.lang.IllegalArgumentException - if items list is null
      • createTuple

        public static EsExpr createTuple​(java.util.List<EsExpr> items)
        Create tuple of given S-expressions.
        Parameters:
        items - list of S-expressions
        Returns:
        tuple containing all expressions from items list
        Throws:
        java.lang.IllegalArgumentException - if items list is null
      • cons

        public static EsExpr cons​(EsExpr lhs,
                                  EsExpr rhs)
        Create dotted pair for given S-expressions.
        Parameters:
        lhs - left expression in dotted pair
        rhs - right expression in dotted pair
        Returns:
        tuple containing lhs and rhs expressions
        Throws:
        java.lang.IllegalArgumentException - if any of given expressions is null