Next: , Previous: , Up: chains   [Index]


35.6 Folding chains

The following syntactic bindings are exported by the library (vicare containers chains). The bindings whose name is prefixed with $ are unsafe operations: they do not validate their arguments before accessing them.

Function: chain-fold-left-forwards kons knil chain
Function: $chain-fold-left-forwards kons knil chain

Perform a fold-left style iteration over the objects in chain. The iteration starts at chain and proceeds forwards.

(chain-fold-left-forwards
    (lambda (knil obj)
      (cons obj knil))
  '()
  (chain 0 1 2 3 4))
⇒ (4 3 2 1 0)

(chain-fold-left-forwards
    (lambda (knil obj)
      (cons obj knil))
  '()
  (chain-link-next
     (chain-link-next
        (chain 0 1 2 3 4))))
⇒ (4 3 2)
Function: chain-fold-right-forwards kons knil chain
Function: $chain-fold-right-forwards kons knil chain

Perform a fold-right style iteration over the objects in chain. The iteration starts at the last link in the forwards direction and proceeds up to and including chain.

(chain-fold-right-forwards
    (lambda (obj knil)
      (cons obj knil))
  '()
  (chain 0 1 2 3 4))
⇒ (0 1 2 3 4)

(chain-fold-right-forwards
    (lambda (obj knil)
      (cons obj knil))
  '()
  (chain-link-next
     (chain-link-next
        (chain 0 1 2 3 4))))
⇒ (2 3 4)
Function: chain-fold-left-backwards kons knil chain
Function: $chain-fold-left-backwards kons knil chain

Perform a fold-left style iteration over the objects in chain. The iteration starts at chain and proceeds backwards.

(chain-fold-left-backwards
    (lambda (knil obj)
      (cons obj knil))
  '()
  (chain-rear (chain 0 1 2 3 4)))
⇒ (0 1 2 3 4)

(chain-fold-left-backwards
    (lambda (knil obj)
      (cons obj knil))
  '()
  (chain-link-prev
     (chain-link-prev
        (chain-rear (chain 0 1 2 3 4)))))
⇒ (0 1 2)
Function: chain-fold-right-backwards kons knil chain
Function: $chain-fold-right-backwards kons knil chain

Perform a fold-right style iteration over the objects in chain. The iteration starts at the last link in the backwards direction and proceeds up to and including chain.

(chain-fold-right-backwards (lambda (obj knil)
                              (cons obj knil))
  '()
  (chain-rear (chain 0 1 2 3 4)))
⇒ (4 3 2 1 0)

(chain-fold-right-backwards (lambda (obj knil)
                              (cons obj knil))
  '()
  (chain-link-prev
     (chain-link-prev
        (chain-rear (chain 0 1 2 3 4)))))
⇒ (2 1 0)

Next: , Previous: , Up: chains   [Index]