File: scan-doc.m2

package info (click to toggle)
macaulay2 1.25.05%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 172,152 kB
  • sloc: cpp: 107,824; ansic: 16,193; javascript: 4,189; makefile: 3,899; lisp: 702; yacc: 604; sh: 476; xml: 177; perl: 114; lex: 65; python: 33
file content (53 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- Status: rewritten July 2018
-- Author: Lily Silverstein

doc///
 Key
  scan
  (scan, BasicList, Function)
  (scan, BasicList, BasicList, Function)
  (scan, ZZ, Function)
  (scan, Thing, Function)
 Headline
  apply a function to each element in a list or sequence
 Usage
  scan(L, f)
  scan(L, L', f)
  scan(n, f)
 Inputs
  L: BasicList
   or instance of a class with the @TO iterator@ method installed
  n: ZZ
  f: Function
 Description
  Text
   {\tt scan(L, f)} applies the function {\tt f} to each element
   of the list {\tt L}. The function values are discarded.
  Example
   scan({a, 4, "George", 2^100}, print)
   scan("foo", print)
  Text
   {\tt scan(n, f)} applies the function {\tt f} to each element 
   of the list 0, 1, ..., n-1
  Example
   scan(4, print)
   v = {a,b,c}; scan(#v, i -> print(i,v#i))
  Text
   The keyword @TO "break"@ can be used to terminate the scan prematurely,
   and optionally to specify a return value for the expression. Here we
   use it to locate the first even number in a list.
  Example
   scan({3,5,7,11,44,55,77}, i -> if even i then break i)
  Text
   If @TT "L"@ is an instance of a class with the @TO iterator@ method installed
   (e.g., a string), then @TT "f"@ is applied to the values obtained by
   repeatedly calling @TO next@ on the output of @TT "iterator L"@ until
   @TO StopIteration@ is returned.
  Example
   scan("foo", print)
 SeeAlso
  apply
  accumulate
  fold
  "lists and sequences"
///