The run-time performance of the library has been drastically improved. This has all been done "under the hood"; the interface to the library has barely changed. The main sources for the improvements are
List
sThe library now works with both g++2.95.2 and g++3.0. It should also work with any other standard-conforming C++ compiler. See this page for details.
There are now many more example files.
Fun3
class has finally been implemented. Like
Fun2
it supports automatic currying.IRef
(the intrusive version of
Ref
) has been added.ListIterator
now supports
operator->
.FCPP_DEBUG
turns on extra run-time checking
so that if you try to head()
or tail()
an
empty list, an exception (of type fcpp_exception
) is
thrown. Without the flag, there is no run-time check (and the code
fails un-gracefully).FCPP_SAFE_LIST
adds a destructor to the
List
class which ensures that list nodes are destroyed
iteratively. The reference-counting in list nodes
(Cache
s) works recursively, and as a result, can blow the
stack for large lists. In other words,
{ List<int> l = enumFromTo(1,200000); length(l); // force evaluation of the list (actually create nodes) } // Boom! Recursion with a call-depth of 200000.is likely to "blow up" unless the
FCPP_SAFE_LIST
flag is
set. Setting this flag degrades the overall performance of lists,
however. In order to ensure that a specific instance of a
list doesn't blow up, you can always just iteratively destroy that
list, as in
{ List<int> l = enumFromTo(1,200000); length(l); // force evaluation of the list (actually create nodes) while(l) l = tail(l); // iteratively destroys list } // no problem here
using namespace fcpp;at the end of
prelude.h
. As a result, you should add this
yourself to your .cc
files that use the library.
cat
has changed slightly. The first
parameter must be a list, but the second parameter can be either a list
or a function that returns a list. (It used to be that both parameters
could be either lists or functions.)Sig
s of Plus
, Minus
,
etc., now better reflect the true signatures of those functoids.OneElement
(one_element
) has been removed.
You should use cons(x,NIL)
instead.Nil<T>
has been removed. You should just use NIL
instead, unless type inference fails, in which case you can always use
List<T>()
.FCPP_LEAK
turns off the reference counting in
the IRef
class. As a result, the application leaks
away memory (but might run faster).enumFrom()
and
enumFromTo()
be template functoids rather than just
functoids that work on int
s. They really probably should be
template functoids, however g++2.95.2 seems to generate slow code for
them when they templated, for no obvious reason. (g++3 generates fast
code regardless of whether the functoids are templated or not.)main()
). This helped us debug order-of-initialization
errors.OddList
s, Reuser
s, and iteration. The old
implementations of many of the functions are still there, enclosed in
#ifdef FCPP_SIMPLE_LIST
s. We've kept the old
implementations in the file mostly for instructional value (they
illustrate the simplest ways to create functoids, and also help show
the changes necessary to create optimized versions of functoids).The library now compiles with the "-pedantic -ansi" options for g++, which means it will probably compile with more other compilers now, too. The previous release had a number of "typename" problems; C++ requires the "typename" keyword to appear in lots of places inside templates.
minus(3,2); // yields 1 minus(3); // yields a new function f, where f(x) = 3-x minus(3,_); // same as above minus(_,2); // yields a new function f, where f(x) = x-2This is accomplished by the
CurryableN
classes, which
serve as wrappers around normal functions. The function
makeCurryable()
turns an uncurryable function into an
automatically curryable version. See http://www.cs.umass.edu/~yannis/fc++/currying.html
for more info.fcpp
. However, bugs in the g++2.95.2 compiler force us to keep
part of the library in the global namespace. If you have a working
compiler, use the compiler option -DFCPP_USE_NAMESPACE to have the whole
library be in the namespace. There's a
using namespace fcpp;at the bottom of
prelude.h
, which dumps it all
into the global namespace anyway. We've done that for backwards
compatibility (you can drop in the new library and your old code should
still work without changes), but feel free to remove it (we certainly
will, in a future revision).FunN
s). For example,
Fun1<int,int,int> f = fcpp::plus; Fun1<double,double,double> g = fcpp::plus;both "do the right thing".
ptr_to_fun()
, monomorphizeN()
,
CurryableN
, etc.) work for all sets of functions with 0-3
arguments. (Previous versions of FC++ had spotty support.)List
class has been completely re-implemented.
The old version had a number of problems (the major ones being that (1)
it was too eager (not lazy enough) in a number of cases, and (2) that
functions like cons
had un-intuitive interfaces) that have
now been solved. In our limited tests, the new List
seems
to perform comparably with the old, but let us know if you notice a
speed difference.List::WrappedType
has been renamed to
List::ElementType
. The new name makes more sense,
especially in papers/tutorials.list_until
has been renamed
listUntil
(consistent with
naming convention of other list functions).