For details read Perl NOC. After June 25

Ryan Voots >
Language-Farnsworth-0.7.7 >
Language::Farnsworth::Docs::Functions

Language::Farnsworth::Docs::Functions - A big reference to all the functions in the Language::Farnsworth Standard Library

This document is intended to document all of the functions that Language::Farnsworth includes in its standard library.

push[array, elements, ...]

Push will take an array and place all arguments following the array onto the end. Just like a `stack`

.

result = pop[array]

Pop is the antithesis (ED NOTE: need better word!) to push, instead of placing an element on the end of the array, pop[] removes it.

unshift[array, elements, ...]

Unshift is very similar to pop[]. However instead of putting the elements on the end of the array; unshift puts them at the beginning.

shift[array]

Just as pop is the antithesis (ED NOTE: need better word, STILL!) to push, shift[] is the antithesis to unshift[]

sortedarray = sort[elements, ... ] sortedarray = sort[array] sortedarray = sort[{`a,b` a <=> b}, elements, ... >] sortedarray = sort[{`a,b` a <=> b}, array]

sort[] will take a series of numbers or strings and sort them into either alphabetical or numerical order. If you give a lambda as the first argument to sort[] it will use that to do all of the logic for comparing each element of the array. This lambda must perform the comparison in a stable manner or the results will not be deterministic. The lambda must take two arguments and then return either a -1, 0, or 1 as the **<=>** operator does.

mappedarray = map[maplambda, array] mappedarray = map[maplambda, elements, ...] mappedarray = map[{`x` x + 10}, array] mappedarray = map[{`x` x + 10}, elements, ...]

map[] will take an array or set of elements and pass each element as the first argument to **maplambda** for **maplambda** to transform. **maplambda** should return the new value for the element to be used in **mappedarray**.

howmany = length[array]

When you give length[] and array, it will return how many elements the array has.

reversedarray = reverse[array]

reverse[] will reverse the order of the elements in array and return the result.

minimum = min[array] minimum = min[elements, ...] maximum = max[array] maximum = max[elements, ...]

These two functions give you the minimum or maximum element from their arguments.

reversedstring = reverse[string]

reverse[] will reverse the order of all the characters in the string.

howlong = length[string]

When length[] take either a string as its argument it will return the length of the string in characters, this means that a string with unicode characters like **"日本語"** will have a length of **3**.

codepoint = ord[string]

ord[] will give you the unicode codepoint of the first character of the string you pass it.

string = chr[codepoint]

chr[] will take a unicode codepoint and give you back a string containing only that character.

position = index[string, substring] position = index[string, substring, pos]

index[] will search in **string** for the first occurance of **substring** and return its **position**. If **substring** is not found in **string** it will return -1. The optional parameter **pos** will tell index how far into the string to start looking, 0 being the start of the string.

result = eval[string]

eval[] will take a string and evaluate it as if it were the Language::Farnsworth language and return the result.

substring = substrLen[string, start, length]

substrLen[] will pull out a part of **string** that starts at **start** and is **length** characters. If **length** is longer than the end of **string** then it will **substring** will only contain the text up until the end of the string.

substring = substr[string, start, end]

substr[] will pull out a part of **string** that starts at **start** and ends at **end**

substring = left[string, length]

left[] returns the left '**length**' characters from '**string**'.

substring = right[string, length]

right[] returns the right '**length**' characters from '**string**'.

sin[x] csc[x] cos[x] sec[x] tan[x] cot[x] atan[x] arctan[x] acos[x] arccos[x] asin[x] arcsin[x] sinh[x] cosh[x] tanh[x] atanh[x] arctanh[x] acosh[x] arccosh[x] asinh[x] arcsinh[x] atan2[x, y]

I will not go into a detailed explination of what these functions are. They are the basic trigonometric functions, they all take a single number in and return the result. atan2[x,y] is best explained by wikipedia http://en.wikipedia.org/w/index.php?title=Atan2&oldid=246845908.

sqrt[x]

Returns the square root of **x**

exp[x]

Returns **e ** x**.

ln[x]

Returns the natural logarithm of **x**

log[x]

returns the logarithm base 10 of **x**

abs[x]

Returns the absolute value of **x**

gcd[x, y]

Returns the greatest common divisor of **x** and **y**

lcm[x, y]

Returns the lowest common multiple of **x** and **y**

quad[a, b, c] quadratic[a, b, c]

Returns an array containing the two solutions to the quadratic equation described by the equation

a x^2 + b x + c

floor[x] ceil[x] int[x] trunc[x] rint[x] round[x, digits]

floor[] and ceil[] do what they say they do. Both int[] and trunc[] will in fact just truncate a floating point number to an integer, dropping all digits past the decimal point. rint[] will round the to the nearest integer. round[x, digits] will round to a specified number of digits, 0 being an integer 1 meaning having one digit past the decimal point.

numerator[x] denominator[x]

Because Language::Farnsworth uses Math::Pari internally for doing all calculations numbers may be represented as a rational number when possible rather than a floating point number in order to preserve precision. When used on floating point numbers numerator[] will return the number back to you, and denominator[] will return 1.

isprime[x]

Returns true if **x** is a prime number.

prime[x]

Returns the **x**th prime number.

nextprime[x]

Returns the next prime number after **x**

precprimep[x]

Returns the preceeding prime number before **x**

conj[x] # conjugate norm[x] # normal real[x] # gives back the real part of a complex number imag[x] # gives back the imaginary part of a complex number

randmax[x]

randmax[x] returns a random number between 0 and **x**.

getrseed[]

returns the current seed for the random number generator.

setrseed[x]

sets the seed for the random number generator to **x**.

random[]

returns a random number between 0 and 1 with 30 digits of precision (e.g. 10**30 different random numbers).

return[]

return[] lets you return a single value/variable to the previous context just like in almost any other language.

now[]

now[] returns the current date and time as a Language::Farnsworth Date value.

#=head2 unit[] # # unit[unit] # #unit[] takes the name of a unit **NOT** as a string (in future releases it will take it as a string or barename), and will always return the value of the unit[] named as such. This allows you to have access to a unit even when someone has carelessly defined a variable that stomps on that unit. #

syntax highlighting: