String Functions

Animal ships with a collection of built-in helpers for manipulating text. Because strings are used for both user interaction and symbolic error messages, these helpers are available everywhere without any imports.

Operators

purr

Concatenation operator. Joins two strings together.

greeting -> "Hello"
name -> " Lynx"
roar greeting purr name          :: Hello Lynx

Core Functions

nuzzle(text1, text2)

Function form of concatenation. Accepts strings or lists; when lists are passed they are concatenated as well.

roar nuzzle("Animal ", "Kingdom")    :: Animal Kingdom
merged -> nuzzle([1, 2], [3])        :: [1, 2, 3]
pelt(value, times)

Repeats value times and returns the concatenated string. value is converted to a string automatically.

roar pelt("*", 5)     :: *****
roar pelt(42, 3)      :: 424242
rat(text)

Returns an uppercase version of text.

roar rat("howl softly")     :: HOWL SOFTLY
mole(text)

Returns a lowercase version of text.

roar mole("LOUD PACK")      :: loud pack
snipe(text, symbol = " ")

Trims leading and trailing instances of symbol (defaults to whitespace).

roar snipe("  padded  ")    :: padded
roar snipe("--alpha--", "-"):: alpha
ferret(text, start, length)

Extracts a substring beginning at start with length characters.

roar ferret("snowleopard", 4, 3)   :: leo
badger(text, needle)

Returns true when needle occurs in text, otherwise false.

growl badger("lynx den", "lynx") {
    roar "Found it!"
}
squirrel(text, delimiter)

Splits text using delimiter and returns a list of segments.

words -> squirrel("alpha,beta,gamma", ",")
roar words       :: ["alpha", "beta", "gamma"]
parrot(list)

Joins every element of list (which must contain only strings) into a single string.

pack -> ["lynx", "otter", "mink"]
roar parrot(pack)   :: lynxottermink

Conversion Helpers

Several string helpers interact with numbers. They live in the math module but are frequently used when working with strings:

purr(number, base)

Converts a number to a string representation in the supplied base (2–36).

scent(text, base)

Parses text as a number written in the supplied base.

See Math Functions for full examples.

Putting It Together

The following snippet demonstrates several helpers in tandem:

input -> "  lynx,otter,Mink  "
clean -> snipe(mole(input))
pack -> squirrel(clean, ",")

pack.sniff("stoat")
banner -> pelt("-", 10)
update -> rat(nuzzle("pack update: ", parrot(pack)))

roar banner
roar update