Skip to content

LRM Standard Library Functions

Bahul Jain edited this page Feb 27, 2016 · 2 revisions

Standard Library Functions

JSJS provides a simple set of standard library functions to perform basic operations on lists, maps and work with standard input/output. By default, all the following libraries are automatically available.

List Module

The awesome List module provides essential functions to do basic operations on lists:

  1. List.hd: Returns the head of the list.
  2. List.tl: Returns a list without the head of the original list.
  3. List.cons: Appends an element to the head of the list.
  4. List.length: Returns the total number of elements in the list.
  5. List.nth: Returns the nth element of the list.
  6. List.contains?: Return true if a given element exists in the list, else returns false.
  7. List.isEmpty?: Return true if the list does not contain any elements, else returns false.
  8. List.rev: Reverses the given list.

Map Module

The awesome Map module provides essential functions to do basic operations on maps:

  1. Map.set: Adds an entry in a map.
  2. Map.get: Returns a value given the key from a map.
  3. Map.remove: Returns a map after removing key from a map.
  4. Map.clear: Removes all entries of the map.

String Module

The String module is provided to assist users with string manipulation:

  1. String.length: Returns the length of the string
  2. String.concat: Concatenates two strings
  3. String.substring: Returns a substring of the given string

IO Module

The IO module is used to interact with the standard IO

  1. IO.print: Display on standard output
  2. IO.println: Display on standard output, followed by a new line character.
  3. IO.read: Reads contents from standard input.