Documentation

Subprogram Listing

Subprogram Listing

Here is a listing of all built-in subprograms in the Mint libraries. Library operator The operator library provides common operators such as +, -, *, / in subprogram format. `bitNot(a)` Returns the bitwise NOT of a. This is the same as `~a` in other programming languages.`neg(a)` Returns negative a. `bitAnd(a, b)` Returns the bitwise AND of a and b. This is the same as `a & b` in other programming langugages.`bitOr(a, b)` Returns the bitwise OR of a and b. This is the same as `a | b` in other programming languages.`bitXor(a, b)` Returns the bitwise XOR of a and b. This is the same as `a ^ b` in other programming languages. Note that in Mint, ^ means "to the power of" and not bitwise XOR.`pow(a, b)` Returns a to the power of b. `shl(a, b)` Takes the integer a and shifts it b bits to the left. This is the same as `a << b` in other programming languages.`shr(a, b)` Takes the integer a and shifts it b bits to the right. This is the same as `a >>> b` in other programming languages.`sar(a, b)` Takes the integer a and shifts it b bits to the right. The old most significant bit is copied into the new most significant bit. This is the same as `a >> b` in other programming languages.`plus(a, b)` Returns `a + b` .`minus(a, b)` Returns `a - b` .`mul(a, b)` Returns a times b. `div(a, b)` Returns a divided by b. `inc(a)` Returns `a + 1` .`dec(a)` Returns `a - 1` .`intDiv(a, b)` Performs division between a and b, rounding down to the nearest whole number. `floorDiv(a, b)` does the same thing.`logicAnd(a, b)` Returns true only if a and b are both true. Otherwise, returns false. `logicOr(a, b)` Returns true if a or b is true. Otherwise, returns false. `logicXor(a, b)` Returns true if either a or b is true, but not both. Otherwise, returns false. `logicNot(a)` Returns true if a is false, and false if a is true. `eq(a, b)` Returns true if a equals b. `notEq(a, b)` Returns true if a is not equal to b. `greater(a, b)` Returns true if a is greater than b. `lesser(a, b)` Returns true if a is less than b. `greaterEq(a, b)` Returns true if a is greater than or equal to b. `lesserEq(a, b)` Returns true if a is less than or equal to b. Library math The math library provides mathematical constants and math subprograms. `e` An approximation of the base of the natural logarithm. It is a constant equal to 2.7182818284590452354. `pi` An approximation of the ratio between a circle's circumference and diameter. It is a constant equal to 3.14159265358979323846. `phi` An approximation of the golden ratio. It is equal to half of 1 plus the square root of 5 or 1.618033988749895. `INFINITY` A Mint object that is bigger than any number. `-INFINITY` (or `NEGATIVE_INFINITY` )A Mint object that is more negative than any number. `UNDEFINED` A number that is not defined. `findRoot(functor, guess)` Attempts to solve the equation defined by functor, which should be a subprogram such as: sub f(x) return x^2 + 2(x) - 9 endIt will find when a function `functor(x)` equals 0, and then return that x.It will start guessing for x by setting `x = guess` .`differentiate(f)` Takes the derivative of the subprogram f, such that the returned subprogram fPrime, written as f'(x), is f differentiated with respect to x. In other words, differentiating the subprogram that implements the math function g(t) = ln(t) + t^{3}will return a Mint subprogram called gPrime that implements the math function g'(t) = 1/t + 3(t^{2})`binomialChoose(N, K)` Performs the math operation `N choose K` ,
often written in mathematics as:
`fib(i)` Returns the `ith` Fibonacci number,using the fastest known calculation method. `abs(a)` Returns the absolute value of a. `sin(a)` Returns the sine of a radians. `cos(a)` Returns the cosine of a radians. `tan(a)` Returns the tangent of a radians. `asin(a)` Returns the arcsine of a. `acos(a)` Returns the arccosine of a. `atan(a)` Returns the arctangent of a. `sinh(a)` Returns the hyperbolic sine of a. `cosh(a)` Returns the hyperbolic cosine of a. `tanh(a)` Returns the hyperbolic tangent of a. `asinh(a)` Returns the hyperbolic arcsine of a. `acosh(a)` Returns the hyperbolic arccosine of a. `atanh(a)` Returns the hyperbolic arctangent of a. `ln(a)` Returns the natural log of a. `log10(a)` Returns the log base 10 of a. `sqrt(a)` Returns the square root of a. `cbrt(a)` Returns the cube root of a. `factorial(a)` Returns a!, where ! means factorial. `log(a, b)` Returns the log base b of a. `min(a, b)` Returns a if a is less than b. Otherwise, returns b. `max(a, b)` Returns a if a is greater than b. Otherwise, returns b. `BigInt(a)` Constructs a big integer object from a. a can be a real number, an integer, or string. Big integers can hold extremely large numbers. For example, try: import math print factorial(BigInt(500)) `PreciseReal(a)` Constructs a precise real object from a. a can be a real number, an integer, or string. Precise reals offer more precision than regular real numbers. Compare: import math print 1 / 3 print PreciseReal(1) / PreciseReal(3)Library type The type library offers subprograms that convert between the different variable types of Mint. `string(a)` Converts a into a string. `int(a)` Converts a into an integer. `real(a)` Converts a into a real number. `truth(a)` Converts a into a truth value, either true or false. `type(a)` Returns the type of object a as a string. `list(a)` Converts a into a list. `char(a)` Converts the integer a into an ASCII character. Library time The time library offers subprograms that measure or deal with time. `wait(a)` Causes the program to wait for a milliseconds. `year()` Returns the current year. `amPm()` Returns the string "am" if it is before noon, and "pm" otherwise. `date()` Returns a string that represents the current date. `hour()` Returns the current hour in 12-hour format. `hour24HourFormat()` Returns the current hour in 24-hour format. `millisecond()` Returns the current millisecond. `minute()` Returns the current minute. `month()` Returns the current month as a number between 1 and 12. `second()` Returns the current second. `timeZone()` Returns the current timezone as a string. `weekday()` Returns the current weekday as a string. `weekdayNumber()` Returns the current weekday, where 0 is Sunday and 6 is Saturday. Library system The system library offers subprograms that deal with system functions and low-level assembly-like commands. `exit()` Exits the Mint program. `halt()` Exits the Mint program with exit code 1, which indicates some form of error has occurred. `getArgs()` Returns the command line arguments passed to the program as a list of strings. `swap(t, w)` Returns [w, t]. If t and w are real numbers (numbers with decimal points in them), this will also perform `flip t, w` .`systemScan()` Scans the system, returning some information about the Mint Virtual Machine's memory usage. `sizeInBytes(obj)` Returns the size of a Mint object in bytes. An integer is worth 4 bytes, a real number takes up 8 bytes, and a fraction takes up a massive 16 bytes. Strings and lists have different lengths and will vary in size. The size of `null` is 0.Values that are represented with less than 8 bits will return a real number, such as 0.5 for a 4-bit integer. `clear()` Attempts to clear the screen of text characters. This will try to call the Windows `cls` or the Mac/Linux/Unix `clear` .If that does not work, it will display a bunch of empty lines to clear the screen. `address(value)` Takes any Mint value, such as a string or a table, and returns the address where it is located in memory. `caliber(value)` Takes any Mint value, such as a string or a table, and returns the ID number of the data segment where it is located in memory. `star(calib, addr)` Performs the C and C++ operation `*(calib * DATA_SEG_SIZE + addr)` , whichwill deference the pointer with address `addr` and data segment ID number `calib` .`changeString(addr, newString)` Modifies the string at address `addr` .In C++, this is equivalent to: string *somePointer = addr; somePointer[0] = newString;Note that the data segment ID number is calculated automatically. `inveigle(value)` Using `inveigle(true)` will cause Mintto ignore all errors. Instead of errors crashing the program, ignored errors are saved in the file: `mint.error.log` `viewStrings()` Returns a table of all strings, with the addresses of the strings as the keys. `viewHeap()` Returns a table that represents the entire Mint Virtual Machine. Library compress The compression library offers subprograms that will put multiple files together into a single file. `glue(listOfFiles, outputFile)` If listOfFiles is a list of strings such as `[file0, file1, file2 ...]` , then `glue(listOfFiles, outputFile)` will glue together the contents of those files, and save the result as outputFile. Opening the glued file in a hex editor will allow you to see all the files in that glue file, separated by a randomly generated separator. It is suggested that outputFile end with the file extension: .glue Note that gluing files together does not preserve the filenames of each file. Also, there is currently no `unglue(...)` subprogram, unless you write it yourself.Library file The file library offers subprograms that modify files and folders. `Bytes(a)` Creates a bytes object out of a, where a is a list of integers or a string. `appendStrToFile(fileName, s)` Appends the string s to the file with name fileName. `bytesToHex(bytes)` Converts a bytes object to a string of hexadecimal digits. `canReadAndWrite(fileName)` Returns true if it is possible to read and write to the file with name fileName. `copyFile(file1, file2)` Copies file1 to file2. `delete(f)` Deletes file or folder f. `exists(f)` Returns true if file or folder f exists. `fileToStr(fileName)` Converts a file's contents into a string. `fullPathToRelPath(path)` Converts a full path to a relative path, relative to the program's path. `getCurrentFolder()` Gets the folder name of the folder the program is in. `getFileSize(fileName)` Gets the size of file fileName. `getFilesInFolder(folderName)` Returns a list of filenames in the folder folderName. `hexToBytes(hex)` Converts a hexadecimal string of digits into a bytes object. `makeFolder(folder)` Creates the folder folder. `readBytes(file, begin, end)` Reads a bytes object from file, where the bytes begin at position begin and end at position end. `readHex(file, begin, end)` Reads a hexadecimal string of digits from file, where the hex begins at position begin and ends and position end. `removeFileExtension(fileName)` Returns fileName, but with the file extension removed. `strToFile(s, fileName)` Writes the string s to file fileName. `writeBytes(fileName, bytes, begin)` Writes bytes to the file fileName starting at position begin. `writeHex(fileName, hex, begin)` Writes a hexadecimal string of digits to the file fileName starting at position begin. `fileLength(fileName)` Same as `getFileSize(fileName)` .Library web The web library offers subprograms that interface with the Internet. `getWebsiteContents(url)` Gets the HTML contents of the website url. `downloadFile(url, fileName)` Downloads a file from url to file fileName. `connectToIRC(server, botName, channels, showDebug, commandsSub)` Sets up an IRC bot on server server, with name botName, on a list of channels channels, with a debugging mode showDebug, and a subprogram commandsSub that will be executed whenever the bot receives a message. commandsSub takes five arguments, all of which are strings, which are channel, sender, login, hostname, and message. `sendMessage(channel, msg)` This subprogram can only be used inside your commands subprogram for connectToIRC. It sends the string msg to the channel channel, thereby chatting on IRC. `sendRawLine(msg)` This subprogram can only be used inside your commands subprogram for connectToIRC. It sends the string msg to the channel channel, but performs no modifications to the string. This is used to execute IRC commands. Unfortunately, it is not currently possible to control the channel on which the message displays. For example: import web import time import system sub commands(one, two, three, four, five) sendMessage("#some_channel", "hi") //Says hi on #some_channel. sendRawLine("NICK Eugene") //Changes the bot's nickname to Eugene. end connectToIRC("irc.SOME_EXAMPLE_SERVER.net", "SomeBot", ["#some_channel"], true, commands) `openWebBrowser(url)` Opens a web browser page that points to url. `getIPAddress()` Gets the IP address of the computer. Library mint The mint library offers subprograms that interface with the Mint interpreter. `eval(s)` Evaluates the expression s and returns the resulting value. `exec(s)` Executes the string s as a Mint program. Library graphics The graphics library offers subprograms that draw graphics to the screen. `Window()` Creates a window object. `showMessageBox(title, msg)` Shows a message box with a title and message. `showWarningBox(title, msg)` Shows a warning box with a title and message. `showErrorBox(title, msg)` Shows a error box with a title and message. `showPlainBox(title, msg)` Shows a plain message box with a title and message. `showQuestionBox(title, msg)` Shows a question box with a title and message. If the selected option is yes, returns true. If the selected option is no, returns false. `Button()` Creates a button object, which can be added to a window. `Arc(x, y, width, height, startAngle, arcAngle)` Creates an arc object which can be drawn onto a window. `Line(x, y, x2, y2)` Creates an line object which can be drawn onto a window. `Oval(x, y, width, height)` Creates an oval object which can be drawn onto a window. `Polygon(x, y, x2, y2, x3, y3, ...)` Creates an polygon object consisting of the points (x, y), (x2, y2), (x3, y3), etc. which can be drawn onto a window. `Rectangle(x, y, width, height)` Creates an rectangle object which can be drawn onto a window. Library thread The thread library offers subprograms that give multi-threading capabilities. `startThread(t)` Runs the subprogram t with no arguments as a single thread. Multiple threads run side-by-side in a single Mint program. Library random The random library generates random numbers. `coinToss(number)` Using coinToss(0.5) will toss a fair coin, with a 50% chance of returning "heads" or "tails". coinToss(1.0) will always return heads. coinToss(0.0) will always return tails. coinToss(0.75) will return heads 75% of the time. coinToss(0.2) will return tails 80% of the time. `randomInt(a, b)` Returns a random integer that is greater than or equal to a and less than or equal to b. `randomReal()` Returns a random real number between 0.0 and 1.0, not including 1.0. `trueRandomInt()` Returns a 32-bit random integer, calculated by grabbing various data from the Internet. You must be connected to the Internet for this to work. `trueRandomReal()` Returns a random real number between 0.0 and 1.0, not including 1.0, calculated by grabbing various data from the Internet. You must be connected to the Internet for this to work. Library programming The programming library allows you to run programs in other coding languages that are not Mint. `executePython(nameOfPythonFile)` Runs a Python program. You must have Python installed. `executeJava(nameOfJavaSourceFile)` Runs a Java program. You must have Java installed. You might need to run `executeJava(...)` twice. The firsttime is to compile the .java file, and the second time is to run the compiled results. Library "data.mint" The "data.mint" library defines some data structures that aren't inherently built-in to Mint. `tree(r)` Generates a tree node which can have any number of children. r is the value associated with the node. `set()` Generates an empty set where order of elements is unimportant. Sets only care about unique elements. If an object is already in the set, it cannot be re-added to the set. `sortedList()` Generates an empty sorted list. A sorted list keeps its elements in order as they are added to the list. `bubbleSort(lst)` Uses the Bubble Sort algorithm to sort the list lst. The sorted result is returned. `quickSort(lst)` Uses the Quick Sort algorithm to sort the list lst. The sorted result is returned. Previous Lesson: Operator Overloading Next Lesson: Object Methods Table of Contents |