1 [/==============================================================================
2 Copyright (C) 2001-2010 Joel de Guzman
3 Copyright (C) 2001-2005 Dan Marsden
4 Copyright (C) 2001-2010 Thomas Heller
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 ===============================================================================/]
12 Values are functions! Examples:
17 The first evaluates to a nullary function (a function taking no arguments) that
18 returns an `int`, `3`. The second evaluates to a nullary function that returns
19 a `char const(&)[13]`, `"Hello, World"`.
21 [heading Lazy Evaluation]
23 Confused? `val` is a unary function and `val(3)` invokes it, you say?
24 Yes. However, read carefully: /"evaluates to a nullary function"/.
25 `val(3)` evaluates to (returns) a nullary function. Aha! `val(3)`
26 returns a function! So, since `val(3)` returns a function, you can
29 std::cout << val(3)() << std::endl;
31 (See [@../../example/values.cpp values.cpp])
33 [blurb __tip__ Learn more about values [link phoenix.modules.core.values here.]]
35 The second function call (the one with no arguments) calls the nullary function
36 which then returns `3`. The need for a second function call is the reason why
37 the function is said to be [*/Lazily Evaluated/]. The first call doesn't do
38 anything. You need a second call to finally evaluate the thing. The first call
39 lazily evaluates the function; i.e. doesn't do anything and defers the evaluation
44 It may not be immediately apparent how lazy evaluation can be useful by just
45 looking at the example above. Putting the first and second function call in a
46 single line is really not very useful. However, thinking of `val(3)` as a
47 callback function (and in most cases they are actually used that way), will make
60 print(val("Hello World"));
64 (See [@../../example/callback.cpp callback.cpp])