I am designing a DSL for writing numerical simulations. I am working on a specific issue related to returning values from functions, and I am wondering if any other existing language solves the same problem.A toy example of a basic simulation kernel in my DSL looks something like this:function MySimulationKernel()    res1 = foo1()    res2 = foo2()    res3 = foo3()    res4 = foo4()endOnce the simulation kernel has been implemented, I would like to run it and collect the simulation results. The problem is that which result(s) need to be collected is not known by the function.For example, one user of MySimulationKernel might only need the value of res1, however another user might need res1 and res4. In this example, we have 4 different such values, so there are 16 possible combinations of output values:$16 = {4 \choose 0} + {4 \choose 1} + {4 \choose 2} + {4 \choose 3} + {4 \choose 4}$In practice, we have hundreds of these possible output values from a simulation kernel. It does not make sense for the simulation kernel to list out its possible result values, it is safe to assume that any local variable of the function is a potential result that the simulation user needs to collect from a function call. Essentially, it seems that what to return is a separate concern from what to compute. The simulation kernel is concerned with what to compute, and it would be preferable if that code was not cluttered at all with any logic about what to return since that is a separate concern. The function callee must somehow specify what to return, and that is properly a concern of the function callee.Note that the type and size of these different result values can vary drastically. In some cases, a result is just a single floating-point value (and would be highly efficient to return from the function). But in other cases, the result value could be a multi-gigabyte array and outputting that array from the simulation has a very high computational cost, so we want to avoid returning values unless they are requested at the function call. What I am looking for are example of how other languages might solve this problem. It seems like such a simple problem that others must have already encountered and solved it (I hope). Any pointers in the right direction would be helpful. The closest I solutions I found are the Policy-Based Design / Strategy Pattern [1], and Aspect-Oriented programming [2]. These solutions are definitely overkill for the problem I am trying to solve. They also require a heavy-duty object-oriented language, which doesn't make a lot sense in this DSL. [1] https://en.wikipedia.org/wiki/Policy-based_design[2] https://en.wikipedia.org/wiki/Aspect-oriented_programming
Languages with Multiple Arbitrary Return Values
programming languages;language design;domain specific languages