# On scoring imported functions

There are lots of questions about whether to count the bytes in an import statement, etc. This question is not about that. Instead, this question is more inline with this question but I think it would be considered off topic/distinct.

Again, assume standard library imports are allowed at least, and that the byte count of the whole import is included in the score. The question arose here where many languages have libraries that provide a ready made solution. Now, is importing the solution enough, or does the required function need to be reassigned or evaluated?

When considering the consensus about builtin functions, it seems builtin solutions are acceptable in two situations:

1. The builtin is evaluated.
2. The builtin is assigned to a new name.

My gut feeling is that just importing a library is the same as doing neither of the above and claiming the builtin solves it for 0 bytes.

For instance, in Python, the NumPy library provides the function eye which returns the nxn identity matrix.

from numpy import*


seems like cheating, but by the wording of the other discussion, I think it could be argued that it's valid.

My gut feeling is that this should not be allowed, but by the wording of the discussion about builtins it looks like it should be. Look at the wording of these two articles assignments and imports:

Assignment statements are used to (re)bind names to values

• Assignment

The import statement ... searches for the named module, then it binds the results of that search to a name in the local scope.

So is

from library import func


equivalent to

func=builtin_func


and therefore acceptable as an answer? And if, technically, it is, should we put it on the list of banned loopholes?

## Score is the length of the import plus the length of the function name

This seems to be the standard around here. If there exists a built-in function (we'll call it foo) that solves the task, and built-ins are not forbidden, then, for a challenge that accepts functions and not just full programs, the solution would be:

## Python, 3 bytes

foo


Similarly, if foo resides in a module named bar, the solution would be:

## Python, 20 bytes

from bar import*
foo


(technically it would be shorter to do import bar\nbar.foo, but that's beside the point)

Though this is specifically aimed at Python, it's easy enough to generalize to other languages. Consider a challenge where the goal is to output the number of characters in an ASCII string. A C solution would be:

## C, 25 bytes

#include<string.h>
strlen

• Yes, I just used Python because I'm not as familiar with other languages' syntaxes. – Ogaday Feb 4 '16 at 14:33
• @Ogaday Nothing wrong with that. Python makes for some nice, simple examples. – user45941 Feb 4 '16 at 14:34
• Your C code causes a compilation error, surely that shouldn't be a valid answer? The main problem I have in deciding what should be allowed is that as far as I can tell in python there isn't a difference between from foo import bar and def bar.... other than the first way allows a sort of cheaty meta golfscript library idea, and as a reason "it's boring" is not really satisfying, even if it is necessary sometimes. – FryAmTheEggman Feb 4 '16 at 15:41
• foo is considered valid for Python because to can prepend an assignment (f=) to create a user-defined function. You cannot do f=strlen in C. – Dennis Feb 4 '16 at 15:42
• @Dennis You could work with a function pointer in C. – Martin Ender Feb 4 '16 at 15:47
• @MartinBüttner Right, something like size_t (*f)(const char *str) = strlen; would work (and be a valid submission). That still leaves the issue that the submitted code doesn't compile though. – Dennis Feb 4 '16 at 16:06
• Ok I learned something weird today, if you click edit on Ideone you actually change where the link points, you don't create a new one, so my old link is borked now because I fixed it, but I don't want to delete the rest of the comment so here's a link to the error again... Sorry :P – FryAmTheEggman Feb 4 '16 at 16:13
• @Dennis Well, function submissions normally end in expressions that evaluate to a function which could either be captured in a name or be called directly. – Martin Ender Feb 4 '16 at 16:13
• Isn't the third example (the C one) 25 bytes? – Downgoat Feb 12 '16 at 0:48
• @Downgoat Err, yeah. I was counting a trailing line feed for some reason. Temporary insanity. – user45941 Feb 12 '16 at 0:51