25
\$\begingroup\$

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)

\$\endgroup\$
9
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Oct 28, 2015 at 12:47
  • 1
    \$\begingroup\$ @TomášZato On the contrary, experience tells me that's not always the case (e.g. the linked standard deviation question) \$\endgroup\$
    – Sp3000
    Commented Oct 28, 2015 at 13:44
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Oct 28, 2015 at 13:47
  • 4
    \$\begingroup\$ @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... \$\endgroup\$
    – Beta Decay
    Commented Oct 28, 2015 at 13:53
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Oct 28, 2015 at 14:04
  • 2
    \$\begingroup\$ @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. \$\endgroup\$
    – Geobits
    Commented Oct 28, 2015 at 14:07
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Oct 28, 2015 at 14:10
  • \$\begingroup\$ * 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. \$\endgroup\$
    – Euan M
    Commented Nov 28, 2015 at 23:43
  • \$\begingroup\$ Related \$\endgroup\$
    – user45941
    Commented Apr 24, 2016 at 22:58

3 Answers 3

18
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ 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? \$\endgroup\$
    – Sp3000
    Commented Oct 17, 2015 at 15:03
  • 5
    \$\begingroup\$ @Sp3000 Yes, that's exactly the same case as sum. \$\endgroup\$
    – feersum
    Commented Oct 17, 2015 at 15:06
  • 5
    \$\begingroup\$ 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. \$\endgroup\$
    – user45941
    Commented Apr 24, 2016 at 21:20
  • 2
    \$\begingroup\$ I do also disagree with this edit, as this contradicts to what was deemed acceptable before. \$\endgroup\$
    – flawr
    Commented Apr 25, 2016 at 19:40
  • \$\begingroup\$ I've posted a separate answer mirroring the common interpretation of this answer prior to the edit. \$\endgroup\$
    – Alex A. Mod
    Commented Apr 25, 2016 at 21:06
7
\$\begingroup\$

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.)

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$
    – feersum
    Commented Apr 25, 2016 at 21:23
  • \$\begingroup\$ @feersum You started the discussion here when you edited your (consensus) answer to specifically forbid something the rest of the community viewed as acceptable. \$\endgroup\$
    – user45941
    Commented Apr 27, 2016 at 3:08
-7
\$\begingroup\$

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.

\$\endgroup\$
3
  • 11
    \$\begingroup\$ -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. \$\endgroup\$
    – lirtosiast
    Commented Oct 17, 2015 at 1:42
  • 1
    \$\begingroup\$ -1 as the zero byte solution would be in violation of this standard loophole. \$\endgroup\$
    – Alex A. Mod
    Commented Oct 17, 2015 at 3:44
  • 6
    \$\begingroup\$ @AlexA. The loophole currently only applies to quine, source-layout, and restricted-source questions. \$\endgroup\$
    – lirtosiast
    Commented Oct 17, 2015 at 21:02

You must log in to answer this question.

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