4 ms·
;; clojure (defn sum-and-square [a b] (let [sum (+ a b)] (* sum sum))) Honestly, I'm not sure what you're trying to show.
by erichocean 3y ago
;; clojure
(defn sum-and-square [a b] (let [sum (+ a b)] (* sum sum)))
Honestly, I'm not sure what you're trying to show.
- lispm 3y agoI'm not sure what you are trying to show? Code can be in one line? Okaaaaay... I was trying to show that one can define local variables without adding another list level via let. Like if one would/could write in Clojure: (defn sum-and-square [a b &blah sum (+ a b)] (* sum sum)) Another Common Lisp example, we'll stick to your one liner format, using infix syntax via a reader macro: (defun sum-and-square (a b) #I(sum=a+b,sum*sum)) Before you ask: what am I trying to show? This shows that Common Lisp syntax can be deeply extended by the user and that this is a standard feature of the language. Want a shorter infix notation without s-expressions? Why not...
- samatman 3y agoReader macros are global and stateful, this is one of the worst things about Common Lisp. Excellent feature, pity we're forever burdened with the implementation.