Skip to content

Commit

Permalink
PPMPF_MAP as a first ppmpf bind - aware prototype.
Browse files Browse the repository at this point in the history
With the work done on PPMPF_BDS31, a ppmpf branching expression was used
in order for the PPMPF_TUP_MAP / PPMPF_UTUP_MAP to become bind - aware.
The newer macro is at its 3rd generation and is to be the prototype
upon which PPMPF_TUP_MAP, PPMPF_UTUP_MAP and PPMPF_SEQ_MAP are going to
be unified and become bind - aware. Affects series of dependent issues
#6, #9, #18, #20. The macro has its own dedicated test that can be
checked with 'make just ppmpf/map.cc'. This macro is going to be used
as the model upon which the other high order function emulators are
going to evolved into macros with "binding" and "type" features like the
left and right folds, zip, zipwith.
  • Loading branch information
irrequietus committed Mar 8, 2014
1 parent 6bdf437 commit 4834e89
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 1 deletion.
59 changes: 59 additions & 0 deletions odreex/ppmpf/algorithms/map.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* --
* Copyright (C) 2013, 2014 George Makrydakis <[email protected]>
*
* This file is part of odreex.
*
* odreex is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* odreex is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* odreex. If not, see http://www.gnu.org/licenses/.
*
*/

#ifndef _ODREEX_PPMPF_ALGORITHMS_MAP_HH_
#define _ODREEX_PPMPF_ALGORITHMS_MAP_HH_

#include <odreex/ppmpf/collections/tuple.hh>
#include <odreex/ppmpf/functional/bind.hh>
#include <odreex/ppmpf/functional/rdfn.hh>

/*~
* @desc A newer implementation of the map high order function, for tuples,
* that is bind - aware.
* @pfrg f: a plain function or a ppmpf bind expression.
* @pfrg t: a safe tuple
* @pexp Application of f over an n-ary ppmpf tuple.
* @note This is very much a work in progress, based on work done with the
* `PPMPF_BDS31` bind map prototype.
* @todo Implement the first ppmpf "type" system within this prototype and
* optimize expansion times of the initial code inheritance from the
* `PPMPF_BDS31` proof of concept code.
*/

#define PPMPF_MAP(f,t) \
PPMPF_RDFN( PPMPF_PFLD1 \
, f \
, ( (())(t) \
, PPMPF_TUP_GET \
, PPMPF_TUP_POP \
, PPMPF_UTUP_EMPTY \
, PPMPF_BDSN4 \
, PPMPF_FLDX0D \
, PPMPF_BDSN2 ) \
, ( (())(t) \
, PPMPF_TUP_GET \
, PPMPF_TUP_POP \
, PPMPF_TUP_EMPTY \
, PPMPF_FLDX0E \
, PPMPF_FLDX0D \
, PPMPF_FLDX0H ) )

#endif /* _ODREEX_PPMPF_ALGORITHMS_MAP_HH_ */
2 changes: 1 addition & 1 deletion odreex/ppmpf/functional/bind/internals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
, (PPMPF_DREF(b),) ,)

#define PPMPF_BDS28(f,r,t,a,b) \
r(PPMPF_APPLY(f,PPMPF_DREF(PPMPF_BDS27(t,a,b))))
r(PPMPF_APPLY2(f,PPMPF_DREF(PPMPF_BDS27(t,a,b))))
#define PPMPF_BDS29(...) \
PPMPF_BDS28(__VA_ARGS__)
#define PPMPF_BDS30(a,b,c) \
Expand Down
40 changes: 40 additions & 0 deletions odreex/ppmpf/functional/rdfn.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* --
* Copyright (C) 2013, 2014 George Makrydakis <[email protected]>
*
* This file is part of odreex.
*
* odreex is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* odreex is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* odreex. If not, see http://www.gnu.org/licenses/.
*
*/

#ifndef _ODREEX_PPMPF_FUNCTIONAL_RDFN_HH_
#define _ODREEX_PPMPF_FUNCTIONAL_RDFN_HH_

#include <odreex/ppmpf/ppfk.hh>

#define PPMPF_RDFN_1(p,f,b,c) \
PPMPF_APPLY(p,f,PPMPF_DREF(b),)

#define PPMPF_RDFN_2(p,f,b,c) \
PPMPF_APPLY(p,f,PPMPF_DREF(c),)

#define PPMPF_RFDN_3(p,...) \
PPMPF_APPLY(p,__VA_ARGS__)

#define PPMPF_RDFN(p,f,b1,b2) \
PPMPF_IFELSE( PPMPF_ISPRN(f) \
, PPMPF_RDFN_1 \
, PPMPF_RDFN_2 )(p,f,b1,b2)

#endif /* _ODREEX_PPMPF_FUNCTIONAL_RDFN_HH_ */
20 changes: 20 additions & 0 deletions tests/ppmpf/bds31.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/* --
* Copyright (C) 2013, 2014 George Makrydakis <[email protected]>
*
* This file is part of odreex.
*
* odreex is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* odreex is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* odreex. If not, see http://www.gnu.org/licenses/.
*
*/

#include <odreex/ppmpf/functional/bind.hh>
#include <odreex/ppmpf/range.hh>
#include <odreex/test.hh>
Expand Down
58 changes: 58 additions & 0 deletions tests/ppmpf/map.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* --
* Copyright (C) 2013, 2014 George Makrydakis <[email protected]>
*
* This file is part of odreex.
*
* odreex is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* odreex is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* odreex. If not, see http://www.gnu.org/licenses/.
*
*/

#include <odreex/ppmpf/algorithms/map.hh>
#include <odreex/ppmpf/range.hh>
#include <odreex/test.hh>

PPMPF_TST( ppmpf_map64a
, PPMPF_MAP
, (f, PPMPF_NRANGE_TUP((0)(0)(0)(0), (0)(0)(6)(3)))
, ((f(0)),(f(1)),(f(2)),(f(3)),(f(4)),(f(5)),(f(6)),(f(7)),(f(8)),\
(f(9)),(f(10)),(f(11)),(f(12)),(f(13)),(f(14)),(f(15)),(f(16)),(f(17)),\
(f(18)),(f(19)),(f(20)),(f(21)),(f(22)),(f(23)),(f(24)),(f(25)),(f(26)),\
(f(27)),(f(28)),(f(29)),(f(30)),(f(31)),(f(32)),(f(33)),(f(34)),(f(35)),\
(f(36)),(f(37)),(f(38)),(f(39)),(f(40)),(f(41)),(f(42)),(f(43)),(f(44)),\
(f(45)),(f(46)),(f(47)),(f(48)),(f(49)),(f(50)),(f(51)),(f(52)),(f(53)),\
(f(54)),(f(55)),(f(56)),(f(57)),(f(58)),(f(59)),(f(60)),(f(61)),(f(62)),\
(f(63)))
, "PPMPF_MAP, 64 arguments, plain signature for f" )

PPMPF_TST( ppmpf_map64b
, PPMPF_MAP
, ((f,(__0)(__1,_(X))), PPMPF_NRANGE_TUP((0)(0)(0)(0), (0)(0)(6)(3)))
, (f(0,X),f(1,X),f(2,X),f(3,X),f(4,X),f(5,X),f(6,X),f(7,X),f(8,X),\
f(9,X),f(10,X),f(11,X),f(12,X),f(13,X),f(14,X),f(15,X),f(16,X),f(17,X),\
f(18,X),f(19,X),f(20,X),f(21,X),f(22,X),f(23,X),f(24,X),f(25,X),f(26,X),\
f(27,X),f(28,X),f(29,X),f(30,X),f(31,X),f(32,X),f(33,X),f(34,X),f(35,X),\
f(36,X),f(37,X),f(38,X),f(39,X),f(40,X),f(41,X),f(42,X),f(43,X),f(44,X),\
f(45,X),f(46,X),f(47,X),f(48,X),f(49,X),f(50,X),f(51,X),f(52,X),f(53,X),\
f(54,X),f(55,X),f(56,X),f(57,X),f(58,X),f(59,X),f(60,X),f(61,X),f(62,X),\
f(63,X))
, "PPMPF_MAP, 64 arguments, (f,(__0)(__1,_(X)))" )

PPMPF_TEST_BLOCK( ppmpf
, check_ppmpf_map
, ( ppmpf_map64a, ppmpf_map64b )
, true
, "testing PPMPF_MAP - 3rd generation - (tuples only)" )

PPMPF_TEST_MRUN(check_ppmpf_map)

0 comments on commit 4834e89

Please sign in to comment.