RE: [racket-users] Understanding 'curry'

2018-02-28 Thread Jos Koot
You are right, I think.
Thanks.

  _  

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




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



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


Oh, it's simple!  When you curry curry your curried curry can have curried any 
sort of arguments but it can't curry keyword
arguments, only positionals, so you need to curry curry in order to curry a 
keyword that you want to curry onto a non-curry function
to produce a curried function.


Stated in a less smart-alecky way:  You cannot curry keyword arguments onto a 
function, unless that function is the curry function
itself.  I have no idea why it does that.


Here's a series of items that clarified it for me.  I suspect you get it at 
least as well as I do, but hopefully it will help
someone else at some point:


Welcome to Racket v6.11.


> (define (pos-only a b) b)

> (pos-only 7 8)
8

> (curry pos-only 7)
# ; actual value is roughly (lambda (b) (pos-only 7 b))

> ((curry pos-only 7) 8)
8
> ((lambda (b) (pos-only 7 b)) 8)
8


> (curry curry pos-only 7) ; you can curry the 'curry' function.
#  ; roughly equivalent to (lambda args (apply (curry 
pos-only 7) args))
 

> (define (has-1-kw a #:foo b) b)
> (has-1-kw 7 #:foo 8)
8
 

> (curry has-1-kw 7)  ; you cannot curry a function with keyword arguments...
; application: required keyword argument not supplied
;   procedure: has-1-kw
;   required keyword: #:foo
; [,bt for context]

> (curry curry has-1-kw)  ; ...but you can curry the function 'curry', giving 
> it a single argument that is a function.  The function
in question requires keyword arguments, but that's not relevant here.
#  

> (curry curry #:foo 7)   ; the 'curry' function can accept arbitrary keyword 
> arguments
# ; conceptually equivalent to (lambda (func . args) (apply 
curry func _ #:foo 7)) where _ will be replaced with
more arguments later.  That is NOT legal syntax, however.


Recall that the 'curry' function takes a function (call it ) and returns a 
new function (call it ).  In general,  is not
allowed to accept keyword arguments.  The only exception to this is if  is 
the curry function itself, in which case you're free
to pass keywords. Why it's like this, I don't get any more than Jos does.






  _  

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) ; -> #
((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  that, when evaluated, will return a function  
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  that, when evaluated, will generate a function 
 that is the result of currying the keyword
argument+value '#:bar 9' onto foo.   expects N arguments where N is the 
number of positional arguments expected by foo.  It is
not possible to generate  directly, it needs to be done by creating and 
evaluating .  Also,  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)
#

> ((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)
; a

Re: [racket-users] Understanding 'curry'

2018-02-27 Thread David Storrs
On Tue, Feb 27, 2018 at 2:46 PM, Jos Koot <jos.k...@gmail.com> wrote:

> 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
>

Oh, it's simple!  When you curry curry your curried curry can have curried
any sort of arguments but it can't curry keyword arguments, only
positionals, so you need to curry curry in order to curry a keyword that
you want to curry onto a non-curry function to produce a curried function.

Stated in a less smart-alecky way:  You cannot curry keyword arguments onto
a function, unless that function is the curry function itself.  I have no
idea why it does that.


Here's a series of items that clarified it for me.  I suspect you get it at
least as well as I do, but hopefully it will help someone else at some
point:


Welcome to Racket v6.11.

> (define (pos-only a b) b)
> (pos-only 7 8)
8

> (curry pos-only 7)
# ; actual value is roughly (lambda (b) (pos-only 7 b))

> ((curry pos-only 7) 8)
8
> ((lambda (b) (pos-only 7 b)) 8)
8

> (curry curry pos-only 7) ; you can curry the 'curry' function.
#  ; roughly equivalent to (lambda args (apply (curry
pos-only 7) args))


> (define (has-1-kw a #:foo b) b)
> (has-1-kw 7 #:foo 8)
8

> (curry has-1-kw 7)  ; you cannot curry a function with keyword
arguments...
; application: required keyword argument not supplied
;   procedure: has-1-kw
;   required keyword: #:foo
; [,bt for context]

> (curry curry has-1-kw)  ; ...but you can curry the function 'curry',
giving it a single argument that is a function.  The function in question
requires keyword arguments, but that's not relevant here.
#

> (curry curry #:foo 7)   ; the 'curry' function can accept arbitrary
keyword arguments
# ; conceptually equivalent to (lambda (func . args)
(apply curry func _ #:foo 7)) where _ will be replaced with more arguments
later.  That is NOT legal syntax, however.

Recall that the 'curry' function takes a function (call it ) and returns
a new function (call it ).  In general,  is not allowed to accept
keyword arguments.  The only exception to this is if  is the curry
function itself, in which case you're free to pass keywords. Why it's like
this, I don't get any more than Jos does.




> --
> *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) ; -> #
>> ((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  that, when evaluated, will return a function
>  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  that, when evaluated, will generate a
> function  that is the result of currying the keyword argument+value
> '#:bar 9' onto foo.   expects N arguments where N is the number of
> positional arguments expected by foo.  It is not possible to generate 
> directly, it needs to be done by creating and evaluating .  Also, 
> 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)
> #
>
> > ((curry curry foo #:bar 8 #:baz 9) 7)
> 8
>
> > ((curry curry foo #:bar 8) 7)
> ; a

RE: [racket-users] Understanding 'curry'

2018-02-27 Thread Jos Koot
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) ; -> #
((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  that, when evaluated, will return a function  
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  that, when evaluated, will generate a function 
 that is the result of currying the keyword
argument+value '#:bar 9' onto foo.   expects N arguments where N is the 
number of positional arguments expected by foo.  It is
not possible to generate  directly, it needs to be done by creating and 
evaluating .  Also,  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)
#

> ((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)
#

> ((curry baz 8) 9)
9

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

> (curry foo #:bar 9)
#

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

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

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))
#

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.


Re: [racket-users] Understanding 'curry'

2018-02-27 Thread David Storrs
On Tue, Feb 27, 2018 at 12:12 PM, Jos Koot  wrote:

> curry itself is curried (which sometimes is puzzling)
>
> (define (foo a #:bar x) x)
> ((curry   foo #:bar 9) 8) ; -> #
> ((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  that, when evaluated, will return a function 
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  that, when evaluated, will generate a
function  that is the result of currying the keyword argument+value
'#:bar 9' onto foo.   expects N arguments where N is the number of
positional arguments expected by foo.  It is not possible to generate 
directly, it needs to be done by creating and evaluating .  Also, 
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)
#

> ((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@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)
> #
>
> > ((curry baz 8) 9)
> 9
>
> > (define (foo a #:bar x) x)
> > (foo 8 #:bar 9)
> 9
>
> > (curry foo #:bar 9)
> #
>
> Up to this point I'm fine, but now my understanding derails and all is
> confusion.
>
> > ((curry foo #:bar 9) 8)
> #
>
> 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))
> #
>
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/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.


RE: [racket-users] Understanding 'curry'

2018-02-27 Thread Jos Koot
curry itself is curried (which sometimes is puzzling)

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

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

Jos

-Original Message-
From: racket-users@googlegroups.com [mailto:racket-users@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)
#

> ((curry baz 8) 9)
9

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

> (curry foo #:bar 9)
#

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

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

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))
#

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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/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.