Product SiteDocumentation Site

4.3. Functional

The functional variant of the Scheme library is much different than those in other languages. It is patterned after the system described in the paper Infusing Parallelism into Introductory Computer Science Curriculum using MapReduce,[6] (albeit with the significant difference that the job is started through a web interface, rather than using a function within a scheme interpreter).
Unlike most other languages in WebMapReduce, the types of the intermediate keys and values are preserved (rather than converted to strings) between the map and reduce phases. In other words, if the values returned by your mapper are numbers, the values fed to your reducer will be also.
The mapper and reducer must have these signatures:
(mapper pair)
Maps the key-value pair (a list in the format (key value)) and returns the result as a list of key-value pairs like the following:
It is of course possible to return '() for no result.
(reducer next-value accumulator)
Reduces (accumulates) the two arguments, where next-value is the next value to reduce and accumulator is the result of the previous application of reducer (if any). The library applies this function to every value for a given key, so that the resulting value is equivalent to:
(fold reducer '() values)
Where values is the list of the values associated with the key. In other words, where the values associated with the key are (val1 val2 ... valn), the resulting value would be:
(reducer valn ... (reducer val2 val1) ... )

4.3.1. API

In addition to standard R6RS scheme, SRFIs 1 (lists) and 13 (strings), and any other modules included by default in MZScheme, WebMapReduce provides the following procedures, intended for compatibility with Berkeley's implementation of map-reduce in Scheme:
(kv-key pair)
Returns the key portion of the given key-value pair. Equivalent to (car pair).
(kv-value pair)
Returns the value portion of the given key-value pair. Equivalent to (cadr pair).
(make-kv-pair key value)
Returns a new key-value pair made from the given key and value. Equivalent to (list key value).


[6] Matthew Johnson, et al., UC Berkeley, 2008. http://www.eecs.berkeley.edu/Pubs/TechRpts/2008/EECS-2008-34.html