# Can I write a golfing library?

(This might be a duplicate of another question but all of its answers were vague nonanswers, and I can't find it again, so here goes...)

I like python3 and I'm quite good at it; it's rather verbose so when I make long scripts I have a tool script I import that contains lots of shortenings and predefinitions. As long as I don't answer existing questions with it, and as long as I make it freely available (on git?), can I do this and only have the from g import* counted towards my score? or would I be implored to include the bytes of library just cause I wrote it?

It almost feels boring but to say it is, is to call Golfscript and Pyth boring and uninteresting, with which I disagree.

• Note that Pyth, while written in Python, is rather far from a shorthand for Python. It has evolved quite a bit from where it started. – Alex A. Oct 21 '15 at 23:17
• @AlexA. agreed on the evolution bit, and not to sound thick but since it compiles to python and is very pythonic isn't it kind of just a (developed) shorthand for python? – cat Oct 21 '15 at 23:22
• I'd actually like to write a golfing library for Java, specifically to reduce calls to java.lang.Math and java.math.*. I'd like to see this implemented. – Addison Crump Oct 21 '15 at 23:27
• @Calvin'sHobbies I think what he's asking is to make a specific importable set of methods, not a language. – Addison Crump Oct 21 '15 at 23:28
• @Calvin'sHobbies I've got a whole multipurpose scripting language in the works that should be fun to golf in, but I'm asking about creating g.py which turns print() into p() and input() into q(), which I then import with from g import*: is this OK and how are bytes counted? – cat Oct 21 '15 at 23:30
• @VTCAKAVSMoACE But if the methods are to be used in a code-golf answer (and not have the bytes be counted) it needs to count as a different language. – Calvin's Hobbies Oct 21 '15 at 23:32
• @Calvin'sHobbies So would we say "Java with the Golfing Library 'G', x bytes"? – Addison Crump Oct 21 '15 at 23:33
• @VTCAKAVSMoACE Sure. Though you could think of a more imaginative name. (e.g. Guava) – Calvin's Hobbies Oct 21 '15 at 23:35
• @VTCAKAVSMoACE none of the answers actually disagree, how can you infer that just from votes? meta.codegolf.stackexchange.com/a/5427/46231 – cat Oct 21 '15 at 23:35
• @sysreq It appears to be the most popular idea is what I was trying to say. – Addison Crump Oct 21 '15 at 23:36
• You could save some characters by using import g and having g.py shove stuff into builtins – gnibbler Oct 22 '15 at 6:45
• I've been working on a similar thing with JavaScript, using lots of unusual constructs: (i+5).a prints the input plus five. – Ypnypn Oct 22 '15 at 21:55

## Yes, and it does not necessarily have to be a separate language.

There's no problem with using your own library as long as it doesn't violate the standard loopholes. In answers where you use it, you should put "Python 3 + <name> library" in the header.

If you go for the library route, you do need to count the import in any answers with it.

• This makes the most sense: why treat a library different from a language? – Ypnypn Oct 22 '15 at 21:53
• A estabilished example is "<some shell language> + coreutils", coreutils isn't included in the byte count. – Kroltan Nov 2 '15 at 23:28
• Why include the import statement? It's trivial to compile foo-with-bar-language to foo-language + bar-lib - are we required to publish such a compiler in order to be eligible for this deduction? – John Dvorak Jul 8 '17 at 0:27
• @JanDvorak Yes (that would be a quite Meta-Golfscripty thing to allow). – feersum Jul 8 '17 at 2:27
• @feersum Hm... is there an established naming scheme for these languages? – John Dvorak Jul 8 '17 at 6:55

# Yes. But:

According to what I see from the comments and previous relevant questions, the consensus is that you may, however, you must do the following things:

### - Define it as not a clean copy.

• This means declaring it as "<Original Language> + <Library Name (with link)>"

### - Provide a link to the library.

• This is common sense.

### - Explain thouroughly

• Also common sense - if you show up with a library no one has ever seen, nobody's going to know what it actually does.

### - The Library cannot be updated after the question exists!

• This is a general loophole, and must be abided to.
• Wait, so I have to call it Gython rather than Python with my G library? – cat Oct 21 '15 at 23:48
• I would agree with calling it the latter - you just can't say that it's normal Python with a normal import. – Addison Crump Oct 21 '15 at 23:48
• Additionally, in the case of Java, Oracle don't much like people messing with their stuff. Does this only apply to languages with permissive licences? – cat Oct 21 '15 at 23:49
• If you can't find it on an unaltered version of whatever your language your writing the library for, it must be identified as said language with a custom library. It's just not the same language anymore. – Addison Crump Oct 21 '15 at 23:50
• And just for final Clojure: the bytes counted are from g import* or the length of g.py? – cat Oct 21 '15 at 23:58
• I'd say the former, but I don't have the full right to say that. I'd suggest an opinion from a moderator for that. – Addison Crump Oct 22 '15 at 0:05
• RE "The library cannot be updated after the question exists". I disagree. The library cannot be updated to easily solve the question, but new versions of the library can always be created (in which case one might need to specify which version of the library is being used) – Justin Oct 22 '15 at 4:12
• I agree with @Justin. It seems silly to freeze development of a golfing library once it gets used for the first time. The solution of specifying "Original Language + Library Name + Version (with link)" as the "language" of the post, with the "Version" being one that existed prior to the creation of the question, seems like a good one. (...and it just now occurs to me that I haven't even posted on this site so why should anyone listen to me? But the argument seems solid, anyway.) – David Z Oct 26 '15 at 7:51

# Yes, but make a language not a library

Writing a library might be acceptable but we definitely allow the creation of custom languages.

To achieve your goal you could make up a language called "Mython" (or whatever you want to call it) and write this compiler for it:

p = print
q = input
def runMython(code):
exec(code)


So if you wanted to run the Mython code

x = "dog"
p(q() + x)


You could just do

runMython("""
x = "dog"
p(q() + x)
""")


This is better than a library because you don't even need the import.

As always, languages are (usually) only valid in challenges that were posted after the language was invented.

• Hmm. Perhaps I'll just get to work on an interpreter for the actual, non-pathetic language I'm actually designing from actual scratch. – cat Oct 22 '15 at 0:02
• This is better. The Library route would be good, but using this would both reduce byte count and de-clutter answer headers. +1 – Addison Crump Oct 22 '15 at 0:16
• -1. This works for Python, but making a Mjava compiler would be a huge pain involving complex file manipulations. – Ypnypn Oct 22 '15 at 21:52
• -1. Didn't golf the Mython interpreter. :P – mbomb007 Oct 30 '15 at 15:03

# Yes, but make it runnable on its own

You don't necessarily need a compiler, as long as you can run mython myscript.my (or whatever your language is called) from the command line.

One way of achieving this would be to make a small shell script that somehow ran Python with the right flags and parameters so that your library is loaded at startup. I don't know for Python, but this option exists for other languages such as Ruby and Perl. I know because I have very similar plans to yours :)