Serving the Quantitative Finance Community

Cuchulainn
Topic Author
Posts: 64081
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Quizzies, Brainteasers: Functional Programming in C++

Quiz
Consider a scalar-valued function of arity n $f = f(x_1,... ,x_n)$ From this function we want to fix $n-1$ arbitrary arguments leaving one argument free as it were, resulting in a (higher-order) function of arity 1.. The idea is to cycle over each argument from 1 to n, thereby creating a function of arity 1.

ex
f(x,y,z)

g1(x) = f(x, 2.0, 1.0)
g2(y) = f(2.0, y, 1.0)
g3(z) = f(2.0, 2.0, z)

Can it be done?

I bet Mathematica or Haskell yes?

ppauper
Posts: 70239
Joined: November 15th, 2001, 1:29 pm

### Re: Quizzies, Brainteasers: Functional Programming in C++

I'm not sure what you're trying to do.
If the goal is to do what you did in the example, then didn't you already do it?

Cuchulainn
Topic Author
Posts: 64081
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: Quizzies, Brainteasers: Functional Programming in C++

I'm not sure what you're trying to do.
If the goal is to do what you did in the example, then didn't you already do it?
But i want to do it for any function of any arity n = 1,2,3,...
The compile-time example was only an example to show the intent.

At run-time I want to do it for a variable number of arguments that is only known at run-time.

ppauper
Posts: 70239
Joined: November 15th, 2001, 1:29 pm

### Re: Quizzies, Brainteasers: Functional Programming in C++

THIS?

IMPLICIT DOUBLE PRECISION (A-H,L,O-Z)
IMPLICIT INTEGER (I-K,M-N)
PARAMETER (N=20)
DIMENSION G(N),X(N),Y(N),X0(N)
DO 110 J=1,N
Y(J)=X0(J)
110 CONTINUE
DO 100 I=1,N
Y(I)=X(I)
G(I)=F(Y)
Y(I)=X0(I)
100 CONTINUE
END

DOUBLE PRECISION FUNCTION F(X)
IMPLICIT DOUBLE PRECISION (A-H,L,O-Z)
IMPLICIT INTEGER (I-K,M-N)
DIMENSION X(*)
F = DSIN(X(1))
RETURN
END

Cuchulainn
Topic Author
Posts: 64081
Joined: July 16th, 2004, 7:38 am
Location: Drosophila melanogaster
Contact:

### Re: Quizzies, Brainteasers: Functional Programming in C++

is this bad practice in C++
int netbuf[4* 1000000];