# Can Whispers programs ignore a final output line?

This was first asked by Leo in the Whispers chat room:

But I have a general question about Whispers submissions: couldn't we avoid counting the final Output line most of the time? We can consider the rest of the program a function returning the desired output, printing it to the screen with a full program is not generally required for submissions

This seems, to me, as though an edge case of the general I/O formats, so posting an answer over to the I/O defaults may not allow for appropriate discussion.

For those unfamiliar with Whispers, programs work line-by-line where each line returns a specific value. Lines are "called" by other lines through references in order to get the value from that line. For example, the basic Hello World program:

> "Hello, World!"
>> Output 1


Try it online!

As you can probably figure out, the last line "calls" line 1 and outputs the result.

However, by Leo's argument above, an equally valid program per our I/O rules would be

> "Hello, World!"


as you could consider this a function which returns the string "Hello, World!" when "called" by another line referencing it.

This meets our requirements for a function (it is reusable, lines can be composed with arguments, lines can call other lines etc.), but it definitely isn't a standard function.

Thoughts? Should Whispers programs be allowed to ignore a final >> Output line and consider the rest of the program as a function that returns the output?

• The Hello, world! challenge doesn't allow functions anyway, so this may not be the best example. – Redwolf Programs Feb 9 at 18:37
• @RedwolfPrograms For the specific challenge, it doesn’t really apply. However, I wanted to choose a clear example that anyone would be able to understand and "Hello World" is sort of a quintessential programming example – caird coinheringaahing Feb 10 at 1:56

# Whispers lines are functions and they should follow our rules for functions

Since I was the one posing this question here's my opinion on this.

Each line in Whispers is a function. Most often, these functions take no input, call other functions, and return one output. Calling a function that takes no input is as simple as writing the corresponding line number (in the "Hello, World!" example line 2 calls the function line 1 and outputs the result of that).

A function can take up to two arguments, referred with the identifiers L and R. We can pass arguments to functions with the infix operator ∘ (only supports one argument) or with constructs like Each, ∑,∏,… (can use two arguments, special conditions apply).

With lines being functions our defaults for functions apply, including:

Combining these, we get that Whispers submissions may take input with the command Input or with the L/R arguments, and may produce output with the command Output or with the implicit return value of the main function line.

### Edit

Clarification, since I've seen people confused by this: you cannot just take any Whispers program, remove the first and last line and claim this is now a function. The submitted function needs to really work as a function.

In practice, if your program only produced output via a final >> Output N line, it should be enough to remove that and have line N be your function submission (with all other lines being auxiliary functions). Taking input via L/R generally needs bigger changes to your code, your main function will need to use L/R itself, and these values will need to be passed to any auxiliary function working on the input: this will not necessarily be shorter than the original program, and in some cases it may even be impossible to do. As a rule, your function should never refer to lines outside the function itself (this would be similar to taking input from pre-initialized variables).

Example:

>> Input
>> 1!
>> Output 2


This is a program that prints the factorial of an input number. We can turn it into a function by getting rid of the final output line:

>> Input
>> 1!


Now our line 2 is the function we are submitting, giving output via its return value. We can also decide to take input via argument L:

>> L!


And this can be our submission. We can write a full program to test it by calling the function on some input and printing its result to the screen: Try it online!.