It breaks my brain, certainly.
Glad to read you think you are getting to it.
When you got it, explain to me, please, for I don't understand nothing of it.
I just applied some trial and error to get to a point where I can use curry.
(In fact I prefer to use my own curry (that is not curried, but neither workd 
with keyword arguments)
My private curry gives ((curry list)) -> (), not a procedure.
For me it remains a queston why curry has been made such as to give a procedure 
that in behaviour differs from a procedure produced
by an application of a curried frunction.
Jos

  _____  

From: David Storrs [mailto:david.sto...@gmail.com] 
Sent: martes, 27 de febrero de 2018 20:13
To: Jos Koot
Cc: Racket Users
Subject: Re: [racket-users] Understanding 'curry'




On Tue, Feb 27, 2018 at 12:12 PM, Jos Koot <jos.k...@gmail.com> wrote:


curry itself is curried (which sometimes is puzzling)

(define (foo a #:bar x) x)
((curry       foo #:bar 9) 8) ; -> #<procedure:curried>
((curry curry foo #:bar 9) 8) ; -> 9

I hope others can explain this in detail.
I can't.

Jos



Madness!  Madness, I say!


Okay, it looks like I misunderstood what it meant by "The curry function 
provides limited support for keyworded functions: only the
curry call itself can receive keyworded arguments to be propagated eventually 
to proc."  It's currying the keyword argument *onto
the curry function*, not onto the foo function.  The result is a form of curry, 
not a form of foo.


(define (bar a b) b)

(curry bar 7)

...produces a version of bar that takes one argument and the other one is 
already set.


(curry curry bar)

...produces a function <X> that, when evaluated, will return a function <Y> 
that is the result of currying no arguments onto the
function bar.  (Which is equivalent to bar)


Similarly:

(define (foo a #:bar x) x)

(curry curry foo #:bar 9)

...is creating a function <X> that, when evaluated, will generate a function 
<Y> that is the result of currying the keyword
argument+value '#:bar 9' onto foo.  <Y> expects N arguments where N is the 
number of positional arguments expected by foo.  It is
not possible to generate <Y> directly, it needs to be done by creating and 
evaluating <X>.  Also, <Y> will not accept keyword
arguments.

(define (foo a #:bar x #:baz y) x)
> (foo 7 #:bar 8 #:baz 9)
8

> (curry curry foo #:bar 8 #:baz 9)
#<procedure:curried>

> ((curry curry foo #:bar 8 #:baz 9) 7)
8

> ((curry curry foo #:bar 8) 7)
; application: required keyword argument not supplied
;   procedure: foo
;   required keyword: #:baz
; [,bt for context]

> ((curry curry foo #:bar 8) 7 #:baz 9)
; application: procedure does not accept keyword arguments
;   procedure: curried
; [,bt for context]


That makes my brain hurt, but I think I get it.


Thanks, Jos


 



-----Original Message-----
From: racket-users@googlegroups.com [mailto:racket-users@ 
<mailto:racket-users@googlegroups.com> googlegroups.com] On Behalf Of
David Storrs
Sent: martes, 27 de febrero de 2018 17:36
To: Racket Users
Subject: [racket-users] Understanding 'curry'

Despite using it for a long time, I discovered today that I do not
understand 'curry', at least insofar as it applies to keyword
arguments.

> (define (baz a b) b)
> (baz 8 9)
9

> (curry baz 8)
#<procedure:curried>

> ((curry baz 8) 9)
9

> (define (foo a #:bar x) x)
> (foo 8 #:bar 9)
9

> (curry foo #:bar 9)
#<procedure:curried>

Up to this point I'm fine, but now my understanding derails and all is
confusion.

> ((curry foo #:bar 9) 8)
#<procedure:curried>

I expected it to yield 9 as it did in the original direct call.  The
curry records the keyword argument and returns a function that takes
one positional argument; when that argument is supplied the original
foo function has all the arguments it needs so it should execute.

Maybe if I apply the final curried proc as a thunk?

> (((curry foo #:bar 8) 9))
#<procedure:curried>

Nope.

What am I not understanding?


--
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscribe@
<mailto:racket-users%2bunsubscr...@googlegroups.com> googlegroups.com.
For more options, visit https://groups.google.com/d/ 
<https://groups.google.com/d/optout> optout.




-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to