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[]
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[]
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
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*x, [1,2,3]));
}
(I'm not talking about
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, funcint, int: int f) int
RETURN f(a, b)
}
And call it with:
IO.writeLine(add: .. someprocedure(2, 3, { a, b = a + b
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, funcint, int: int f) int
RETURN f(a, b)
}
And
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, funcint, int:
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
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 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
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
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,
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).
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
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
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_price,
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
Jonas H. jo...@lophus.org 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:
Timon Gehr timon.g...@gmx.ch 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 =
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
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
Actually, looks like you have done it already 2 years ago :)
http://d.puremagic.com/issues/show_bug.cgi?id=4505
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:
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
But is there any way to actually say D compiler that I want this
function to accept only pure delegates?
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
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
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
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
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
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
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
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;
}
return input;
}
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 Sun, 31 Oct 2010 20:24:59 -0600
Rainer Deyke rain...@eldwood.com 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
Jesse Phillips:
Since when?
You are right, what I have said doesn't apply to map/filter. Sorry for my silly
mistake.
Bye,
bearophile
On Sun, 31 Oct 2010 17:31:54 -0400
Nick Sabalausky a...@a.a wrote:
spir denis.s...@gmail.com 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
spir denis.s...@gmail.com wrote:
On Sun, 31 Oct 2010 17:31:54 -0400
Nick Sabalausky a...@a.a wrote:
spir denis.s...@gmail.com 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
39 matches
Mail list logo