# Default for Code Golf: Input/Output methods

It looks like we have a consensus that we want certain defaults for the format which answers are expected in for . On that poll, the question arose twice, which input/output formats should be allowed for programs and functions.

So here is another poll. This one works different though. All the input/output methods are independent of each other, so there will be one answer per method. Upvote all you think are reasonable for the default. Downvote those which you think shouldn't be allowed unless the OP explicitly permits them.

To keep this remotely manageable, I have not posted individual answers for all possible inputs for functions. So there are only four: functions can take input/output via their arguments and return values. Or functions can use any method full programs can. I don't think there is any point in (say) allowing programs to take input from STDIN (only) and to allow functions to take input from ARGV (only) or something like that. If you disagree, please leave a comment.

Note: Some votes have been reverted because they were detected as serial voting. If you vote on multiple answers, please leave some time between votes.

A method is allowed if it has 5 net votes and at least twice as many upvotes as downvotes.

### Update

The current results of the polls are now part of the tag wiki. Please notify me, if results change significantly and the wiki should be amended.

• Related (Can numeric input/output be in the form of byte values) – mbomb007 Dec 13 '16 at 16:10
• "The current results of the polls are now part of the tag wiki" which tag wiki? meta wiki has nothing for code-golf tag. ppcg wiki has codegolf.stackexchange.com/tags/code-golf/info but it's missing a lot of answers here. – Sparr Jul 18 '18 at 18:17

# Regexes may output via the list of matched strings (the captured group 0)

• We now have Retina for regex so this can – CalculatorFeline Apr 2 '16 at 16:13
• @CalculatorFeline Retina is actually Turing Complete. – mbomb007 Feb 17 '17 at 19:14
• ...I'm confused. – CalculatorFeline Feb 20 '17 at 23:34
• @CalculatorFeline: Retina is more powerful than plain regex is, due to the way it redefined the backquote character (which just matches itself literally in most regex syntaxes). That's enough to make it Turing complete. – user62131 Apr 27 '17 at 15:56
• True. But Retina is basically regex+. Do we need this anymore? – CalculatorFeline Apr 28 '17 at 21:59
• I don't think using plain regex is even allowed, since it isn't Turing complete. – 12Me21 Mar 2 '18 at 2:22

# Functions may return their result in an optional type wrapper

By "optional type wrapper" I mean something like Maybe a in Haskell, Option<T> in Rust, etc.

The consensus was that this should be allowed because it functions like a singleton wrapper, or like a possibly-erroring function that never actually errors.

# CGI scripts may take input via GET/POST parameters

A CGI script required to take, e.g., three inputs can be expected to be called as the GET request

GET script.cgi?<A>=<1st input>&<B>=<2nd input>&<C>=<3rd input> HTTP/1.1


(where A, B and C are keys of the poster's choice) of the equivalent POST request.

• Also, PHP<5.4.0 (exclude) has the directive register_globals (enabled by default up to PHP4.1), which allows you to use POST, GET, COOKIE, SESSION and what-not. It creates the variables with the names of the keys (E.g.: a.php?a=1 would create $_GET[a] (version-dependent) and the variable $a with value 1). This was removed due to security reasons, but was a standard feature that was (fortunally) removed. – Ismael Miguel Nov 27 '15 at 17:52
• Also, would parse_str($_SERVER[QUERY_STRING]) be a valid input method? It does exactly the same as register_globals, but reads input parameters from a superglobal and parse them into variables. This is explained in the documentation: php.net/manual/en/function.parse-str.php – Ismael Miguel Nov 27 '15 at 18:01 • This proposed a specific input method. What language features you use to access that input is up to you. – Dennis Nov 27 '15 at 18:20 • Then using $_GET (superglobal with all GET parameters, in PHP) fits the "What language features you use to access that input is up to you", right? – Ismael Miguel Nov 27 '15 at 18:25
• Yes, it does, assuming a GET request becomes an accepted input input. – Dennis Nov 27 '15 at 18:37
• Then there is the program <?php eval(key($_GET));. (SQL table input may have similar problems.) – jimmy23013 Nov 27 '15 at 18:51 • @jimmy23013 PHP4.1: <?eval($c); (assuming short_tags and register_globals, the code can be anywhere, even in a cookie (if below 4kb)). Or even <?eval(fgets(STDIN)). Or, for Javascript, eval(prompt()). Or eval "$s" for bash. Other languages have the same problem. Any language that allows evaluation of a string containing code has the same problem – Ismael Miguel Nov 27 '15 at 20:19 • @Dennis Would eval(return {${location.hash}}), assuming your URL is http://example.com/#a:"value",other:"value", fit in this definition? – Ismael Miguel Nov 27 '15 at 20:32
• @IsmaelMiguel As written, no. Those are neither GET nor POST parameters. – Dennis Nov 27 '15 at 20:34
• @Dennis What about eval(location.search.replace(/^\?/,''))? It would create every single variable you would need, right away (if the input is numeric and not an array). The location.search will contain all the GET parameters, optionally starting with an ?. – Ismael Miguel Nov 27 '15 at 20:38
• This can also be done with php -r '<code>' <A>=<input1> <B>=<input2> (or php-cli, depending on your distribution/installation), which alleviates the need for a web server (a much better option IMO). In this case, scoring is much easier: the -r flag would cost 2 bytes, but the ability to drop the leading <? in the code balances it out. Each GET parameter would cost 1 byte (for the =) plus the length of the parameter name. – Mego Nov 28 '15 at 6:11
• @Mego The -r is free. Read: meta.codegolf.stackexchange.com/q/2424/14732 – Ismael Miguel Nov 28 '15 at 22:44
• @IsmaelMiguel Fair enough. The rest of my comment still stands. – Mego Nov 28 '15 at 23:42
• @Mego It's still under discussion. – Ismael Miguel Nov 29 '15 at 1:09
• @IsmaelMiguel Hence why I offered my opinion – Mego Nov 29 '15 at 1:58

## Input and output of a single value may be represented as a singleton list

For example, if the value was 4, [4] would be an acceptable representation (using Python list syntax).

• This is useful in array languages like J. – Esolanging Fruit Apr 26 '17 at 16:51

# black-box functions to be taken as input can be passed as an argument

This holds for functional languages or languanges that do have first class functions/anonymous functions/lambda functions or function pointers, for instance: Java, JavaScript, C++, TI-Basic, Python, Octave, Matlab, Haskell, Lisp

• Huh? I'm confused what makes this different from passing inputs as arguments in general. – Solomon Ucko Sep 30 '18 at 3:24
• @SolomonUcko You mean as opposed to other non-function input types? In that case nothing, but this should just serve as an additional clarification as we introduced black-box functions just last year into our rules. Also consider these two entries: codegolf.meta.stackexchange.com/a/13713/24877 codegolf.meta.stackexchange.com/a/13707/24877 – flawr Sep 30 '18 at 12:07

# An array may be represented in input as a pointer and length.

For example in C you could use:

int f(int*p,int l){...}

• Do you think it should be restricted to C? – Keyu Gan Jul 12 '17 at 3:46
• @KeyuGan I think it should be allowed in any language with pointers (c++, asm ...). Do you know of a language where this would be a problem? – MegaTom Jul 12 '17 at 13:25
• I don't know whether a language exists where both pointer and array are well-defined. Under such circumstances, it may benefit a lot from this rule. I would still suggest languages which does not regard an array of general type as a first-class object may use a reference to first element and length to replace with array/list inputs. – Keyu Gan Jul 14 '17 at 9:12
• I'd say this should only be for a language where this is the natural representation of an array – Justin Jul 19 '17 at 20:15
• @keyugan C# supports both standard arrays and C-style pointers – Pavel Nov 8 '17 at 23:51
• @Pavel It is the same situation with C++. As for C# (I'm not an expert), many answers are based on LINQ and seemingly they cannot be shortened in this way. Besides, I will say yes to use pointer / length encapsule here. I think it will be better if we could give some restrictions on what language could do so, according to meta discussion, while the original answer doesn't. codegolf.meta.stackexchange.com/questions/13210/… – Keyu Gan Nov 9 '17 at 9:17
• @KeyuGan It's just a technicallity really, the only concievable reason to use pointer types in C# is for interop with native code. It probably won't ever apply. – Pavel Nov 9 '17 at 15:06
• @KeyuGan Please don't make drastic changes to suggestions. – Mego Nov 12 '17 at 4:56

# Submissions may use list of strings instead of multi-line strings

Input or output may be the equivalent of the string separated by newlines. For example, the multiline string:

1
2
Fizz
4
Buzz


May be instead be taken as a list of strings like:

["1","2","Fizz","4","Buzz"]

• I always see comments about this in multiline challenges, so I thought I'd throw this up there and see if it is well-recieved as a standard form of input – Jo King Nov 13 '18 at 11:54
• I would add an exception for ascii-art as linebreaks can be an important part of those challenges. – lirtosiast Nov 19 '18 at 19:43

# I/O for sequence questions may either be 0-indexed or 1-indexed

Any question that has the user output the $$\n\$$th term, first $$\n\$$ terms, etc. of a sequence should allow programs to index the first element of the sequence as 0 or 1 at the answerer's choice, as long as the program is consistent.

• This is now allowed by the sequence tag default. – lirtosiast Jul 18 '19 at 20:44

# Functions may return a function that returns the result

This is very similar to currying, the only difference being that only the first call includes an argument. Sometimes it's useful to curry a recursive function that has only one argument, especially if that argument doesn't need to be modified to find the result. For example, each of these JavaScript functions returns the bit-length of a positive integer:

f=(n,x)=>n?f(n>>1,-~x):x
f=(n,x)=>n>>x?f(n,-~x):x
n=>f=x=>n>>x?f(-~x):x


All three functions can be called by assigning them to g and calling them with e.g. g(49); however, the third version must be called again with g(49)() to actually return the result. Again, this is very similar to currying, where the arguments are passed separately (g(a)(b) rather than g(a,b)).

Note that no additional input should be needed to get the result (i.e. "to call on a number x, use f(x)(2)"). Optional arguments are fine, of course (x=>(y=2)=>x+y).

There is also a meta post about this here, though it was closed as a duplicate of this question.

• The only restriction I'd like to see on this is that no additional input should be needed to fetch the result. In other words, the returned function should take no mandatory arguments (optional arguments are fine), so that f(whatever)() would return the result. Otherwise, it falls under additional unspecified input, and therefore violates that loophole. – Mego Mar 20 '17 at 4:12
• @Mego Thanks, I agree. I thought that was implicit, but I've added a mention to the post. – ETHproductions Mar 20 '17 at 16:36
• How many brackets at the last is allowed? 1? or allowed if not that large(only avoid loophole) – l4m2 Dec 20 '17 at 2:02
• @l4m2 I'm only vouching for one extra function call here; you could write another answer allowing multiple extraneous calls if you wish. – ETHproductions Dec 21 '17 at 15:31
• @l4m2, I thought about any constant (not related to input) number. – Qwertiy May 25 '19 at 22:21

# Programs may take input from a file

• ... only if makes sense for the challenge, and even then you should input a file name first... I'd say – John Dvorak Nov 3 '14 at 6:32
• @JanDvorak That's a "no", because that makes the file name itself the input (which you would take from STDIN or ARGV). – Martin Ender Nov 3 '14 at 11:07

# Functions may return a promise containing the output

## Example

Consider the following function to retrieve my rep from the API, with the output logged from the last Promise in the chain:

f=

_=>fetch("//api.stackexchange.com/users/58974?site=codegolf").then(r=>r.json()).then(j=>console.log(j.items[0].reputation))

f()

I propose instead that we simply be allowed to return the Promise containing the output, like so:

f=

_=>fetch("//api.stackexchange.com/users/58974?site=codegolf").then(r=>r.json()).then(j=>j.items[0].reputation)

f().then(console.log)

## Conditions of Use

This section requires more detail, please edit it to include any other conditions you think should be covered or to add tags to the existing conditions.

### code-golf

In challenges that use code length as a measure for the winning criterion, returning a promise would not be permitted if further manipulation would be required to achieve the desired output, as in this example:

f=

_=>fetch("//api.stackexchange.com/users/58974?site=codegolf").then(r=>r.json()).then(j=>j.items[0])

f().then(i=>console.log(i.reputation))

### fastest-code

If this method is used in time-based challenges then the time required to resolve the final promise must be counted towards your score.

• I feel like we should allow it but add a penality of 5 bytes (.then) due to the overhead in calling like using a command line flag. – Christoph May 12 '17 at 6:34
• @Christoph, I can see your point. I suggest posting that as a counter-proposal as simply editing in as an option above won't tell us what the consensus is. – Shaggy May 12 '17 at 7:11
• I'd allow this except in fastest-code and similar time-based challenges (or at least count the time taken in forcing the promise, in that case), for what I hope are obvious reasons. – user62131 May 17 '17 at 7:23
• @ais523, I've added a section on conditions of use, feel free to edit it to add more detail, tags and/or examples. – Shaggy May 23 '17 at 10:28
• This should be updated for await / async - especially as Chrome console has top-level await. The "get the answer" part of the [code-golf] snippet can be shortened to (await f()).reputation. – Riking Jan 11 '18 at 8:11

# black-box functions to be taken as input can be assumed to be predefined under a given name

This holds for languages that do have classical functions, for instance: Java, JavaScript, VB, C, C++, TI-Basic (some versions), Python, Octave, Matlab, Haskell, Lisp

This proposition is the opposite of that one which only allows this method of taking input for languages that cannot take functions as arguments.

• I'm not entirely sure what is meant by this, but if I interpret it correctly, this will have my downvote, as inputs are never assumed to be stored in a variable already, so why are functions any different? – Sanchises Aug 13 '17 at 22:23
• @Sanchises The problem is a lack of other ways for some languages. E.g. before Java introduced lambdas recently (so everything before Java 8), there was no way for a function to take a "functional" input. – flawr Aug 13 '17 at 22:26
• Maybe add this method as an exception to the other one, so only when your language does not have function pointers or similar? – Sanchises Aug 13 '17 at 22:31
• @Sanchises I now added a second proposal that includes your suggestion, see linked. – flawr Aug 14 '17 at 21:04

# Metaprogramming languages may return a boolean by compiling/not compiling

For example, C++ template metaprogramming has no "return value". A common way for a C++ template metaprogramming to reject something is to fail to compile (sometimes in a SFINAE way, sometimes not).

• if C++ doesn't compile, it prints to STDERR? If so, this could be generalized to allow boolean output by STDOUT vs STDERR. – Nathan Merrill Nov 13 '18 at 2:28
• @NathanMerrill If something does not compile, it doesn't output at all, I think. Expect compiling/not compiling (as described here). – val says Reinstate Monica Jul 17 '19 at 13:57

# For languages not containing a formal implementation of an input or output data type, the data type may be implemented as standardized for the language

For instance, in TIS-100, all inputs and outputs are integers ranging from -999 to 999. Therefore, arrays of positive integers are often terminated with zeroes. If a challenge asks to take in the array [3, 4, 5, 6] and return [6, 8, 10, 12], in TIS-100 the implementation would be to take in the sequence 3 4 5 6 0 and output the sequence 6 8 10 12 0.

# When a challenge asks for an array as input/output, you may use a list instead, and vice-versa

Note that some languages may lack one of these concepts. For example, TI-Basic does not have an array datatype (but has lists) and C does not have a list in its standard library, but has arrays as part of the language.

In keeping with the general flexibility of I/O formats, I suggest we allow to use them interchangeably for all languages.

• A fairly recent meta discussion which basically reached the conclusion that saying "list" in a challenge description is equivalent to any number of possible implementations in different languages which may or may not have different names. To put it a different way, I agree with your intention but I don't think it needs to be specified that "different languages use different words for fundamentally equivalent concepts". – Kamil Drakari Jul 18 '18 at 16:14

# Lists of decimal digits and strings that match ^[0-9]*$ are interchangeable... ...but not when this may make the input format inconsistent. For example, let's say you can assume the string input will match ^[1457]+$, which is a subset of ^[0-9]*$. Then, '1775' can also be input as [1, 7, 7, 5]. However, for a counterexample, let's assume the string input will match ^[a0-8]{2,15}$, which isn't a subset of ^[0-9]*$. In this case, no, you may not use a list of digits, since you can't use one to represent 1aa7708, for example. You can use [1, 1, 8, 8, 6, 4] to represent 118864, but this inconsistency is invalid by default. I posted this after having come across numerous occurrences where I've had to ask about this in the comment section of the question, so I thought "why not post this here?". Surprisingly, this, AFAICT, hasn't ever been posted yet! I definitely have a positive opinion. # Regexes may output via any captured groups Users can specify which subset of captured group(s) contains the output; it doesn't have to be just group 0. • perhaps reword to "a specified subset of captured groups" any could be mis-interpreted as allowing a different subset at each call. – Jasen Dec 22 '16 at 10:51 • Is this to be interpreted such that the specification of which backref(s) contain the output is not counted towards the byte length of the regex program? I would strongly disagree with that, since the backref numbers are an integral part of the program and without them, it would not do anything useful. Is there any other language with a rule like this? At best, any regex answer that uses this rule should be treated as a distinct language which varies depending on the exact combination of backref numbers, like command-line parameters. – Deadcode Feb 26 '19 at 19:29 • @Deadcode yes, there are other languages with rules like this: asm may output via registers, and specifying the register numbers doesn't add to your byte count. – Grimmy Feb 28 '19 at 9:03 • Should non-participating capture groups count as empty string / 0 for the purpose of this rule? – Grimmy Feb 28 '19 at 9:23 • Also, for unary regexes, can the meaning of the capture groups be specified to include combinations of groups to make output of larger numbers possible, for example \4*\2^2 + \5*\2 + \6 or examples such as those shown here? Without this, it is only possible to output numbers less than or equal to the input (or the largest input number, in the case of multiple delimited input numbers). – Deadcode Feb 28 '19 at 22:41 # Regexes may output a number via the number of matches Or truthy / falsey as whether they match. • Plain regex submissions are still not generally accepted as valid so I'm not sure it's worth adding defaults for this very specific case that a lot of people don't accept at all. – Martin Ender May 30 '15 at 10:27 • Again , Retina. – CalculatorFeline Apr 2 '16 at 16:14 # Programs may input/output bytes in a bit-serial or 8-bit parallel manner with a clock and enable signal This is mainly applicable to HDLs such as Verilog, as well as other embedded devices (such as microcontrollers). Currently, $display is capable of writing to standard out in a simulator, but of course, not in a physical FPGA.

• Why require an enable signal? If you take a clock as input, and can output a bit with every clock pulse, the enable signal is just wasting code. (I've used this in a submission already, although the question specified I/O methods explicitly rather than defaulting to this post.) – user62131 Jan 26 '17 at 20:40
• @ais523 Sorry, I didn't think of that when I created this. It makes sense that the clock could be stopped, at least for input, but not sure how a program could communicate that it wants to delay output for a few clock cycles while calculating. – Reinstate Monica - ζ-- Jan 26 '17 at 20:46
• If the problem's simple enough, the program can guarantee that it'll never have to delay output. (Note that you could define a fairly slow clock speed.) Of course, for some algorithms (especially ones that are slower than constant or linear-bounded time) the enable signal might be required. – user62131 Jan 26 '17 at 20:49
• Why need a clock signal? It is also possible to just use UART with a given Clock Frequency. And why 8 Bit? If you want what stop you from using 4, 12, 16 or 27 Bits? – 12431234123412341234123 Jun 21 '17 at 11:12
• @12431234123412341234123 There is often no good way to perform sequential or stateful computation in synthesizable Verilog without a clock signal. 8-bit is in alignment with the fact that 8-bit ASCII is common; you can submit a new answer that allows non-8-bit parallel inputs. Additionally, to output/input data a communication clock is required, whether for each word/bit or to actually run a UART. I would strongly doubt that anyone would want to spend valuable bytes on writing a UART, except perhaps in code-bowling challenges. – Reinstate Monica - ζ-- Jun 21 '17 at 21:32

# Programs may output using their return value

Iff it is legit regarding their specs and compilers.

Certain language treat programs as function, allowing programs to communicate via returns. Hence, we shoule allow such programs to be considered as whole, and not as snippet.

• This has my upvote, because it is natural to languages as lua, where we often use this mechanism when creating an object. – Katenkyo Aug 9 '16 at 21:46
• Is this different from meta.codegolf.stackexchange.com/a/5330/8478? – Martin Ender Aug 9 '16 at 22:30
• @MartinEnder: This refers to codegolf.stackexchange.com/a/88856/15 this answer here and explicitly concerns itself with return values of programs that are not integers. Which, incidentally, doesn't work in any environment I know of. – Joey Aug 10 '16 at 7:00
• Ok, basically you are referring to the fact that you can embed Lua and have the host application handle any return values from the "main" Lua program in a suitable manner. It's just that the default Lua interpreter will effectively do nothing with the stack contents in that case, right? – Joey Aug 10 '16 at 17:57
• @MartinEnder I think it is a generalisation of the one you're pointing to. I'm only creating this post as some PPCGer think it doesn't apply to returns, and I'd like to have a clear consensus on the return for programs, instead of one that simply embed it because of its definition. – Katenkyo Aug 11 '16 at 7:35
• @joey in lua, you can see this value the same way you would do for a library. As this is generally some short piece of code, you could use both local answer = require"codegolf" and local answer = loadstring("program copypasted")() – Katenkyo Aug 11 '16 at 7:39

# Programs running on FPGAs may take input or give output through transceivers.

• I'm not familiar with FPGAs, but I would upvote if there's no way to encode data into which transceiver is being used or how. – lirtosiast Dec 3 '18 at 23:28

# Programs may write output to the clipboard

Complementing the programs may take input from the clipboard proposal.

• I agree with this, this is just like the proposal where stack-based languages could write to the stack instead of outputting the result – user41805 Feb 28 '17 at 10:05
• This would mean that any program can compute the identity by doing nothing, right? That's kind-of weird. – xnor Feb 28 '17 at 21:17
• While I agree that that is weird, I don't think that that is grounds to down vote. That is abusable in exactly 1 challenge, (and that loophole could be closed in that 1 challenge) – Nathan Merrill Mar 6 '17 at 14:14
• If you favor this proposal, you should also allow the identity to be computed by outputting on stdin. – feersum Mar 30 '17 at 2:27

# BASIC and related languages may take input via DATA / READ

In various dialects of BASIC, you can include data in the source code by using the DATA statement:

DATA abc, xyz
DATA 2, 3, 5, 7, 11


(Examples are written in QBasic because that's what I know.)

You access this data by using READ:

READ str1$, str2$
FOR i = 1 TO 5
NEXT


This input method is idiomatic for BASIC.

• Is this basically the equivalent of final static in Java? – Nathan Merrill Mar 5 '17 at 5:03
• @NathanMerrill I don't think it's similar at all, actually. Based on 2 mins of research on Java, it looks like final is equivalent to CONST in QBasic, and static doesn't have an equivalent because QBasic doesn't have classes. READ is like INPUT, except the input is stored in the program with DATA so the user doesn't have to retype it each time they run the code. – DLosc Mar 5 '17 at 5:42
• I guess I don't follow: when would you use const vs data/read? It seems like reading data already stored in your program is a waste of CPU cycles. – Nathan Merrill Mar 5 '17 at 14:32
• @NathanMerrill Initializing arrays is one use case, since as far as I know BASIC doesn't have anything like C's int array[3] = {2,3,5};. In QBasic you DIM array(3) and then you can either do array(1)=2: array(2)=3: array(3)=5 (etc.) or you can write an easy-to-read FOR loop as above and put DATA 2, 3, 5 in the program. For large amounts of data (like layouts for a maze game), it might be better programming practice to put the data into a different file, but in the interests of being self-contained and not having to deal with file I/O, the DATA statement is often used instead. – DLosc Mar 6 '17 at 7:09
• Note also that READ does not result in fixed values like CONST does. If you do CONST pi = 3.14, you can never modify that value (assigning to pi thereafter is a syntax error). But you can READ x and then do x=x+1 (or whatever). And you can READ multiple different data values into the same variable (in a loop, say). – DLosc Mar 6 '17 at 7:16
• The argument is that the Data command effectively creates unnamed constant variables (and read just reads them), so the fact that you can modify the read ones is irrelevant IMO. I'm on the fence here: the syntax is similar to input from the user, but it also feels like reading from a variable. – Nathan Merrill Mar 6 '17 at 14:08
• The ZX80 and ZX80 do not have DATA/READ keywords in its default interpreter. One has to store data in variables, or in REM statements and - in this case - read each byte by using the PEEK keyword. – Shaun Bebbers Apr 4 '17 at 9:03
• Would the very similar <DATA> be accepted in Perl? (docs: perldoc.perl.org/SelfLoader.html#The-DATA-token). – Grimmy May 31 '17 at 15:21

# Assembly language / machine code must take input and output as defined by an ABI for the platform that predates the challenge

For example, most commonly used ABIs for x86 state that 32-bit integer outputs are returned in the %eax register. As such, that's a valid way to output a 32-bit integer. However, outputting in, e.g., %esp would not be valid, unless a pre-existing ABI can be located where that's considered a valid method of output.

(Some background for people unaware of assembly language technology: an ABI, or Application Binary Interface, is a specification for how pieces of code within a particular program, on a particular platform, communicate with each other via the state of the processor. Most ABIs specify specific memory addresses and/or registers to be used for the communication.)

This is outright intended as a competing answer to the other assembly-language-related answers, because I feel they're too permissive and could lead to loopholes in which bytes are moved from the program to a selection of a register/memory address. (See this answer and the corresponding question for more detail.)

• Assembly is free for platform etc it can have arg as one register and return its result as a flag... If it has to communicate or to be used to C language programs than yes has to follow API... – RosLuP Feb 4 '19 at 22:27

# An array may be represented in input as a begin pointer and an end pointer.

like what's done in C++ std

• So you mean the iterator model that the C++ STL uses? I like this. – Mego Mar 7 '18 at 3:46
• "like what's done in C++ std" - that needs to be fleshed out a bit more, maybe with an example, for those unfamiliar with C(++). – Shaggy Mar 8 '18 at 8:15
• @Shaggy What other language have pointer but not enough knower know C/C++? – l4m2 Mar 8 '18 at 12:02
• @l4m2 Well, C and C#. Both of them have pointers and both of them have lots of users that don't know how the C++ standard library works. – Pavel Mar 12 '18 at 15:17

# Numerical input and output can be given as a character code

For example, the input 64 can instead be given as the character @. This is mainly used for more esoteric languages that can only take input through character codes, for example brainfuck.

• Note that this was already a consensus here, I'm just adding it here to make it easier to find. – Jo King Aug 28 '19 at 12:47

# Functions may output by calling a callback function or event

The callback function should be provided using a valid input method.

Example in JavaScript that outputs Hello world!:

f=>f("Hello world!")


This may be shorter than returning a value in some languages:

import random as r
def f(x):
q=r.random()
return(q+q/2)/2


As opposed to:

import random as r
def f(x,g):
q=r.random()
g((q+q/2)/2)

• I don't see why this should be useful, considering you can just return the result. – Esolanging Fruit Feb 11 '17 at 2:27
• Never mind, I see why this might be useful. Upvoted. – Esolanging Fruit Feb 13 '17 at 0:16
• @Challenger5 Please explain why. – haykam Feb 28 '17 at 12:34
• @haykam In a language like Python, something like import os [\n] def f(k):return os.system(k) is longer than import os [\n] def f(k,g):g(os.system(k)) – Esolanging Fruit Feb 28 '17 at 17:51
• @Challenger5, the point of specifying default I/O methods is to allow answers to use idiomatic I/O, not to allow golfing a byte off print. – Peter Taylor Mar 1 '17 at 15:04
• @PeterTaylor Might it be more idiomatic in some languages to use continuation-passing style rather than returning? – Esolanging Fruit Apr 26 '17 at 16:49