3
\$\begingroup\$

An interesting conundrum has arisen in relation to the bonus I offered for APL solutions to An Ant on a Cube. It's an old challenge that requires a "named function", such as a lambda assigned to a variable: f←{...} - that is 2+ the code length we normally consider valid for most golfing challenges. @Adám devised the following way to circumvent the need for "f←": create a named function object (in APL-speak: "fix" it) from a string, and claim the string's length as code length. Typing the string directly in the REPL or placing it in a file wouldn't have the same effect, so "fix"-ing is essential and the actual number of bytes sent to the interpreter in order to pull off this stunt is, of course, much higher.

So, in this context, how do we define code length?

\$\endgroup\$
  • 4
    \$\begingroup\$ To me this looks like either an abuse of the interpreter or an abuse of the term "byte count" (particularly when it comes to interpreter flags). \$\endgroup\$ – Draco18s Mar 16 '18 at 19:41
  • 1
    \$\begingroup\$ I'm pretty sure the code length is the length of code←'f',n,'{⍵≡(↓∪⊢∘⌽)/⎕,⍵}⊂⍳4', it'd be just like in C where you have to count f(int*i) before the function body. I'm not really sure I understand, though, because I don't see how it could be interpreted otherwise. \$\endgroup\$ – FryAmTheEggman Mar 16 '18 at 20:00
  • \$\begingroup\$ @FryAmTheEggman In C that is sufficient to make it a valid (fragment of a) source file. In APL you're required to surround that kind of function definition (called a "tradfn"), including its header, with a pair of -s, except when you pass a string to ⎕fx. \$\endgroup\$ – ngn Mar 16 '18 at 20:24
  • 2
    \$\begingroup\$ Alright, so is it like how this Python code shows that the "code" is 8 bytes, but in order to make something interpreted like that you would need to do something like the third example in this answer? \$\endgroup\$ – FryAmTheEggman Mar 16 '18 at 23:22
  • \$\begingroup\$ @FryAmTheEggman Yes, something like that, but with text, not bytecode. \$\endgroup\$ – ngn Mar 17 '18 at 0:29
  • \$\begingroup\$ @FryAmTheEggman If an interpreter exists that can use that bytecode, you certainly could use Python function bytecode as a language. \$\endgroup\$ – Mego Mar 18 '18 at 3:24
  • 2
    \$\begingroup\$ @Mego Right, if they are exactly the same then I think its a case of it being fine to submit that as a solution, but it would need to be for a different language called "APL tradfn" or something similar. I still don't think I understand enough about what the APL code is doing to answer, though. \$\endgroup\$ – FryAmTheEggman Mar 18 '18 at 4:35
1
\$\begingroup\$

The just opens and closes the line editor and is certainly not part of the code, as can be seen Character Representation (⎕CR'f') of the program. It was exactly to demonstrate this that I included the ⎕CR in the output.

Also placing the code in a file without s is perfectly adequate for APL to import it. Try it online!

\$\endgroup\$
  • \$\begingroup\$ You're just reading the file and calling ⎕fx on its content :) and you're not counting the bytes it took you to do that. \$\endgroup\$ – ngn Mar 17 '18 at 23:59
  • \$\begingroup\$ @ngn How you you count a multi-line dfn? \$\endgroup\$ – Adám Mar 18 '18 at 0:11
  • \$\begingroup\$ \n can be replaced with ⋄. A dfn is a self-contained unambiguous piece of code. A tradfn's header line is ambiguous - it could be a valid APL expression. You can't pipe a bare (∇-less) tradfn to "dyalog -script". \$\endgroup\$ – ngn Mar 18 '18 at 0:19
  • \$\begingroup\$ @ngn What does dyalog -script have to do with it? Classic doesn't even recognise that switch, so then it isn't a programming language? And this is an invalid solution to returning [8,4,3] \$\endgroup\$ – Adám Mar 18 '18 at 0:30
  • \$\begingroup\$ Huh, I don't know what you're trying to say with the last link. In any case, if we allow ⎕fx-ed APL code, surely Python code objects should be allowed too (see FryAmTheEggman's comment)? \$\endgroup\$ – ngn Mar 18 '18 at 0:46
0
\$\begingroup\$

The length of the code is its byte count. If a full program is required then everything counts. If a function is required then everything counts including function declarations&definitions. If a snippet is required then it may be given as an anonymous function or in any other way that you can directly use this in an interactive fashion. This gets tricky in languages that do not have named functions or don't have functions to begin with in which case you either default to the most reasonable approximation of a function or you exclude these languages from participating. But either way, we're trying to establish categories here that just do not reflect reality because reality doesn't neatly fit into categories.

\$\endgroup\$

You must log in to answer this question.

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