Mirko Vukovic

2019-10-19 03:11:34 UTC

Hello,

As an example, consider a function that adds two numbers.

I want to call it by passing either two numbers, or functions

of zero arguments that evaluate to numbers:

(add-two 2 3)

or

(add-two 2 (lambda () 3))

or

(add-two (lambda() 2) (lambda () 3))

I will show my implimentation below. My questions are:

- Is there a name for this concept

- Is there a better way of doing it

My evantual goal is to do Monte Carlo runs on such functions.

The argument functions will return values generated by

random number generators.

Here is the definition of add-two:

(defun add-two (a b)

"Add two numbers

The arguments can hold either numeric values or functions of

zero arguments that return numeric values"

(let ((a (if (typep a 'function)

(funcall a)

a))

(b (if (typep b 'function)

(funcall b)

b)))

(+ a b)))

Thanks,

Mirko

As an example, consider a function that adds two numbers.

I want to call it by passing either two numbers, or functions

of zero arguments that evaluate to numbers:

(add-two 2 3)

or

(add-two 2 (lambda () 3))

or

(add-two (lambda() 2) (lambda () 3))

I will show my implimentation below. My questions are:

- Is there a name for this concept

- Is there a better way of doing it

My evantual goal is to do Monte Carlo runs on such functions.

The argument functions will return values generated by

random number generators.

Here is the definition of add-two:

(defun add-two (a b)

"Add two numbers

The arguments can hold either numeric values or functions of

zero arguments that return numeric values"

(let ((a (if (typep a 'function)

(funcall a)

a))

(b (if (typep b 'function)

(funcall b)

b)))

(+ a b)))

Thanks,

Mirko