The `~>` form provided by the `threading` package is a macro, and it treats 
parentheses differently than a normal function would.

What you are looking for is probably the ~> *function*, provided by the 
`point-free` package. That has simpler behavior, doing what you expect with 
lambdas, curried functions, and other function expressions:

#lang racket
(require point-free)

(define (add2 x) (+ x 2))
(~> 1 add2)                 ; ok
(~> 1 (lambda (x) (+ x 2))) ; ok
(~> 1 (curry + 2))          ; ok

(define adder%
  (class object%
    (super-new)
    (init-field x)
    (define/public (incr) (lambda (y) (+ x y)))))

(define adder (new adder% [x 2]))
(send adder incr)        ; ok
(~> 1 (send adder incr)) ; ok


> On Mar 31, 2018, at 9:24 PM, 若草春男 <whbug...@gmail.com> wrote:
> 
> Hi, everyone.
> 
> I think that racket threading macros can mix with expressions(lambda, curry, 
> class, ...), but not in fact.
> 
> #lang racket
> (require threading)
> 
> (define (add2 x) (+ x 2))
> (~> 1 add2) ; ok
> (~> 1 (lambda (x) (+ x 2))) ; ng
> (~> 1 (curry + 2)) ; ng
> 
> (define adder%
>   (class object%
>     (super-new)
>     (init-field x)
>     (define/public (incr) (lambda (y) (+ x y)))))
> 
> (define adder (new adder% [x 2]))
> (send adder incr) ; ok
> (~> 1 (send adder incr)) ; ng
> 
> Thanks,
> Haruo

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