Racket: curry

Created on 6 Oct 2017  路  4Comments  路  Source: racket/racket

Code:
(curry 0)

Expected Result:
The documentation for the contract for the function curry says that it has a mandatory argument proc which must satisfy the predicate procedure? (procedure? 0) returns #f, so I expect an exn:fail:contract exception.

Actual Result:
#<procedure:curried>


Code:
(curry string? 0)

Expected Result:
The documentation for the function curry says, "Returns a procedure that is a curried version of proc," so I expect a procedure. Compare to the expression (curry (conjoin string? string?) 0) which returns a procedure. The functions string? and (conjoin string? string?) accept the same number of arguments, and they act the same way, so currying them should yield the same result.

#<procedure:curried>

Actual Result:
#f


Code:
((curry (conjoin string? string?)) 0)

Expected Result:
The documentation for the function curry says, "When the resulting procedure is first applied, unless it is given the maximum number of arguments that it can accept, the result is a procedure to accept additional arguments." The maximum number of arguments that the procedure (conjoin string? string?) can accept is one argument. And the code in this example supplies exactly one argument, so the result should not be a procedure to accept additional arguments. Compare to the expression ((curry string?) 0) which returns #f. The functions string? and (conjoin string? string?) accept the same number of arguments, and they act the same way, so currying them should yield the same result.

#f

Actual Result:
#<procedure:curried>

http://docs.racket-lang.org/reference/procedures.html#(def._((lib._racket%2Ffunction..rkt)._curry))

Most helpful comment

I agree with @schackbrian2012 that (curry 0) should immediately give a contract error.

All 4 comments

For (2), the documentation for curry as it is right now is confusing because there are 2 forms that behave differently, and the pieces of the documentation don't say which form they're describing.

The sentence "Returns a procedure that is a curried version of proc," only describes the first form, (curry proc), and the documentation for the second form, (curry proc v ...) only starts when it says "A function call (curry proc v ...)".

The documentation should be made clearer so that each piece refers to the specific form it's supposed to describe.

Are you trying to define the variable? Shouldn't you do (define (curry 0)) or something along those lines?

I agree with @schackbrian2012 that (curry 0) should immediately give a contract error.

@AlexKnauth I reread the documentation with the clarification that you gave in your comment on this issue, and it makes more sense now. I think that clarifying the documentation would solve the second example. I think that the first and third examples require more than just a clarification though.

@chriscebrero No, I am not trying to define a variable in the first example. I am trying to call the built-in curry function with an argument that violates its contract.

@iitalics Thank you, I think that your commit #0d37545 will fix the first example.

The issue in the third example remains though. I would expect (curry string? 0) and (curry (conjoin string? string?) 0) to yield the same result, but they do not.

> (string? 0)
#f
> ((conjoin string? string?) 0)
#f
> (curry string? 0)
#f
> (curry (conjoin string? string?) 0)
#<procedure:curried>
Was this page helpful?
0 / 5 - 0 ratings