thanks a lot both! Yes I'm aware that map exists already. This
was didactic. I had tried to find out whether lambdas generate
function pointers but also couldn't figure that one out :D
On Monday, 21 February 2022 at 10:04:16 UTC, steve wrote:
I am trying to implement a simple map function. I found code to
do this in another post but it only seems to work with lambda
functions and I do not understand why. Any help would be
greatly appreciated
```
import std.stdio;
T[] map_v
On Monday, 21 February 2022 at 10:04:16 UTC, steve wrote:
I am trying to implement a simple map function. I found code to
do this in another post but it only seems to work with lambda
functions and I do not understand why. Any help would be
greatly appreciated
```
import std.stdio;
T[] map_v
I am trying to implement a simple map function. I found code to
do this in another post but it only seems to work with lambda
functions and I do not understand why. Any help would be greatly
appreciated
```
import std.stdio;
T[] map_vals(T,S)(scope T function(S) f, S[] a){
auto b = new T[
On Wed, Apr 11, 2012 at 07:29:20PM +0200, Jonas H. wrote:
> Wow, thanks for all the answers! Seems to be a great community here.
Welcome to the community! :-)
> What do you guys think about adding the term "anonymous functions"
> to the frontpage and features page? I think that one's a lot more
Wow, thanks for all the answers! Seems to be a great community here.
What do you guys think about adding the term "anonymous functions" to
the frontpage and features page? I think that one's a lot more comman
than "delegates" (even if it's not exactly the same thing).
Apparently your compiler does not support parameter type
deduction yet.
void main ()
{
writeln("add: ", someprocedure(2, 3, (int a, int b) {
return a + b; }));
writeln("multiply: ", someprocedure(2, 3, (int a, int b) {
return a * b; }));
}
Yes, now it works!
Thanks,
On 04/11/2012 11:51 AM, Xan wrote:
On Wednesday, 11 April 2012 at 09:43:27 UTC, Timon Gehr wrote:
On 04/11/2012 11:37 AM, Xan wrote:
On Wednesday, 11 April 2012 at 09:17:12 UTC, Jacob Carlborg wrote:
On 2012-04-11 10:45, Xan wrote:
Good answer.
For the other hand, what is the simplest method
On Wednesday, 11 April 2012 at 10:14:21 UTC, Mirko Pilger wrote:
What is the error?
e.g. try this:
auto someprocedure (int a, int b, int delegate (int, int) f)
I receive the same error
What is the error?
e.g. try this:
auto someprocedure (int a, int b, int delegate (int, int) f)
On Wednesday, 11 April 2012 at 09:43:27 UTC, Timon Gehr wrote:
On 04/11/2012 11:37 AM, Xan wrote:
On Wednesday, 11 April 2012 at 09:17:12 UTC, Jacob Carlborg
wrote:
On 2012-04-11 10:45, Xan wrote:
Good answer.
For the other hand, what is the simplest method for
implementing this
(in pseucod
On 04/11/2012 11:37 AM, Xan wrote:
On Wednesday, 11 April 2012 at 09:17:12 UTC, Jacob Carlborg wrote:
On 2012-04-11 10:45, Xan wrote:
Good answer.
For the other hand, what is the simplest method for implementing this
(in pseucode) in D:
Sure:
FUNC someprocedure(int a, int b, func f) int
RETU
On Wednesday, 11 April 2012 at 09:17:12 UTC, Jacob Carlborg wrote:
On 2012-04-11 10:45, Xan wrote:
Good answer.
For the other hand, what is the simplest method for
implementing this
(in pseucode) in D:
Sure:
FUNC someprocedure(int a, int b, func f) int
RETURN f(a, b)
}
And call it with:
I
On 2012-04-11 10:45, Xan wrote:
Good answer.
For the other hand, what is the simplest method for implementing this
(in pseucode) in D:
Sure:
FUNC someprocedure(int a, int b, func f) int
RETURN f(a, b)
}
And call it with:
IO.writeLine("add: " .. someprocedure(2, 3, { a, b => a + b }))
IO.writ
order function facilities?
D has full runtime support for higher-order functions and
closures.
import std.stdio;
int[] map(scope int delegate(int) f, int[] a){
auto b = new int[a.length];
foreach(i,x;a) b[i] = f(x);
return b;
}
void main(){
int a = 2;
writeln(map(x=>a
"Timon Gehr" wrote in message
news:jm2hnp$s0s$1...@digitalmars.com...
>
> (Well, the standard way to do what that python code does is using
> templates.
>
> auto car_prices = map!(car => car.get_price)(list_of_cars);// lazy range
> auto car_prices = array(map!(car => car.get_price(list_of_cars))
"Jonas H." wrote in message
news:mailman.1600.1334099651.4860.digitalmars-d-le...@puremagic.com...
> Hi everyone,
>
> does D have any runtime higher-order function facilities? (I'm not talking
> about templates.)
>
Yes. Fully. Many are already in the std lib:
http://dlang.org/phobos/std_algori
On 04/11/2012 01:13 AM, Jonas H. wrote:
Hi everyone,
does D have any runtime higher-order function facilities?
D has full runtime support for higher-order functions and closures.
import std.stdio;
int[] map(scope int delegate(int) f, int[] a){
auto b = new int[a.length];
foreach(i,x
On Wed, Apr 11, 2012 at 01:13:17AM +0200, Jonas H. wrote:
> Hi everyone,
>
> does D have any runtime higher-order function facilities? (I'm not
> talking about templates.)
>
> More specifically, is something like this possible? (That's how I'd
> do it in Python)
>
> car_prices = map(Car.get_pric
Hi everyone,
does D have any runtime higher-order function facilities? (I'm not
talking about templates.)
More specifically, is something like this possible? (That's how I'd do
it in Python)
car_prices = map(Car.get_price, list_of_cars)
car = new Car
foobar(car.get_price)
Thanks
Jonas
Actually, looks like you have done it already 2 years ago :)
http://d.puremagic.com/issues/show_bug.cgi?id=4505
mist:
> Are there any reasons for this inconsistency?
I don't know. Maybe it's just a parser bug. There are some of those in Bugzilla.
If you don't like it, then I suggest you to add it to D Bugzilla.
Bye,
bearophile
Ok, finally understood.
I was trying to declare hof like this: void f2( pure int
function() param ) , similar to the way I declare usual pure
functions. Looks like it is syntax error and only void f2( int
function() pure param ) is allowed. That led me to false
conclusion, that such signature
On Thursday, February 23, 2012 21:17:46 mist wrote:
> But is there any way to actually say D compiler that I want this
> function to accept only pure delegates?
Mark the delegate type that it accepts as pure.
- Jonathan M Davis
But is there any way to actually say D compiler that I want this
function to accept only pure delegates?
Le 23/02/2012 21:00, mist a écrit :
Hello!
I have been asked few question recently from a Haskell programmer about
D2 and, after experimenting a bit, have found that I really can't
provide a good answe myself, as I am not getting a design limititations
(if any).
Here is the snippet, it is prett
Hello!
I have been asked few question recently from a Haskell programmer
about D2 and, after experimenting a bit, have found that I really
can't provide a good answe myself, as I am not getting a design
limititations (if any).
Here is the snippet, it is pretty self-descriptive:
http://codepa
>
> Philippe Sigaud's template document covers everything about templates:
>
>https://github.com/PhilippeSigaud/D-templates-tutorial
>
> (Just download the pdf there.)
This should be on the website.
On 01/20/2012 08:43 AM, Jerome BENOIT wrote:
> -
> T[] find(alias pred, T)(T[] input)
> if (is(typeof(pred(input[0])) == bool)) {
> for(; input.length > 0; input = input[1 .. $]) {
> if (pred(input[0])) break;
>>>
On 20/01/12 17:23, Alex Rønne Petersen wrote:
On 20-01-2012 17:14, Jerome BENOIT wrote:
Hello Again:
On 20/01/12 15:58, Alex Rønne Petersen wrote:
On 20-01-2012 15:32, Jerome BENOIT wrote:
Hello List:
In tDlp book in section 5.6 entitled `Higher-Order Functions. Function
Literals,
the
On 20-01-2012 17:14, Jerome BENOIT wrote:
Hello Again:
On 20/01/12 15:58, Alex Rønne Petersen wrote:
On 20-01-2012 15:32, Jerome BENOIT wrote:
Hello List:
In tDlp book in section 5.6 entitled `Higher-Order Functions. Function
Literals,
the first code example is
Hello Again:
On 20/01/12 15:58, Alex Rønne Petersen wrote:
On 20-01-2012 15:32, Jerome BENOIT wrote:
Hello List:
In tDlp book in section 5.6 entitled `Higher-Order Functions. Function
Literals,
the first code example is:
-
T
Thanks.
Let go further.
On 20/01/12 15:58, Alex Rønne Petersen wrote:
On 20-01-2012 15:32, Jerome BENOIT wrote:
Hello List:
In tDlp book in section 5.6 entitled `Higher-Order Functions. Function
Literals,
the first code example is
On 20-01-2012 15:32, Jerome BENOIT wrote:
Hello List:
In tDlp book in section 5.6 entitled `Higher-Order Functions. Function
Literals,
the first code example is:
-
T[] find(alias pred, T)(T[] input)
if (is(typeof(pred(input[0
Hello List:
In tDlp book in section 5.6 entitled `Higher-Order Functions. Function Literals,
the first code example is:
-
T[] find(alias pred, T)(T[] input)
if (is(typeof(pred(input[0])) == bool)) {
for
On Sun, 31 Oct 2010 19:20:04 -0400, bearophile
wrote:
Simen kjaeraas:
They take both, in fact:
auto cubes = map!((a){ return a*a*a; })(arr);
But that needs to be compile-time constant, so if you have several
functions, you need to put them inside a typetuple, or duplicate the
code. A
Jesse Phillips:
> Since when?
You are right, what I have said doesn't apply to map/filter. Sorry for my silly
mistake.
Bye,
bearophile
bearophile Wrote:
> Simen kjaeraas:
>
> > They take both, in fact:
> >
> > auto cubes = map!((a){ return a*a*a; })(arr);
>
> But that needs to be compile-time constant, so if you have several functions,
> you need to put them inside a typetuple, or duplicate the code. And some
> idioms are ju
On Sun, 31 Oct 2010 20:24:59 -0600
Rainer Deyke wrote:
> On 10/31/2010 16:57, Simen kjaeraas wrote:
> > For very short functions, strings are better, because of the length of
> > the 'return' keyword. Had D instead always returned the result of the
> > last line of a function (unless specified to
On 10/31/2010 16:57, Simen kjaeraas wrote:
> For very short functions, strings are better, because of the length of
> the 'return' keyword. Had D instead always returned the result of the
> last line of a function (unless specified to be of void return type),
> map/filter/reduce would likely not ta
Simen kjaeraas:
> They take both, in fact:
>
> auto cubes = map!((a){ return a*a*a; })(arr);
But that needs to be compile-time constant, so if you have several functions,
you need to put them inside a typetuple, or duplicate the code. And some idioms
are just not possible.
You may see it well
spir wrote:
On Sun, 31 Oct 2010 17:31:54 -0400
"Nick Sabalausky" wrote:
"spir" wrote in message
news:mailman.45.1288523296.21107.digitalmars-d-le...@puremagic.com...
>
>Also, I could not find functional methods like map, filter,
> reduce in std.functional. Where else? Also not in std.array.
On Sun, 31 Oct 2010 17:31:54 -0400
"Nick Sabalausky" wrote:
> "spir" wrote in message
> news:mailman.45.1288523296.21107.digitalmars-d-le...@puremagic.com...
> >
> >Also, I could not find functional methods like map, filter,
> > reduce in std.functional. Where else? Also not in std.array.
>
>
43 matches
Mail list logo