Standard library

There are two components to the standard library: built-in functions and a distribution of functionality defined in Hurl.

Built-ins

Built-ins are functions which evaluate as an expression to a value; when you use them you do not have to catch the result but may assign it directly. These are the built-ins that are defined, with *args representing any number of arguments:

  • print(*args): prints all arguments with no separators; evaluates to nil
  • println(*args): print, but with a newline; evaluates to nil
  • is_digit(x): evaluates to true if x is an ASCII digit, and false otherwise
  • as_num(x): evaluates to x converted to a number, or panics if that fails
  • as_str(x): evaluates to x as a string
  • str_chars(s): evaluates to a list containing all the chars that are in the string s, and panics if called on a non-string argument
  • str_lines(s): evaluates to a list containing all the lines that are in the string s, and panics if called on a non-string argument
  • len(xs): evaluates to the length of the list or string represented by xs, and panics if provided any other type
  • slice(xs, start, end): evaluates to the substring or sublist of xs starting from start and going to end or the end of the list, whichever is sooner; panics if given a non-list and non-string argument
  • at(xs, index): evaluates to the element of xs at the index location (remember, it's 1-indexed)
  • set(xs, index, val): evaluates to a copy of the list xs with the indexth element replaced with val
  • floor(x): evaluates to the value passed in rounded down to the nearest integer
  • ceil(x): evaluates to the value passed in rounded up to the nearest integer
  • read_file(x): evaluates to the content of the file at path x as a string, or panics if the file does not exist or cannot be read
  • trim(s): evaluates to the string s with all leading and trailing whitespace removed; this can be implemented in pure Hurl, but I'm sorry, I was tired while doing the Advent of Code problems okay?

Hurl stdlib

If you check out the main Hurl repo, there are some included files in the lib/ directory which are the standard library. You can browse them in the repo and new standard library functions are welcome.