Re: [racket-users] Re: Question about Racket design philosophy: returning (void)

2018-04-12 Thread Gustavo Massaccesi
For debuging I like

  (define (show x)
(display x)
x)

  (define (noshow x)
x)

For example in

  (define (average x)
(/ (+ (car x) (show (cdr x))) 2))

noshow is useful to turn on/off them fast.

But this is different from the convension of << in the streams of C, that
return the stream instead of the value, something like

  (<< (<< cout "Hello ") "Word!")

Gustavo

-- 
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 Racket design philosophy: returning (void)

2018-04-10 Thread Jack Firth
Racket's also flexible enough that you can say "to hell with void, I want 
function chaining" if you decide it's more appropriate:

(require fancy-app) ;; now (+ _ 1) means (lambda (v) (+ v 1))
(require point-free) ;; now (~> x f g h) means (h (g (f x)))

;; makes voidful procedures return their argument
(define ((action! proc) v)
  (proc v)
  v)

;; like ~>, but turns all procedures into actions first
(define (act~> v . procs)
  (apply ~> v (map action! procs)))

;; voila!
(act~> (make-vector 5)
   (vector-fill! _ 'blank)
   (vector-set! _ 2 'grapefruit)
   (vector-set! _ 0 'watermelon)
   (vector-map! symbol->string _)
   (vector-sort! _ stringhttps://groups.google.com/d/optout.