To clarify this, I think the function version is better because it's more 
powerful and more general, not just because it's convenient.
A macro constrains you to the syntax, but a function can be used in many 
different ways.

Similarly for the macro, allowing the user to specify the identifier to use as 
a placeholder allows -> expressions to be nested within other ->, meaning 
pieces can be fit together much more nicely. That's one thing functions do that 
these shorthand macros tend to leave aside.

> On Oct 8, 2015, at 12:34 AM, Alex Knauth <alexan...@knauth.org> wrote:
> 
> 
>> On Oct 8, 2015, at 12:02 AM, Jack Firth <jackhfi...@gmail.com 
>> <mailto:jackhfi...@gmail.com>> wrote:
> 
>> As for the actual package, I'm a strong proponent of a non-macro version 
>> that's just the reverse of compose, mostly because it plays very nicely with 
>> anonymous macro functions like fancy-app. I'm a bit biased as that's the one 
>> I made in my point-free package however. Macro versions are nice too, but I 
>> prefer the flexibility of an actual function for most purposes.
> 
> 
> +1
> I like the function version better too, as long as I'm also using a good 
> library (such as afl or fancy-app) for concise anonymous functions.
> 
> But for more complicated expressions, especially involving nesting, what I 
> really want is something like this:
> 
> (-> x ; declares that x is the equivalent of _ or <>
>   1
>   (add1 x)
>   (number->string x 2)
>   (string-append x "1")
>   (string->number x 10))
> 
> This is especially helpful when the xs are more deeply nested within the 
> expressions.
> 
> Which can be defined easily like this:
> (define-simple-macro (-> var:id expr:expr ...+)
>   (let* ([var expr] ...) var))
> 
> The some-> version is almost as simple:
> (define-simple-macro (some-> var:id expr0:expr expr:expr ...)
>   (let* ([var expr0] [var (and var expr)] ...) var))
> 
> I actually got this idea from Matthias Felleisen, from this email on the list:
> https://groups.google.com/forum/#!msg/racket-users/Um0_anlD8r4/1r-GFejV_HYJ 
> <https://groups.google.com/forum/#!msg/racket-users/Um0_anlD8r4/1r-GFejV_HYJ>
> Which was rewritten to use let* instead of set! here:
> https://groups.google.com/forum/#!msg/racket-users/Um0_anlD8r4/cpW0Bp-GMpUJ 
> <https://groups.google.com/forum/#!msg/racket-users/Um0_anlD8r4/cpW0Bp-GMpUJ>
> 
> I think it would be useful to provide both the function and the macro, 
> without trying to conflate the two.


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