Suppose there's a challenge which can be solved completely by a builtin function, and functions are allowed. Note that as of writing the standard loophole for builtins is heavily disputed, but let's just assume that the poster explicitly allowed builtins since that's not the point of this question.

Which of the following submissions would be valid? To give a more concrete example, let's say the task was adding a list of numbers.

                   0 bytes, since the user can use the function already
sum                3 bytes, an expression which evaluations to a function
s=sum              5 bytes, aliasing the builtin
lambda L:sum(L)    15 bytes, an explicit unnamed function

Similarly, if the task was to multiply two numbers, would the following be valid? Or rather, is it possible that the following is only valid in languages which treat operators in a certain way?

*                  1 byte, multiplication operator

(For context, this question was inspired by the Calculate Standard Deviation question)

  • I just think it doesn't matter. I doubt such answer will gather votes - most likely, it will rather gather downvotes, being a Pyrrhic victory for the guy who posted it. – Tomáš Zato Oct 28 '15 at 12:47
  • 1
    @TomášZato On the contrary, experience tells me that's not always the case (e.g. the linked standard deviation question) – Sp3000 Oct 28 '15 at 13:44
  • Well, this looks a lot like you want to forbid all math languages (eg. Matlab, mathematica...). You smell like the kind of guy who would like to drive all the weird languags so characteristic for PCG away. – Tomáš Zato Oct 28 '15 at 13:47
  • 3
    @TomášZato Hey, there's no need to go around making these sorts of accusations. Sp3000 is probably one of the most prolific users of "weird languages" here. And besides, what you have said is irrelavent to the question... – Beta Decay Oct 28 '15 at 13:53
  • @BetaDecay I don't think it's irrelevant. From these occasional 2-5 byte answers you get to know about new languages. So unless the language was made for purpose of solving the question, the author often deserves a credit for knowing it at least. – Tomáš Zato Oct 28 '15 at 14:04
  • 2
    @TomášZato I don't see this question purporting to ban any languages. It's asking how to score. The accepted answer (and comments) show that there is no prejudice against what a language can do, as long as it works in that language. – Geobits Oct 28 '15 at 14:07
  • @TomášZato welcome to Programming Puzzles & Code Golf! Feel free to post an answer here so people can vote to indicate whether they agree. Comments are best for clarifying the question rather than expressing opinions, as they are not guaranteed to be permanent. – trichoplax Oct 28 '15 at 14:10
  • * is the standard Forth way to multiply two numbers. It removes the top two items from the stack, and then pushes the product onto the stack. – Euan M Nov 28 '15 at 23:43
  • Related – Mego Apr 24 '16 at 22:58
up vote 15 down vote accepted

Code that purports to define a function should only be accepted if it actually causes the function to be defined. That is, the function should not be defined before/without that code running.

Accordingly, the empty string is not a valid function answer. s=sum is valid because it defines a function s that did not exist before. sum and lambda L:sum(L) are valid because expressions that evaluate to a function are an accepted answer form. However, an unnamed expression may only be used if the entire answer is the expression; it may not be part of a larger program. * is not a valid answer in Python because it is neither an expression nor any other kind of executable code.

  • Just to clarify the second half, if * is a valid expression in a given language and is possibly even assignable (maybe in J?), then would that make it a valid answer? – Sp3000 Oct 17 '15 at 15:03
  • 5
    @Sp3000 Yes, that's exactly the same case as sum. – feersum Oct 17 '15 at 15:06
  • 5
    I changed my +1 to a -1 because of the new edit. That goes against how built in submissions have been done since the original post. – Mego Apr 24 '16 at 21:20
  • 2
    I do also disagree with this edit, as this contradicts to what was deemed acceptable before. – flawr Apr 25 '16 at 19:40
  • I've posted a separate answer mirroring the common interpretation of this answer prior to the edit. – Alex A. Apr 25 '16 at 21:06

Since feersum edited his answer and the edit conflicts with the common interpretation of the text (which is how we've been doing things since that answer was posted), I'll repost the text of his answer prior to the edit so that we still have an answer here reflecting that practice.

Code that purports to define a function should only be accepted if it actually causes the function to be defined. That is, the function should not be defined before/without that code running.

Accordingly, the empty string is not a valid function answer. s=sum is valid because it defines a function s that did not exist before. sum and lambda L:sum(L) are valid because expressions that evaluate to a function are an accepted answer form. * is not a valid answer in Python because it is neither an expression nor any other kind of executable code.

It is acceptable to post a defined function along with an import, such as the pseudocode import math; sum. (This is what was declined by the edit.)

  • Come to think of it, why is this discussion being held on this particular question? The debate is about the acceptable forms for any unnamed functions, which has nothing to do with whether builtins are involved. – feersum Apr 25 '16 at 21:23
  • @feersum You started the discussion here when you edited your (consensus) answer to specifically forbid something the rest of the community viewed as acceptable. – Mego Apr 27 '16 at 3:08

For challenges that accept functions as answers, a submission should be valid if after being run, there exists a function that does exactly as the challenge asks.

Thus, the zero byte submission is valid, if the builtin function accepts input in a way that perfectly conforms to the challenge specifications; if it is even slightly different (such as taking extra parameters), then the zero byte submission is invalid.

  • 11
    -1; this allows the MetaGolfScript-like ability to use the same program for multiple different tasks. It would allow submissions that define all possible functions to be valid in any challenge. – lirtosiast Oct 17 '15 at 1:42
  • 1
    -1 as the zero byte solution would be in violation of this standard loophole. – Alex A. Oct 17 '15 at 3:44
  • 6
    @AlexA. The loophole currently only applies to quine, source-layout, and restricted-source questions. – lirtosiast Oct 17 '15 at 21:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .