|
Boost Users : |
From: Simon Buchan (simon_at_[hidden])
Date: 2005-09-22 04:22:56
Foster Gareth wrote:
>>What's wrong with:
>>std::for_each
>>( as.begin
>>, as.end()
>>, bool some_function_keyword(A& a)
>> { return a.wee() & SOME_FLAG;
>> }
>>);
>>
>
>
> I think the previous poster (whos comments where appreciated) implied that
> while some languages (he mentioned Lisp and Perl I think, and I mentioned
> Java) could/do support this, C++ would struggle to. It would make things
> hairy for the compiler because a function definition is not preceeded by any
> keyword.
>
A normal function, no, but I believe (as I should, I wrote it! :) that
this syntax shouldn't have any problems. The keyword, (for the sake of
argument, 'inline') in place of where a function name would be in a
function definition, means an expression returning a type that the
function call syntax is legal on. (In this case, say, 'bool(A&)', for
lexically binding functions (where it refers to objects in it's
enclosing scope), 'inline<bool(A&)>', as it would behave like a functor)
Having statements inside an expression is a New Thing for C++, though.
What happens if you declare another inline function inside your inline
function, and return it as the result? (function composition) A lot of
kick-ass functional programming, thats what!
> I think you can also do things a bit like this in java ... Interesting
> perhaps that there is a keyword involved in this case, would this still bog
> down compilers so much as to outweight the advantages of the sytax style
> (assuming there are any, I'm happy to be argued out of thiking this kind of
> coding is neat).
>
> button_click_event.set_handler (
> new class : public button_click_event_handler {
> void on_click() {
> std::cout << "anon_class::on_click() :
> printing wee" << std::endl; }
> }
> );
>
Java (recently) has 'Anonymous Classes', which are kind of cool, but
syntaticly obese for most inline functions... Never used them myself,
though.
>
>>I don't know what a good function keyword name would be.
>>Obviously: fn, function, lambda are in common use everywhere
>>(and fn is too short for a C++ keyword! :D)
>>Reuse 'inline'?
>
>
> I suppose inline would make sense, but it might be a bit of a hack to have
> it used in two senses. I wonder if you can do this stuff in Delphi, they
> have a function keyword.
>
Well, so is 'template', 'typename', 'class' (sorta), (famously)
'static', and soon to be 'auto', so no biggy there. Anyway, inline is
used far less nowadays, (although not as little as auto :D) since
compilers are normally better than programmers at picking inline'able
functions.
>
> Thesaurus :)
>
> "
> function
>
> noun
>
> 1. The proper activity of a person or thing: job, purpose, role, task.
> See do/not do.
> 2. A large or important social gathering: affair, celebration, festivity,
> fete, gala, occasion, party, soiree. Informal do. Slang bash. See group,
> work/play.
>
> verb
>
> 1. To react in a specified way: act, behave, operate, perform, work. See
> action/inaction.
> 2. To perform a function effectively: go, operate, run, take, work. See
> thrive/fail/exist.
> 3. To perform the duties of another: act, officiate, serve. See do/not
> do, substitute.
> "
>
> Cheers for the responses anyway,
>
> Gaz
The last thing C++ needs is another keyword ;)
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net