ext/ preprocessor/ seq/ foldleft.bi

This file is part of the <ext/Preprocessor> library API, and can be directly included by user programs.

Summary
ext/ preprocessor/ seq/ foldleft.biThis file is part of the <ext/Preprocessor> library API, and can be directly included by user programs.
LicenseCopyright © 2009, FreeBASIC Extended Library Development Group Copyright © 2002, Paul Mensonides
Macros
fbextPP_SeqFoldLeftExpands a macro returning a new state for each element in a sequence.

License

Copyright © 2009, FreeBASIC Extended Library Development Group Copyright © 2002, Paul Mensonides

Distributed under the Boost Software License, Version 1.0.  See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Distributed under the FreeBASIC Extended Library Group license.  See accompanying file LICENSE.txt or copy at http://code.google.com- /p- /fb-extended-lib- /wiki- /License

Macros

fbextPP_SeqFoldLeft

# define fbextPP_SeqFoldLeft(
   op,
   state,
   seq
) fbextPP_Repeat(fbextPP_SeqSize(seq), fbextPP_SeqFoldLeft__L, op) state fbextPP_Repeat(fbextPP_SeqSize(seq), fbextPP_SeqFoldLeft__R, seq)

Expands a macro returning a new state for each element in a sequence.

Parameters

opA procedure macro of the form op(state, elem), where state is the current state, and elem is the current sequence element.  This macro should return a new state.
stateThe initial state of the fold.
seqA sequence.

Returns

The final state.

Description

Given a sequence (a)(b)(c)(d), this macro will expand to op(op(op(op(state, a), b), c), d).

Example

# include "ext/preprocessor/seq/foldleft.bi"
# include "ext/preprocessor/stringize.bi"

# define SEQ (a)(b)(c)(d)
# define OP(state, elem) state##elem

' Expands to "xabcd"
# print FBEXT_PP_STRINGIZE(fbextPP_SeqFoldLeft(OP, x, SEQ))
# define fbextPP_SeqFoldLeft(
   op,
   state,
   seq
) fbextPP_Repeat(fbextPP_SeqSize(seq), fbextPP_SeqFoldLeft__L, op) state fbextPP_Repeat(fbextPP_SeqSize(seq), fbextPP_SeqFoldLeft__R, seq)
Expands a macro returning a new state for each element in a sequence.