Package astra.lang

Class Prelude


  • public class Prelude
    extends Module
    This API provides support for manipulating ASTRA Lists.
    Author:
    Rem Collier
    • Constructor Detail

      • Prelude

        public Prelude()
    • Method Detail

      • headAsInt

        public int headAsInt​(ListTerm list)
      • headAsLong

        public long headAsLong​(ListTerm list)
      • headAsFloat

        public float headAsFloat​(ListTerm list)
      • headAsDouble

        public double headAsDouble​(ListTerm list)
      • add

        public boolean add​(ListTerm list,
                           Object object)
        Action that adds any object to a list
        Parameters:
        list - the list that is to be modified
        object - the object that is to be added to the list
        Returns:
        true if the action succeeds, false otherwise
      • addAt

        public boolean addAt​(ListTerm list,
                             int index,
                             Object object)
        Action that adds any object to a list at a given index.
        Parameters:
        list - the list that is to be modified
        index - the index at which the object is to be added
        object - the object that is to be added to the list
        Returns:
        true if the item is added, false otherwise
      • addAt

        public boolean addAt​(ListTerm list,
                             int index,
                             Integer object)
      • addAt

        public boolean addAt​(ListTerm list,
                             int index,
                             Long object)
      • addAt

        public boolean addAt​(ListTerm list,
                             int index,
                             Float object)
      • addAt

        public boolean addAt​(ListTerm list,
                             int index,
                             Double object)
      • addAt

        public boolean addAt​(ListTerm list,
                             int index,
                             String object)
      • addAt

        public boolean addAt​(ListTerm list,
                             int index,
                             Boolean object)
      • remove

        public boolean remove​(ListTerm list,
                              int index)
        Action that removes an object from a list at a given index.
        Parameters:
        list - the list to be modified
        index - the index of the object to be removed
        Returns:
        true if the item is removed, false otherwise
      • size

        public int size​(ListTerm list)
        Term that returns the size of the list.
        Parameters:
        list - the list whose size is needed.
        Returns:
        the size of the list
      • isEmpty

        public Formula isEmpty​(ListTerm list)
        Formula that returns true if the list is empty, false otherwise
        Parameters:
        list - the list whose state is to be checked
        Returns:
        The formula TRUE if the list is empty, or the formula FALSE is the list is not empty
      • intValueFor

        public int intValueFor​(ListTerm list,
                               String funct)
      • intValueFor

        public int intValueFor​(ListTerm list,
                               String functor,
                               int index)
      • longValueFor

        public long longValueFor​(ListTerm list,
                                 String funct)
      • longValueFor

        public long longValueFor​(ListTerm list,
                                 String functor,
                                 int index)
      • charValueFor

        public char charValueFor​(ListTerm list,
                                 String funct)
      • charValueFor

        public char charValueFor​(ListTerm list,
                                 String functor,
                                 int index)
      • booleanValueFor

        public boolean booleanValueFor​(ListTerm list,
                                       String funct)
      • booleanValueFor

        public boolean booleanValueFor​(ListTerm list,
                                       String functor,
                                       int index)
      • floatValueFor

        public float floatValueFor​(ListTerm list,
                                   String funct)
      • floatValueFor

        public float floatValueFor​(ListTerm list,
                                   String functor,
                                   int index)
      • doubleValueFor

        public double doubleValueFor​(ListTerm list,
                                     String funct)
      • doubleValueFor

        public double doubleValueFor​(ListTerm list,
                                     String functor,
                                     int index)
      • shuffle

        public boolean shuffle​(ListTerm list)
      • valueAsInt

        public int valueAsInt​(ListTerm list,
                              int index)
        Term that returns the value at the given index cast as an int.
        Parameters:
        list - the list containing the value
        index - the index of the value in the list
        Returns:
        the value at the given index in the list
      • valueAsLong

        public long valueAsLong​(ListTerm list,
                                int index)
        Term that returns the value at the given index cast as an long.
        Parameters:
        list - the list containing the value
        index - the index of the value in the list
        Returns:
        the value at the given index in the list
      • valueAsFunct

        public Funct valueAsFunct​(ListTerm list,
                                  int index)
        Term that returns the value at the given index cast as an long.
        Parameters:
        list - the list containing the value
        index - the index of the value in the list
        Returns:
        the value at the given index in the list
      • valueAsDouble

        public double valueAsDouble​(ListTerm list,
                                    int index)
        Term that returns the value at the given index cast as an double.
        Parameters:
        list - the list containing the value
        index - the index of the value in the list
        Returns:
        the value at the given index in the list
      • valueAsFloat

        public float valueAsFloat​(ListTerm list,
                                  int index)
        Term that returns the value at the given index cast as an float.
        Parameters:
        list - the list containing the value
        index - the index of the value in the list
        Returns:
        the value at the given index in the list
      • valueAsList

        public ListTerm valueAsList​(ListTerm list,
                                    int index)
        Term that returns the value at the given index cast as a list.
        Parameters:
        list - the list containing the value
        index - the index of the value in the list
        Returns:
        the value at the given index in the list
      • valueAsString

        public String valueAsString​(ListTerm list,
                                    int index)
        Term that returns the value at the given index cast as an string.
        Parameters:
        list - the list containing the value
        index - the index of the value in the list
        Returns:
        the value at the given index in the list
      • valueAsBoolean

        public Boolean valueAsBoolean​(ListTerm list,
                                      int index)
        Term that returns the value at the given index cast as a boolean.
        Parameters:
        list - the list containing the value
        index - the index of the value in the list
        Returns:
        the value at the given index in the list
      • sort_asc

        public boolean sort_asc​(ListTerm list)
        Term that sorts the list in ascending order. This method assumes that the values stored in the list are comparable.
        Parameters:
        list - the list to be sorted
        Returns:
        true if the action succeeds, false otherwise
      • sort_desc

        public boolean sort_desc​(ListTerm list)
        Term that sorts the list in descending order. This method assumes that the values stored in the list are comparable.
        Parameters:
        list - the list to be sorted
        Returns:
        true if the action succeeds, false otherwise
      • swap

        public boolean swap​(ListTerm list,
                            int i,
                            int j)
        Term that swaps the value at index i with the value at index j in the list.
        Parameters:
        list - the list to be modified
        i - the index of the first value
        j - the index of the second value
        Returns:
        true if the action succeeded, false otherwise
      • reverse

        public boolean reverse​(ListTerm list)
        Term that reverses the order of the values stored in the list.
        Parameters:
        list - the source list
        Returns:
        true if the action succeeded, false otherwise
      • fromASTRAList

        public List fromASTRAList​(ListTerm list)
        Term that converts the ASTRA list to a standard list of Java objects. This assumes that the ASTRA list contains only primitives...
        Parameters:
        list - the source list
        Returns:
        the list of values
      • toASTRAList

        public ListTerm toASTRAList​(List list)
        Term that converts any Java list (anything that implements the List interface) into an ASTRA list. Here the contents of the original list are assumed to be primitives or objects and are converted to ASTRA Primitives.
        Parameters:
        list - the list to be converted
        Returns:
        an ASTRA list of values
      • toObjectArray

        public Object[] toObjectArray​(ListTerm list)
        Term that converts a list to an object array.
        Parameters:
        list - the list
        Returns:
        an array of objects