13
\$\begingroup\$

As per past discussion, function submissions should be reusable. And, currying function may be a valid submission.

Consider a challenge which require 2 inputs x, and, y. A currying function submission may be f = λ x: (initial_global(); λ y: more_codes_about(x, y)), and it should be used as f(x)(y). Though f is reusable, g = f(x) is not (due to failed to initialize global values). Is this a valid submission? Or, in the other word, is function g = f(x) required to be reusable?

\$\endgroup\$
5
  • \$\begingroup\$ Why wouldn't it be? It seems like this flows pretty naturally from the provided links. \$\endgroup\$
    – Wheat Wizard Mod
    May 15, 2018 at 5:33
  • 4
    \$\begingroup\$ @HatWizard Really? I don't know. f needs to be reusable. I wouldn't necessarily expect g = f(1); g(4); g(5) to be valid, just f(1)(4); f(1)(5), since f is the actual submission. That said, an argument for requiring intermediate functions to be reusable could certainly be made, but I wouldn't say it's clear from rules we already have. I think this is a good question. \$\endgroup\$ May 15, 2018 at 8:26
  • \$\begingroup\$ @PeterTaylor I had made an edit on the example. fell free to edit it anyway if it is not such clear. \$\endgroup\$
    – tsh
    May 15, 2018 at 11:22
  • 6
    \$\begingroup\$ The key here is "function submissions". We don't require that every function in your code is reusable, but rather that your submission (which is a function) is reusable. \$\endgroup\$ May 15, 2018 at 16:34
  • \$\begingroup\$ seems there was discussion about whether t=f(4);t(5) support is necessary \$\endgroup\$
    – l4m2
    May 16, 2018 at 14:17

2 Answers 2

18
\$\begingroup\$

Only the first function need be reusable

I'd say this for the following reasons:

Disadvantage to functional languages

Suppose that there is a challenge to print two numbers, and I submitted the following code in F#:

let f x y =
 printfn "x: %i y: %i" x y

F# would implicitly curry this, so to comply it would have to be re-written into something like:

let g y = 
 printfn "y: %i" y

let f x =
 printf "x: %i " x
 g

Which is a disadvantage to F# (and I'm assuming other functional languages!)

It's the submitted function itself that's important

Martin Ender said this too in his comment.

When I look at a submission like:

let f x y =
 printfn "x: %i y: %i" x y

I'm more looking at if this block of code is reusable, rather than the individual functions curried in this code. I would expect that the code function be reusable, but not every function implicitly defined in it. The actual submission is what's important.

It's not a very interesting rule

The rules are (mainly) there to keep challenges open and interesting. It means that I can't hard-code a solution to a puzzle, because that would make things too easy and dull.

With this restriction I cannot see how it would make things more interesting. To me it would be a superfluous rule that's just there to be followed, and doesn't add anything to the site.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ In pure functional languages all functions are reusable anyway. \$\endgroup\$
    – DELETE_ME
    May 15, 2018 at 14:36
  • 3
    \$\begingroup\$ (however: good point. It's not clear what exactly should a partially applied function do) \$\endgroup\$
    – DELETE_ME
    May 15, 2018 at 14:37
-4
\$\begingroup\$

It can even be just currying-like

E.g. this is a valid dividing function in C++:

#define f(x)x/

Called by f(x)(y)

\$\endgroup\$

You must log in to answer this question.

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