# When is code that requires a REPL acceptable?

Question in brief: For what challenge types and in what circumstances should code that requires a REPL be acceptable in an answer?

There seems to be an understanding in chat that code that only works in a REPL is not valid as an answer, but I can't find any consensus here on meta to back this up, which makes it difficult to comment to that effect on REPL answers.

I've found these two somewhat contradictory posts:

This question:

Default for Code Golf: Program, Function or Snippet?

Loopholes that are forbidden by default: Posting a code snippet instead of a complete answer

However, mixing up the discussion and voting with the program/function debate seems to be causing confusion, so I thought this could use its own question.

• Pro: A REPL could basically be thought of as a separate programming language anyway, and it's silly to expect people to create "PythonREPL" and "RubyREPL" etc. for every language that simply runs the code and prints the result. Con: Code that requires a REPL cannot be run from the command line easily and is more of a snippet than an actual program/function. – Doorknob Dec 28 '15 at 23:55
• Not sure if this is a coincidence, but I wanted to post this question literally 5 minutes ago due to this discussion – March Ho Dec 29 '15 at 0:01
• An important thing to consider is languages like J which I think only exists in a REPL environment. – Martin Ender Dec 29 '15 at 0:01
• @MartinBüttner J can exist as POSIX scripts, but Dyalog APL, for example, does not have full programs in the usual sense. – Dennis Dec 29 '15 at 1:19
• @MarchHo that answer wasn't the one that prompted this meta discussion, but the one that did was another answer to the same question... – trichoplax Dec 29 '15 at 14:00

## Always— but a REPL is a different language.

We usually define languages by their interpreters. My Python shell is an interpreter, which satisfies our definition of a programming language. Therefore, it is a valid language.

"Wait a minute", you say, "won't REPLs usually be shorter than their full program/function equivalents?" Why won't people golf in 'Python REPL' over Python?

That will happen, and it's fine. Clever and well-golfed full-program Python answers will still be upvoted—just as they are now despite golfing languages usually winning challenges.

In addition, a REPL entry won't always be a parent language entry without the print(). The REPL often has interesting features that can be used cleverly, and golfing in a REPL means a different set of constraints than in the parent language. For example, _ in a Python REPL is the last evaluated expression, which is shorter than assigning to a variable.

• With Python it is possible to type a full multiline program into the REPL, and still take advantage of not needing to type "print" to output results. – trichoplax Dec 29 '15 at 14:03
• @trichoplax Is there a problem with that? – lirtosiast Dec 29 '15 at 15:34
• If this is accepted, there are two possible outcomes: 1. Many contests will have an answer in Python and another on in Python Shell. This is not very interesting. 2. Most Python golfers will convert to Python Shell golfers. If we wanted that, we shouldn't have outlawed snippets in the first place. – Dennis Dec 29 '15 at 15:43
• @Dennis I see your point (I would discourage golfing in REPL environments), but a shell is an interpreter and therefore a language. Excluding shells, just because they're shells and often shorter, is tantamount to adding them to the list of forbidden languages, for which there is insufficient justification. – lirtosiast Dec 29 '15 at 15:51
• @ThomasKwa it wasn't intended as a good or bad point, just background in case it affects people's view. – trichoplax Dec 29 '15 at 15:56
• @ThomasKwa I think we're not excluding shells because they're shells, but because "full programs" can be stored in files whose encoding and size can be easily determined which is not necessarily true for code typed into a shell. – Martin Ender Dec 30 '15 at 20:58
• Reasons for upvote: 1. Banning languages is always a bad idea. 2. I can think of 2 languages that only exist as loops: Processing (based on Java) and Arduino C (based on C.) I think both – Level River St Jan 4 '16 at 20:21
• I'm unsure about this. I agree that philosophically banning REPLs is unjustified, as they are languages like all others. But I think that votes are liable to cause one of two bad cases: REPL answers get unjustly downvoted simply because some voters don't like the idea of REPL, or they get upvoted more than an equivalent non-REPL answer would, pushing posters to make often-trivial modifications to REPL-ify their code. – xnor Jan 10 '16 at 21:30
• Do Enter keypresses need to be counted as 1, or not be counted at all? (Enter, not Shift+Enter, which definitely counts as 1) Because Enter is the key that sends statements and expressions to the REPL. I think it would be "Yes count Enter keypresses. Subtract 1 from the total score." – Erik the Outgolfer Sep 15 '16 at 18:31
• What if I created a REPL language that counted the number of newlines and then interpreted it as a program in Unary? You now have a golfing language where every program is length 0 (You might need a termination character, in which case length 1). – Esolanging Fruit Nov 1 '16 at 0:05
• @lirtosiast Is there a list of forbidden languages? – Jonathan Frech Aug 29 '18 at 8:01

I believe that if the programming language has a significant proportion of its code being run in a REPL environment, using the REPL form of the code should be allowed, unless it is specifically disallowed in the question.

Examples of such "significantly REPL languages" include Mathematica, where the code is run within "notebooks", which are REPL environments.

Examples of languages where REPL is not active in the majority of usage cases include C++ and PHP (although as far as I am aware both of them can also be run in a REPL shell).

• What about JavaScript/Python? – Martin Ender Dec 29 '15 at 0:10
• @MartinBüttner If we can get consensus on this answer, I am sure there will be opportunities for the community to decide whether certain less well-defined languages are "significantly REPL" or not. – March Ho Dec 29 '15 at 0:13
• I'm uncomfortable with basing this decision on whether a REPL is commonly used. Is this your intended meaning? – trichoplax Dec 29 '15 at 14:17
• @trichoplax yes. I suppose it is much more meaningful than any currently available alternative. Feel free to suggest other possibilities. – March Ho Dec 29 '15 at 15:04
• IMO most mathematica is not in a notebook unless you need to do some really quick calculations – ev3commander Dec 29 '15 at 16:03
• @BlockCoder1392 I have personally not seen anyone using Mathematica outside the notebook environment, and furthermore Mathematica's default file extension is .nb. Can you point out any widely used examples of programming in Mathematica outside of the notebook/kernel REPL environment? – March Ho Dec 30 '15 at 12:15