greghendershott / rackjure

Provide a few Clojure-inspired ideas in Racket. Where Racket and Clojure conflict, prefer Racket.
BSD 2-Clause "Simplified" License
236 stars 17 forks source link

Composition of #λ and ~> ? #37

Closed greghendershott closed 10 years ago

greghendershott commented 10 years ago

After implementing #35 I had this idea:

;; A conventional lambda, with deeply nested function calls:
(λ (a) (z (y (x (w a)))))

;; Rewritten to use the `~>` threading macro:
(λ (a) (~> a w x y z))

;; Rewrittten to use the `#λ` reader function literal:
#λ(~> % w x y z)

;; What if you could write that like this instead:
#λ>(w x y z)

;; Or this way using `~>>` instead of `~>`:
#λ>>(w x y z)

Of course #λ> and #λ>> are open for debate.

However I don't know if this would be useful, or, if it's a solution in search of a problem. Would this improve readability, or, is this excessively concise? (I don't think I'm in a good position to judge because even the plain reader function literals from #35 aren't something I've found a big need for, so far.)

So I'm just logging this as an idea here without any plan right now to actually implement it.

cmpitg commented 10 years ago

For me,

#λ(~> % w x y z)

and

#λ>(w x y z)

look pretty much the same.

As a side note, the reader function literal from #35 has actually been a great help. See my incompleted piece of attempt to have fun with literate programming using Racket.

Some excerpt from the source code:

(define read-file #λ(call-with-input-file % port->string))

(define get-relative-path
  #λ(simple-form-path (apply build-path %&)))

(define get-temp-dir #λ(find-system-path 'temp-dir))

(define remove-dir
  #λ(delete-directory/files % #:must-exist? #f))

(define create-empty-file
  #λ(with-output-to-file %1
      (λ () (display ""))
      #:mode 'text
      #:exists 'truncate/replace))

(define path->directory
  #λ(if-let [path (file-name-from-path %)]
      (~>> path
        path->string
        (string-split %)
        first)
      %))

(define create-directory-tree
  #λ(system (format (~a "mkdir -p " %))))
greghendershott commented 10 years ago

...look pretty much the same.

Yeah, I agree. I forgot that I even had this open as an Issue. It was more a note-to-self that, today, seems not too important. I'll close it.

As a side note, the reader function literal from #35 has actually been a great help.

Great! That's neat.