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
purrConcatenation 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
timesand returns the concatenated string.valueis converted to a string automatically.roar pelt("*", 5) :: ***** roar pelt(42, 3) :: 424242rat(text)Returns an uppercase version of text.
roar rat("howl softly") :: HOWL SOFTLYmole(text)Returns a lowercase version of text.
roar mole("LOUD PACK") :: loud packsnipe(text, symbol = " ")Trims leading and trailing instances of symbol (defaults to whitespace).
roar snipe(" padded ") :: padded roar snipe("--alpha--", "-"):: alphaferret(text, start, length)Extracts a substring beginning at start with length characters.
roar ferret("snowleopard", 4, 3) :: leobadger(text, needle)Returns
truewhen needle occurs in text, otherwisefalse.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