1

I want to know how to return a value after my function finishes running.

I have, for example:

FUNCTION X

? X ⍴ 10

//This means, generate X random numbers (X is the function's argument) within the range 1-10.

I just want to know how I can return the value of the function, and for example, pass it to another function.

Thank you for your help!

Elias Mårtenson
  • 3,820
  • 23
  • 32
idelara
  • 1,786
  • 4
  • 24
  • 48

2 Answers2

2

This is done in the Function header (code line 0).

It has the following form:

returnValue ← leftArgument functionName rightArgument ; localized_variables

So, whenever your function terminates, the value of the variable returnValue will be returned.

mappo
  • 444
  • 2
  • 9
  • I had figured it out from the manual (although I did not completely understand it). Thanks for your response man! Cheers! – idelara Mar 12 '15 at 07:56
2

Alternately, if your APL system supports it, you can use direct definition (dfns, lambdas). This should work in Dyalog, GNU, NARS2000, and NGN APL.

Try

  {?⍵⍴10} 42

⍵ is the function's argument (X in your example)

The return value is the result of the expression and does not have to be explicitly stated.

You can also do

  function←{?⍵⍴10}

then

  function 42
Lobachevsky
  • 1,222
  • 9
  • 17