Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a programming language that allows variable declaration at call site?
    primarykey
    data
    text
    <p><strong>Update 2:</strong> examples removed, because they were misleading. The ones below are more relevant.</p> <p>My question: </p> <p>Is there a programming language with such a construct?</p> <p><strong>Update:</strong> Now when I think about it, Prolog has something similar. I even allows defining operations at definition line. (forget about backtracking and relations - think about syntax)</p> <p>I asked this question because I believe, it's a nice thing to have symmetry in a language. Symmetry between "in" parameters and "out" parameters.</p> <p>If returning values like that would be easy, we could drop explicit returning in designed language.</p> <p>retruning pairs ... I think this is a hack. we do not need <em>a data structure</em> to pass multiple parameters to a function.</p> <p><strong>Update 2:</strong></p> <p>To give an example of syntax I'm looking for:</p> <pre><code>f (s, d&amp;) = // &amp; indicates 'out' variable d = s+s. main = f("say twice", &amp;twice) // &amp; indicates 'out' variable declaration print(twice) main2 = print (f("say twice", _)) </code></pre> <p>Or in functional + prolog style</p> <pre><code>f $s (s+s). // use $ to mark that s will get it's value in other part of the code main = f "say twice" $twice // on call site the second parameter will get it's value from print twice main2 = print (f "Say twice" $_) // anonymous variable </code></pre> <p>In a proposed language, there are no expressions, because all returns are through parameters. This would be cumbersome in situations where deep hierarchical function calls are natural. Lisp'ish example:</p> <pre><code>(let x (* (+ 1 2) (+ 3 4))) // equivalent to C x = ((1 + 2) * (3 + 4)) </code></pre> <p>would need in the language names for all temporary variables:</p> <pre><code>+ 1 2 res1 + 3 4 res2 * res1 res2 x </code></pre> <p>So I propose anonymous variables that turn a whole function call into value of this variable:</p> <pre><code>* (+ 1 2 _) (+ 3 4 _) </code></pre> <p>This is not very natural, because all the cultural baggage we have, but I want to <em>throw away</em> all preconceptions about syntax we currently have.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload