Topic: default arguments - a new idea?
Author: "Mycroft Holmes" <holmes@technologist.com>
Date: Wed, 14 Mar 2001 18:02:58 GMT Raw View
--
The set of solutions is never empty.
Two solutions together form a new problem.
-- Mycroft Holmes
> forwarding functions to default variables even where
> the latter could be used in the current case.
??????????
Could you make an example?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Mycroft Holmes" <holmes@technologist.com>
Date: Wed, 14 Mar 2001 23:46:28 GMT Raw View
thanks.
--
The set of solutions is never empty.
Two solutions together form a new problem.
-- Mycroft Holmes
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Mycroft Holmes" <holmes@technologist.com>
Date: Wed, 14 Mar 2001 23:46:15 GMT Raw View
taken from FC++ intro manual:
"As you may expect, functional programming in C++ is
not without its limitations. The most obvious one for
functional programmers is the lack of a construct like
"lambda". C++ has no built-in support for defining new
functions inside an expression or creating automatic clo-sures,
capturing all variables from the local environment.
There are a number of "lambda libraries" for C++ [3][8]
which use expression-templates to simulate lambda syn-tax
(sometimes rather convincingly). Even these libraries,
however, cannot create automatic closures; to truly add
"lambda" to C++ would require a language extension."
^^^^^^^^^^^^^^^^^^^^^
--
The set of solutions is never empty.
Two solutions together form a new problem.
-- Mycroft Holmes
>
> To learn about this magic and more, check out
>
> http://www.cc.gatech.edu/~yannis/fc++/
>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Mycroft Holmes" <holmes@technologist.com>
Date: Mon, 12 Mar 2001 19:30:35 GMT Raw View
In my opinion c++ should be more flexible in supplying default arguments to
functions, both at high level and at low level.
As a draft idea, I'd add the following features to the language:
1. [low-level] an evaluator operator which rewrites the stack of a
function before calling it
I think about something like:
template <typename T>
T evaluator( T (*foo)(...), void* new_stack )
{
// create a stack for function 'foo' as usual
memcpy( stack, new_stack, sizeof(stack) );
// jump to body of 'foo' and return its return value
}
2. [hi-level] a binder for creating function pointers at run time
suppose I have
double foo(double x, double y, double z);
I'd like to write:
double (*func)(double) = foo( 3.14 , void , 4.28);
// where 'void' is used in a new meaning: it is a wildcard
this should be identical to:
double foo2(double t)
{ return foo( 3.14, t , 4.28); }
// ...
double (*func)(double) = foo2;
but *without compiling* foo2.
of course a workaround could be to define a class and overload its
operator(), BUT...
--
The set of solutions is never empty.
Two solutions together form a new problem.
-- Mycroft Holmes
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Mon, 12 Mar 2001 20:44:56 GMT Raw View
In article <98i7k2$r0a$1@stargate1.inet.it>, Mycroft Holmes
<holmes@technologist.com> writes
> I'd like to write:
>
> double (*func)(double) = foo( 3.14 , void , 4.28);
> // where 'void' is used in a new meaning: it is a wildcard
>
> this should be identical to:
>
> double foo2(double t)
> { return foo( 3.14, t , 4.28); }
> // ...
> double (*func)(double) = foo2;
I think you are heading in exactly the wrong direction. I would strongly
advocate preferring forwarding functions to default variables even where
the latter could be used in the current case. I cannot see any practical
reason for adding your proposed complexity to C++.
--
Francis Glassborow
See http://www.accu.org for details of The ACCU Spring Conference, 2001
(includes many regular participants to C & C++ newsgroups)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: gt5163b@prism.gatech.edu (Brian McNamara!)
Date: Mon, 12 Mar 2001 15:14:50 CST Raw View
"Mycroft Holmes" <holmes@technologist.com> once said:
>2. [hi-level] a binder for creating function pointers at run time
> suppose I have
>
> double foo(double x, double y, double z);
>
> I'd like to write:
>
> double (*func)(double) = foo( 3.14 , void , 4.28);
> // where 'void' is used in a new meaning: it is a wildcard
>
> this should be identical to:
>
> double foo2(double t)
> { return foo( 3.14, t , 4.28); }
> // ...
> double (*func)(double) = foo2;
>
>but *without compiling* foo2.
You can already do this easily with libraries. For example, with FC++,
you can say
// Can't change the behavior of builtins, so first we have to convert
// it to one of our classes:
Fun3<double,double,double,double> xfoo = foo;
// Then voila!
Fun1<double,double> func = xfoo(3.14,_,4.28); // fine
double x = func(6.43); // this works
x = xfoo(3.14,_,4.28)(6.43); // this does too
In this case, the wildcard is '_'.
(In general, FunN<X,Y,...,R> is just an abstraction of "R (*)(X,Y,...)"
where N is the number of arguments.)
To learn about this magic and more, check out
http://www.cc.gatech.edu/~yannis/fc++/
--
Brian M. McNamara lorgon@acm.org : I am a parsing fool!
** Reduce - Reuse - Recycle ** : (Where's my medication? ;) )
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]