Advertisements

Eric Smith wrote:
> How do I get a function foo() below to return both `1+1' and `2' ?
> foo( 1+1 );

You don't.
Your function foo() recieves only one argument which is the result of the
evaluation of the expression 1+1 which happens to be 2.
foo() has no way of knowing that there was anything else.

If you want foo() to know about the "literal" argument, then you need to
pass that as a text string:

foo ('1+1');

Or, depending on what your original problem is, maybe make it a
three-argument call:

foo( 1, '+', 1);

But I got a feeling that we are looking at an x-y problem. Meaning, you got
a problem x and you believe that y would be the best way to solve it,
therefore you are asking how to do y.
What is your x? Chances are there is a better way to do it then have
functions backtrack their arguments (which is not possible anyway).

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!