[CMake] functions as first class objects

Jed Brown jed at 59A2.org
Thu Nov 19 09:44:47 EST 2009


Michael Wild wrote:
> 
> On 19. Nov, 2009, at 15:06 , Jed Brown wrote:
> 
>> Michael Wild wrote:
>>
>>> Not sure I'd like that... Instead of being more expressive, I think this
>>> would be very confusing.
>>
>> This is not a some magic beast coming out of functional languages.  In
>> fact, it's pretty hard to find a language that can't do this sort of
>> thing, even older Fortrans let you pass functions.
>>
>> Jed
> 
> Yes, but that's something completely different! It's not like you're
> able to do (using your notation):

(not my notation)

> set(&tmp &install)
> set(&install &add_executable)
> set(&add_executable &tmp)
> 
> In C/C++ and to various extent in Fortran (depending on the version) you
> can pass around "function pointers". This is _not_ a function. There's
> no way of doing that in C/C++ or Fortran (that is, without using ugly
> preprocessor magic).

CMake is untyped where as C, for example, is statically typed and only
allows symbols to be defined once (C++ breaks this with templates, but
you're supposed to be careful so that all definitions are equivalent).
In any case, you sure can do

  int (*Func)(int,int) = SomeFunction;
  int x = Func(5,6);
  int y = FoldL(Func,array,size,3);

and so on.

Jed
  

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091119/58fafd0f/attachment.pgp>


More information about the CMake mailing list