4 ms·
I feel similarly to Gene Kim about Racket. Here's a comparison ... Gene Kim's Clojure example: ; input is JSON string: "{foo: 2}" (defn xform [s] (->
by dzpower 7y ago
I feel similarly to Gene Kim about Racket. Here's a comparison ...
Gene Kim's Clojure example:
; input is JSON string: "{foo: 2}"
(defn xform [s]
(-> (js/JSON.parse s)
js->clj
(update "foo" + 2)
clj->js
js/JSON.stringify))
Racket equivalent:
#lang racket
(require threading json)
; input is (xform "{\"foo\" : 2 }")
(define (xform s)
(~> s
string->jsexpr
(hash-update 'foo (λ (x) (+ 2 x)))
jsexpr->string))
- Uhuhreally 7y agoActual comparison with Clojure: (require [clojure.data.json :as json]) (defn xform [s] (-> s json/read-str (update "foo" + 2) json/write-str)) Your example is Clojurescript with interop
- reitzensteinm 7y agoThis is a strange comparison. ClojureScript looks bad here because it's using the native platform interop rather than a wrapped library, but the ability to easily drop down and interact with the host is one of the best parts of Clojure.
- another-one-off 7y agoWhat looks bad about the ClojureScript example? I'm obviously a bit slow, but I can't see any practical difference between the two. I do prefer the ClojureScript because I don't know how to type "λ" and that seems like a usability handicap. Minor complaint I know.
- vvillena 7y agoYou can write "lambda" instead of λ. DrRacket also has a shortcut to insert λ easily.
- dzpower 7y agoThe ClojureScript example is great. Clojure and by extension ClojureScript has a lot of tasteful and pragmatic design decisions, e.g. the use of the threading form and implicit lambda illustrated with the "+ 2"). By contrast Racket has been extended to include a Clojure-inspired threading as a library, showing off just a little of its awesome linguistic extensibility, leading in this case to ergonomically similar code. Clojure/Script is a wonderful opinionated modern Lisp; Racket is a more linguistically extensible modern Lisp. There's considerable cross-fertilisation going on. If you love Clojure, it's worth keeping an eye on Racket. * * * You can spell λ out as lambda in Racket (and Scheme).
- deleted 7y ago[deleted]
- Uhuhreally 7y agothey incorrectly said they were comparing Clojure with Racket when in fact the example they gave was verbose Clojurescript