unsw.cse.framescript
Class FSList

java.lang.Object
  extended by unsw.cse.framescript.Term
      extended by unsw.cse.framescript.FSList

public class FSList
extends Term

This class is a simple linked list that provides sets/lists in FrameScript.

Author:
mmcgill

Field Summary
 Term first
          The head of the list.
 FSList next
          The list's tail.
static FSList nil
          The shared empty list.
 
Constructor Summary
FSList(Term t)
          Creates a list with one term.
FSList(Term t, FSList l)
          Creates a list where t is its head and l is its tail.
 
Method Summary
 FSList append(FSList l)
          Appends one list to another.
 Term assign(Instance currentObject, Term arg, StackFrame stackframe)
          Assigns a value to a Term.
 boolean equals(Term t)
          Compares two Terms for equality.
 Term eval(Instance currentObject, StackFrame stackframe)
          Evaluates a Term.
 Term get(long l)
          Gets the element at a given index in the list.
static void init()
          Initialises list manipulation subroutines.
 Term mapVars(FSList vars)
          Maps atoms to variables from the list of variables.
 boolean member(Term t)
          Test to see if a term is a member of a list.
 int size()
          Gets the size of the list.
 java.lang.String toString()
          Turns the Term into a string.
 FSList without(Term t)
          Removes a term from a list.
 
Methods inherited from class unsw.cse.framescript.Term
asString, fullMatch, indents, match
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nil

public static FSList nil
The shared empty list. Doubles as the end of all list.


first

public Term first
The head of the list.


next

public FSList next
The list's tail.

Constructor Detail

FSList

public FSList(Term t)
Creates a list with one term.

Parameters:
t -

FSList

public FSList(Term t,
              FSList l)
Creates a list where t is its head and l is its tail.

Parameters:
t - the head of the list
l - the tail of the list
Method Detail

eval

public Term eval(Instance currentObject,
                 StackFrame stackframe)
          throws FSException
Description copied from class: Term
Evaluates a Term. For many Terms the result is to return itself.

Specified by:
eval in class Term
Parameters:
currentObject - the enclosing instance frame for the code being evaluated
stackframe - StackFrame that holds the values for any variables
Returns:
the result of the evaluation
Throws:
FSException - if any errors occur in performing the evaluation

equals

public boolean equals(Term t)
Description copied from class: Term
Compares two Terms for equality.

Specified by:
equals in class Term
Parameters:
t - Term to be compared to
Returns:
true if the Terms are equal, false otherwise

assign

public Term assign(Instance currentObject,
                   Term arg,
                   StackFrame stackframe)
            throws FSException
Description copied from class: Term
Assigns a value to a Term. Most Terms cannot be assigned values so the default is to throw an error.

Overrides:
assign in class Term
Parameters:
currentObject - the enclosing instance frame for the code being evaluated that is performing the assignment
arg - the unevaluated value to be assigned to the Term
stackframe - StackFrame that holds the values for any variables
Returns:
the valuse assigned to the Term
Throws:
FSException - if assignment cannot be performed

mapVars

public Term mapVars(FSList vars)
             throws SyntaxError
Description copied from class: Term
Maps atoms to variables from the list of variables.

Overrides:
mapVars in class Term
Parameters:
vars - a list of variables to be mapped
Returns:
a clone of the Term where all the variables have been mapped
Throws:
SyntaxError - if in performing the mapping it finds an invalid variable name

member

public boolean member(Term t)
Test to see if a term is a member of a list.

Parameters:
t - term being tested for membership
Returns:
true if t is a member of the list, flase otherwise

size

public int size()
Gets the size of the list.

Returns:
the size of the list

get

public Term get(long l)
         throws FSException
Gets the element at a given index in the list.

Parameters:
l - the index of the element to get
Returns:
the element of the list at the given index
Throws:
FSException - if the indexz is invalid

append

public FSList append(FSList l)
Appends one list to another.

Parameters:
l - list to be append to the end of the list
Returns:
a list where l is appended to the end of this list

without

public FSList without(Term t)
Removes a term from a list.

Parameters:
t - term to be removed from the list
Returns:
a list which is the same as this but is missing the first occurance of t

toString

public java.lang.String toString()
Description copied from class: Term
Turns the Term into a string.

Specified by:
toString in class Term

init

public static void init()
                 throws FSException
Initialises list manipulation subroutines. Subroutines defined: forall in list cons member head tail nth length append delete

Throws:
FSException