The syntax of ParaSail is similar to Modula, but with a class-and-interface-based object-oriented programming model more similar to Java or C#. More recently, the parallel constructs of ParaSail have been adapted to other syntaxes, to produce Java-like, Python-like, and Ada-like parallel languages, dubbed, respectively, Javallel, Parython, and Sparkel. Compilers and interpreters for these languages are included with the ParaSail implementation.
Examples
The following is a Hello world program in ParaSail: func Hello_World is IO.Println; end func Hello_World;
The following is an interface to a basic map module: interface BMap; Element_Type is Assignable<>> is op "" -> BMap; // Create an empty map func Insert; func Find -> optional Element_Type; func Delete; func Count -> Univ_Integer; end interface BMap;
Here is a possible implementation of this map module, using a binary tree: class BMap is interface Binary_Node<> is // A simple "concrete" binary node module var Left : optional Binary_Node; var Right : optional Binary_Node; const Key : Key_Type; var Value : optional Element_Type; // null means deleted end interface Binary_Node; var Tree : optional Binary_Node; var Count := 0; exports op "" -> BMap is // Create an empty map return ; end op ""; func Insert is // Search for Key, overwrite if found, insert new node if not for M => BMap.Tree loop if M is null then // Not already in the map; add it M := ; BMap.Count += 1; else case Key =? M.Key of => continue loop with M.Left; => continue loop with M.Right; => // Key is already in the map; // bump count if Value was null; if M.Value is null then BMap.Count += 1; end if; // in any case overwrite the Value field M.Value := Value; return; end case; end if; end loop; end func Insert; func Find -> optional Element_Type is // Search for Key, return associated Value if present, or null otherwise for M => BMap.Tree while M not null loop case Key =? M.Key of => continue loop with M.Left; => continue loop with M.Right; => // Found it; return the value return M.Value; end case; end loop; // Not found in BMap return null; end func Find; func Delete is // Search for Key; delete associated node if found for M => BMap.Tree while M not null loop case Key =? M.Key of => continue loop with M.Left; => continue loop with M.Right; => // Found it; if at most one subtree is non-null, overwrite // it; otherwise, set its value field to null //. if M.Left is null then // Move right subtree into M M < M.Right; elsif M.Right is null then // Move left subtree into M M < M.Left; else // Cannot immediately reclaim node; // set value field to null instead. M.Value := null; end if; // Decrement count BMap.Count -= 1; end case; end loop; // Not found in the map end func Delete; func Count -> Univ_Integer is // Return count of number of items in map return BMap.Count; end func Count; end class BMap;
Here is a simple test program for the BMap module: import PSL::Core::Random; import BMap; func Test_BMap is // Test the Binary-Tree-based Map var Ran : Random := Start; // Start a random-number sequence // Declare a map from integers to strings var M : BMap Univ_Integer, Element_Type => Univ_String>; M := ; // Initialize the map to the empty map for I in 1..Num*2 forward loop // Add elements to the map const Key := Next mod Num + 1; const Val := "Val" | To_String; Println; Insert; end loop; Println; for I in 1..Num loop // Search for elements in the map const Key := Next mod Num + 1; Println; end loop; for I in 1..Num/3 loop // Delete some elements from the map const Key := Next mod Num + 1; Println; Delete; end loop; Println; for I in 1..Num forward loop // Search again for elements in the map Println; end loop; end func Test_BMap;