openlang

Returning results from an APL function

How do I make my function return something once execution has finished?

For instance, I have:

ROUTINE N

? N ⍴ 12

//That generates N random values (N being the argument to the function) between 1 and 12.

I'd simply like to understand how to get the function's result back and, for instance, supply that result to a different function.

Thanks for any assistance!

The conversation continues 2

Follow the reasoning
  1. Permalink

    You specify that in the function's header (the line numbered 0).

    The syntax looks like this:

    answer ← lhs calculate rhs ; local_names

    Then, when execution of your function ends, it returns whatever is stored in answer.

  2. Permalink

    Another possibility, provided your APL implementation allows it, is direct definition (dfns or lambdas). This should work with Dyalog and GNU, plus NARS2000 and NGN APL.

    Try this

    {?⍵⍴12} 36

    The argument is represented by ⍵ (N in the question)

    Whatever the expression produces becomes the result, without requiring an explicit return declaration.

    Another possibility is

    calculate←{?⍵⍴12}

    followed by

    calculate 36

Other sides of the same question

  1. Choosing enum entries randomly with GDScript in Godot 3.3 without listing each one?

    Here's the enum declaration I'm using in GDScript: I'd like to choose an enum variant randomly without listing every possible…

    Replies 2Latest activity gdscript
  2. Nim remainder syntax

    How is modulus expressed in Nim? cell % 7 == 0 gives undeclared identifier: '%' Neither a Google search nor looking through S…

    Replies 2Latest activity nim
  3. Declaring an array containing constant strings

    Is it possible for Delphi to declare a string array using something like the example below?

    Replies 4Latest activity object-pascal