[racket-users] Re: Question about style

2018-08-11 Thread Andrew J
I typically use either threading or composition...

(require threading)
(define (foo x)
  (~> x 
f g h bar))

or

(define (foo x)
  ((compose bar h g f) x)


A.

On Sunday, 12 August 2018 00:11:19 UTC+10, Robert Heffernan wrote:
>
> Dear all, 
>
> I am new to Racket and only slightly less new to scheme & scheme-like 
> languages. 
>
> I have noticed myself often doing something like the following: 
>
> (define (foo x) 
>   (let* ([y (f x)] 
>  [z (g y)] 
>  [p (h z)]) 
> (bar p))) 
>
> Which could, of course, be written as 
>
> (define (foo x) 
>   (bar (h (g (f x) 
>
> Here's an example from something I was just working on: 
>
> (define (get-data input) 
>   (let* ([url-string (construct-url input)] 
>  [url (string->url url-string)] 
>  [port (get-pure-port url)]) 
> (read-json port))) 
>
> which, again, could be written as: 
> (define (get-data input) 
>   (read-json (get-pure-port (string->url (construct-url input) 
>
> My question is: is the way I'm writing things considered to be bad 
> style?  It feels like a hangover from more imperative-style programming 
> & the inclination to do one thing "per line".  On the other hand, it 
> often helps readability. 
>
> It might be, of course, that both versions amount to the same thing 
> after the interpreter has been at them. 
>
> Thanks and regards, 
> Bob Heffernan 
>

-- 
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] Re: Question about style

2018-08-11 Thread Shu-Hung You
For small expressions it probably does not matter, but suitably naming
intermediate expressions is definitely a good approach as it
`explains' the code. Also, replacing let* by define can reduce nesting
level. These 2 points are suggested in the style guide 4.2 and 4.4:

https://docs.racket-lang.org/style/Choosing_the_Right_Construct.html


On Sat, Aug 11, 2018 at 9:30 AM, Wolfgang Hukriede  wrote:
> My advice would be to follow your own taste. But drop the brackets.
>
>
> On Saturday, August 11, 2018 at 4:11:19 PM UTC+2, Robert Heffernan wrote:
>>
>> Dear all,
>>
>> I am new to Racket and only slightly less new to scheme & scheme-like
>> languages.
>>
>> I have noticed myself often doing something like the following:
>>
>> (define (foo x)
>>   (let* ([y (f x)]
>>  [z (g y)]
>>  [p (h z)])
>> (bar p)))
>>
>> Which could, of course, be written as
>>
>> (define (foo x)
>>   (bar (h (g (f x)
>>
>> Here's an example from something I was just working on:
>>
>> (define (get-data input)
>>   (let* ([url-string (construct-url input)]
>>  [url (string->url url-string)]
>>  [port (get-pure-port url)])
>> (read-json port)))
>>
>> which, again, could be written as:
>> (define (get-data input)
>>   (read-json (get-pure-port (string->url (construct-url input)
>>
>> My question is: is the way I'm writing things considered to be bad
>> style?  It feels like a hangover from more imperative-style programming
>> & the inclination to do one thing "per line".  On the other hand, it
>> often helps readability.
>>
>> It might be, of course, that both versions amount to the same thing
>> after the interpreter has been at them.
>>
>> Thanks and regards,
>> Bob Heffernan
>
> --
> 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.


[racket-users] Re: Question about style

2018-08-11 Thread Wolfgang Hukriede
My advice would be to follow your own taste. But drop the brackets.

On Saturday, August 11, 2018 at 4:11:19 PM UTC+2, Robert Heffernan wrote:
>
> Dear all, 
>
> I am new to Racket and only slightly less new to scheme & scheme-like 
> languages. 
>
> I have noticed myself often doing something like the following: 
>
> (define (foo x) 
>   (let* ([y (f x)] 
>  [z (g y)] 
>  [p (h z)]) 
> (bar p))) 
>
> Which could, of course, be written as 
>
> (define (foo x) 
>   (bar (h (g (f x) 
>
> Here's an example from something I was just working on: 
>
> (define (get-data input) 
>   (let* ([url-string (construct-url input)] 
>  [url (string->url url-string)] 
>  [port (get-pure-port url)]) 
> (read-json port))) 
>
> which, again, could be written as: 
> (define (get-data input) 
>   (read-json (get-pure-port (string->url (construct-url input) 
>
> My question is: is the way I'm writing things considered to be bad 
> style?  It feels like a hangover from more imperative-style programming 
> & the inclination to do one thing "per line".  On the other hand, it 
> often helps readability. 
>
> It might be, of course, that both versions amount to the same thing 
> after the interpreter has been at them. 
>
> Thanks and regards, 
> Bob Heffernan 
>

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