Click here to Skip to main content
15,042,336 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I do something like this?
four(plus(nine()))-> 13

I need to follow the exact same pattern. I would like to know how I can use parentheses. And yeah, plus should be a separate method as well.

What I have tried:

I implemented a similar approach but still I would need to call it differently:
function four (fn) {
  return fn(4)
function plusNine(arg) {
  return 9 + arg
four(plusNine) ///I can`t use parentheses, can I?
Updated 11-Aug-16 11:45am
David_Wimbley 11-Aug-16 9:45am
It seems to me the plus operator turned function call doesn't know to add four to the plus function parameter (in this case 9) due to not having called the four function at that time. In order to do that it would need to be restructured as the following i would think

plus(four(), nine()) -> 13

1 solution

It can't work this way.
The operator must have knowledge of all the values, it is the only possibility.
the only way is:
plus(four(),nine())-> 13

Otherwise, the only possibility is that plus is unique and in thos case plus is an empty shell and the functionality is moved in the four function.
Ralf Meier 12-Aug-16 7:52am
And additional every entered function-name must be checked (perhaps by reflection) if there is a corresponding and existing function. Otherwise this would fail ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900