Navigation
|
Synopsis The Rascal standard prelude.
Description The Prelude library contains core functionality for handling all of Rascal's data-types.
For basic numeric functions, see the Math library.
Prelude provides the following:
- Boolean:
- arbBool: Return an arbitrary Boolean value.
- fromString: Convert the strings "true" or "false" to a bool.
- toInt: Convert a Boolean value to integer.
- toReal: Convert Boolean value to real.
- toString: Convert Boolean value to string.
- DateTime:
- createDate: Create a new date.
- createDateTime: Create a new datetime (with optional timezone offset).
- createDuration: Create a new duration representing the duration between the begin and end dates.
- createInterval: Given two datetime values, create an interval.
- createTime: Create a new time (with optional timezone offset).
- dateRangeByDay: Given an interval, return a list of days.
- daysDiff: Return the difference between two dates and/or datetimes in days.
- daysInInterval: Return the number of days in an interval, including the begin and end days.
- decrementDays: Decrement the days by a given amount or by 1.
- decrementHours: Decrement the hours by a given amount or by 1.
- decrementMilliseconds: Decrement the milliseconds by a given amount or by 1.
- decrementMinutes: Decrement the minutes by a given amount or by 1.
- decrementMonths: Decrement the months by a given amount or by 1.
- decrementSeconds: Decrement the seconds by a given amount or by 1.
- decrementYears: Decrement the years by a given amount or by 1.
- Duration: A duration of time, measured in individual years, months, etc.
- incrementDays: Increment the days by given amount or by 1.
- incrementHours: Increment the hours by a given amount or by 1.`
- incrementMilliseconds: Increment the milliseconds by a given amount or by 1.
- incrementMinutes: Increment the minutes by a given amount or by 1.
- incrementMonths: Increment the months by a given amount or by 1.
- incrementSeconds: Increment the seconds by a given amount or by 1.
- incrementYears: Increment the years by given amount or by 1.
- interval: A closed interval on the time axis.
- joinDateAndTime: Create a new datetime by combining a date and a time.
- now: Get the current datetime.
- parseDate: Parse an input date given as a string using the given format string.
- parseDateInLocale: Parse an input date given as a string using a specific locale and format string.
- parseDateTime: Parse an input datetime given as a string using the given format string.
- parseDateTimeInLocale: Parse an input datetime given as a string using a specific locale and format string.
- parseTime: Parse an input time given as a string using the given format string.
- parseTimeInLocale: Parse an input time given as a string using a specific locale and format string.
- printDate: Print an input date using the given format string.
- printDateInLocale: Print an input date using a specific locale and format string.
- printDateTime: Print an input datetime using the given format string.
- printDateTimeInLocale: Print an input datetime using a specific locale and format string.
- printTime: Print an input time using the given format string.
- printTimeInLocale: Print an input time using a specific locale and format string.
- splitDateTime: Split an existing datetime into a tuple with the date and the time.
- Exception:
- IO:
- appendToFile: Append a value to a file.
- appendToFileEnc: Append a value to a file.
- bprintln: Print a value and return true.
- canEncode: Returns whether this charset can be used for encoding (use with writeFile)
- charsets: Returns all available character sets
- exists: Check whether a given location exists.
- find: Find a named file in a list of locations.
- iprint: Print an indented representation of a value.
- iprintExp: Print an indented representation of a value and returns the value as result.
- iprintln: Print a indented representation of a value and add a newline at the end.
- iprintlnExp: Print an indented representation of a value followed by a newline and returns the value as result.
- iprintToFile: Print an indented representation of a value to the specified location.
- isDirectory: Check whether a given location is a directory.
- isFile: Check whether a given location is actually a file (and not a directory).
- lastModified: Last modification date of a location.
- listEntries: List the entries in a directory.
- md5HashFile: Read the contents of a location and return its MD5 hash.
- mkDirectory: Create a new directory.
- print: Print a value without subsequent newline.
- printExp: Print a value and return it as result.
- println: Print a value to the output stream and add a newline.
- printlnExp: Print a value followed by a newline and return it as result.
- readFile: Read the contents of a location and return it as string value.
- readFileBytes: Read the contents of a file and return it as a list of bytes.
- readFileEnc: Read the contents of a location and return it as string value.
- readFileLines: Read the contents of a file location and return it as a list of strings.
- readFileLinesEnc: Read the contents of a file location and return it as a list of strings.
- rprint: Raw print of a value.
- rprintln: Raw print of a value followed by newline.
- touch: Changes the last modification date of a file.
- writeFile: Write values to a file.
- writeFileBytes: Write a list of bytes to a file.
- writeFileEnc: Write values to a file.
- List: Library functions for lists.
- delete: Delete an element from a list.
- distribution: Get the distribution of the elements of the list. That is how often does each element occur in the list?
- drop: Drop elements from the head of a list.
- dup: Remove multiple occurrences of elements in a list. The first occurrence remains.
- getOneFrom: Pick a random element from a list.
- head: Get the first element(s) from a list.
- headTail: Split a list in a head and a tail.
- index: A list of legal index values of a list.
- indexOf: Index of first occurrence of an element in a list.
- insertAt: Insert an element at a specific position in a list.
- intercalate: Join a list of values into a string separated by a separator.
- isEmpty: Test whether a list is empty.
- itoString: Convert a list to an indented string.
- last: Return the last element of a list, if any.
- lastIndexOf: Return index of last occurrence of elt in lst, or -1 if elt is not found.
- mapper: Apply a function to all list elements and return list of results.
- max: Determine the largest element in a list.
- merge: Merge the elements of two sorted lists into one list.
- min: Determine the smallest element in a list.
- mix: Mix the elements of two lists.
- permutations: Compute all permutations of a list.
- pop: Pop top element from list, return a tuple.
- prefix: Return all but the last element of a list.
- push: Push an element in front of a list.
- reducer: Apply a function to successive elements of list and combine the results (deprecated).
- reverse: Reverse a list.
- size: Determine the number of elements in a list.
- slice: Compute a sublist of a list.
- sort: Sort the elements of a list.
- split: Split a list into two halves.
- sum: Sum the elements of a list.
- tail: Get the tail element(s) from a list.
- take: Get number of elements from the head of a list.
- takeOneFrom: Remove an arbitrary element from a list, returns the element and the modified list.
- takeWhile: Take elements from the front of the list as long as a predicate is true.
- toMap: Convert a list of pairs to a map; first elements are associated with a set of second elements.
- toMapUnique: Convert a list of tuples to a map; result must be a map.
- top: Take the top element of a list.
- toRel: Convert a list to a relation.
- toSet: Convert a list to a set.
- toString: Convert a list to a string.
- unzip: Make a pair (triple) of lists from a list of pairs (triples).
- upTill: Returns the list 0,1..n-1.
- zip: Make a list of pairs from two (three) lists of the same length.
- ListRelation:
- carrier: Return the set of all elements in any tuple in a list relation.
- carrierR: A list relation restricted to certain element values in tuples.
- carrierX: A list relation excluding tuples that contain certain element values.
- complement: Complement of a list relation.
- domain: Domain of a list relation: a list consisting of the first element of each tuple.
- domainR: List relation restricted to certain domain elements.
- domainX: List relation excluding certain domain values.
- groupDomainByRange: Make sets of elements in the domain that relate to the same element in the range.
- groupRangeByDomain: Make sets of elements in the range that relate to the same element in the domain.
- ident: The identity list relation.
- index: Listes a binary list relation as a map
- invert: Invert the tuples in a list relation.
- range: The range (i.e., all but the first element of each tuple) of a list relation.
- rangeR: List relation restricted to certain range values.
- rangeX: List relation excluding certain range values.
- Map:
- delete: Delete a key from a map.
- domain: Determine the domain (set of keys) of a map.
- domainR: Map restricted to certain keys.
- domainX: Map with certain keys excluded.
- getOneFrom: Get a n arbitrary key from a map.
- invert: Invert the (key,value) pairs in a map.
- invertUnique: Invert the (key,value) pairs in a map.
- isEmpty: Test whether a map is empty.
- itoString: Convert a map to a indented string.
- mapper: Apply a function to all (key, value) pairs in a map.
- range: The range (set of values that correspond to its keys) of a map.
- rangeR: Map restricted to certain values in (key,values) pairs.
- rangeX: Map with certain values in (key,value) pairs excluded.
- size: Number of (key, value) pairs in a map.
- toList: Convert a map to a list of tuples.
- toRel: Convert a map to a relation.
- toString: Convert a map to a string.
- Message: A
Message datatype that represents messages in the IDE.
- Node:
- ParseTree: Library functions for parse trees.
- associativity: Choice under associativity is flattened.
- Condition: constructors for declaring preconditions and postconditions on symbols
- doc: Annotate a parse tree node with a documentation string.
- docs: Annotate a parse tree node with documentation strings for several locations.
- implode: Implode a parse tree according to a given (ADT) type.
- isNonTerminalType:
- link: Annotate a parse tree node with the target of a reference.
- links: Annotate a parse tree node with multiple targets for a reference.
- loc: Annotate a parse tree node with a source location.
- message: Annotate a parse tree node with an (error) message.
- messages: Annotate a parse tree node with a list of (error) messages.
- parse: Parse input text (from a string or a location) and return a parse tree.
- priority: Nested priority is flattened.
- Production:
- saveParser: Save the current object parser to a file.
- Symbol:
- Tree: The Tree data type as produced by the parser.
- treeAt: Select the innermost Tree of a given type which is enclosed by a given location.
- TreeSearchResult: Tree search result type for treeAt.
- unparse: Yield the string of characters that form the leafs of the given parse tree.
- Relation:
- carrier: Return the set of all elements in any tuple in a relation.
- carrierR: A relation restricted to certain element values in tuples.
- carrierX: A relation excluding tuples that contain certain element values.
- complement: Complement of a relation.
- domain: Domain of a relation: a set consisting of the first element of each tuple.
- domainR: Relation restricted to certain domain elements.
- domainX: Relation excluding certain domain values.
- groupDomainByRange: Make sets of elements in the domain that relate to the same element in the range.
- groupRangeByDomain: Make sets of elements in the range that relate to the same element in the domain.
- ident: The identity relation.
- index: Indexes a binary relation as a map
- invert: Invert the tuples in a relation.
- range: The range (i.e., all but the first element of each tuple) of a relation.
- rangeR: Relation restricted to certain range values.
- rangeX: Relation excluding certain range values.
- Set: Library functions for sets.
- classify: Classify elements in a set.
- getOneFrom: Pick a random element from a set.
- group: Group elements in a set given an equivalence function.
- index: Map set elements to a fixed index.
- isEmpty: Test whether a set is empty.
- itoString: Convert a set to an indented string.
- mapper: Apply a function to all set elements and return set of results.
- max: Determine the largest element of a set.
- min: Smallest element of a set.
- power: Determine the powerset of a set.
- power1: The powerset (excluding the empty set) of a set value.
- reducer: Apply a function to successive elements of a set and combine the results (deprecated).
- size: Determine the number of elements in a set.
- sort: Sort the elements of a set. Sort the elements of a set: # Use the built-in ordering on values to compare list elements. # Give an additional
lessThan function that will be used to compare elements. This function lessThan (<) function should implement a strict partial order, meaning: # that it is not reflexive, i.e. never a < a # is anti-symmetric, i.e. never a < b && b < a . # is transitive, i.e. if a < b and b < c then a < c .
- sum: Sum the elements of a set.
- takeOneFrom: Remove an arbitrary element from a set, returns the element and a set without that element.
- toList: Convert a set to a list.
- toMap: Convert a set of tuples to a map; each key is associated with a set of values.
- toMapUnique: Convert a set of tuples to a map (provided that there are no multiple keys).
- toString: Convert a set to a string.
- union: flatten a set of sets into a single set.
- String:
- center: Center a string in given space.
- charAt: Return character in a string by its index position.
- chars: Return characters of a string.
- contains: Check that a string contains another string.
- endsWith: Check whether a string ends with a given substring.
- escape: Replace single characters in a string.
- findAll: Find all occurrences of a string in another string.
- findFirst: Find the first occurrence of a string in another string.
- findLast: Find the last occurrence of a string in another string.
- isEmpty: Check whether a string is empty.
- isValidCharacter: Check that a given integer value is a valid Unicode code point.
- left: Left alignment of string in given space.
- replaceAll: Replace all occurrences of a string in another string.
- replaceFirst: Replace the first occurrence of a string in another string.
- replaceLast: Replace the last occurrence of a string in another string.
- reverse: Return a string with all characters in reverse order.
- rexpMatch: Determine if a string matches the given (Java-syntax) regular expression.
- right: Right align s in string of length n using space.
- size: Determine length of a string value.
- split: Split a string into a list of strings based on a literal separator.
- squeeze: Squeeze repeated occurrences of characters.
- startsWith: Check whether a string starts with a given prefix.
- stringChar: Convert a character code into a string.
- stringChars: Convert a list of character codes into a string.
- substring: Extract a substring from a string value.
- toInt: Convert a string value to integer.
- toLocation: Convert a string value to a (source code) location.
- toLowerCase: Convert the characters in a string value to lower case.
- toReal: Convert a string value to real.
- toUpperCase: Convert the characters in a string value to upper case.
- trim: Returns string with leading and trailing whitespace removed.
- wrap: word wrap a string to fit in a certain width.
- Type: This is a module that reflects Rascal's type system, implemented in Rascal itself.
- Attr: Attributes register additional semantics annotations of a definition.
- choice: Choice between alternative productions.
- comparable: Check if two types are comparable, i.e., have a common supertype.
- eq: structural equality between values.
- equivalent: Check if two types are equivalent.
- Exception:
- glb: The greatest lower bound (glb) between two types.
- isADTType: Determine if the given type is an Abstract Data Type (ADT).
- isAliasType: Determine if the given type is an alias.
- isBagType: Determine if the given type is a bag (bags are not yet implemented).
- isBoolType: Determine if the given type is a bool.
- isConstructorType: Determine if the given type is a constructor.
- isDateTimeType: Determine if the given type is a
datetime .
- isFunctionType: Determine if the given type is a function.
- isIntType: Determine if the given type is an int.
- isListRelType: Determine if the given type is a list relation.
- isListType: Determine if the given type is a list.
- isLocType: Determine if the given type is a loc.
- isMapType: Determine if the given type is a map.
- isNodeType: Determine if the given type is a node.
- isNumType: Determine if the given type is a num.
- isRatType: Determine if the given type is a rational.
- isRealType: Determine if the given type is a real.
- isReifiedType: Determine if the given type is a reified type.
- isRelType: Determine if the given type is a relation.
- isSetType: Determine if the given type is a set.
- isStrType: Determine if the given type is a string.
- isTupleType: Determine if the given type is a tuple.
- isTypeVar: Determine if the given type is an type variable (parameter).
- isValueType: Determine if the given type is a value.
- isVoidType: Determine if the given type is a void.
- lub: The least-upperbound (lub) between two types.
- make: instantiate an ADT constructor of a given type with the given children
- Production: A production in a grammar or constructor in a data type.
- subtype:
- Symbol: A Symbol represents a Rascal Type.
- typeOf: returns the dynamic type of a value as a reified type
- var-func:
- ValueIO: Library functions for reading and writing values in textual and binary format.
Benefits This library makes it possible to import all core Rascal functionality with a single import.
Pitfalls - The prelude may contain more functionality than you need; this leads to an unnecessary longer import and pollution of your name space.
- The precise contents of the prelude are under discussion.
- In the future, Rascal may automatically load the prelude.
|