StringTools - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Filter Operations : StringTools/Map

StringTools

  

Map

  

map a Maple procedure onto a string

  

AndMap

  

perform mapped disjunction over a string

  

OrMap

  

perform mapped conjunction over a string

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

Map(p, s)

AndMap(p, s)

OrMap(p, s)

Parameters

p

-

anything; typically, a Maple procedure to apply to string s

s

-

string

Description

• 

The Map(p, s) function applies p to each character in string s. The mapped procedure p should map characters to characters. However, if a string of length greater than one is returned in any call to p, only the first character of the returned string is used. The mapped procedure p can return an empty string to terminate the output string at that point. The result of a call to Map is the string returned by catseqpt,t=s. However, Map is more efficient.

  

Map is a special version of map for strings. Unlike map, extra arguments included in the call to Map are not passed to the calls to p.

• 

The AndMap(p, s) function applies p to each character in string s. If p returns the value true when applied to each character of s, AndMap returns the value true. If p returns the value false when applied to any character of s, false is returned as the final result of the call to AndMap. Otherwise, AndMap returns the result FAIL.

  

The characters of s are visited in order and only as many characters as are needed to determine the result of AndMap are examined.

  

The AndMap function computes the value

foldl( `and`, true, op( map( p, Explode( s ) ) ) )

  

efficiently.

• 

The OrMap(p, s) function applies p to each character in string s and computes the conjunction of the values of p.

  

The result of evaluating p at each character of s is evaluated, in order, from left to right. Each call must return one of the values true, false, or FAIL. If true is returned at any call to p, the value true is returned as the result of the call to OrMap. Otherwise, if the value FAIL is returned at any call to p, FAIL is returned as the result of the call to OrMap. Otherwise, OrMap returns the result false.

  

Like AndMap, the OrMap procedure tests the characters of s in order, and returns as soon as it is possible to determine the final result.

• 

These functions are part of the StringTools package, and so they can be used in the form Map(..) only after executing the command with(StringTools). However, they can always be accessed through the long form of the command by using the form StringTools[Map](..).

Examples

withStringTools:

MapCapitalize,This is a test.

THIS IS A TEST.

(1)

AndMapIsASCII,This is a test.

true

(2)

OrMapIsASCII,This is a test.

true

(3)

AndMapIsUpper,This is a test.

false

(4)

OrMapIsUpper,This is a test.

true

(5)

See Also

cat

FAIL

map

seq

string

StringTools

StringTools[Capitalize]

StringTools[Explode]

StringTools[IsASCII]

StringTools[IsUpper]

StringTools[LeftFold]