Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Clojure

Name: Anonymous 2011-05-18 11:32

0]=> clj
Clojure 1.2.0
user=> (defn f [x] (first x))
#'user/f
user=> (f '(1))
1
user=> (binding [first rest] (f '(1)))
()
user=> "WHAT THE FUCK. Will it work with procedures in a different namespace?"
"WHAT THE FUCK. Will it work with procedures in a different namespace?"
user=> (remove even? [1 2 3 4 5 6 7 8])
(1 3 5 7)
user=> (defn g [& rest] "BROKEN")
#'user/g
user=> (binding [filter g] (remove even? [1 2 3 4 5 6 7 8]))
"BROKEN"
user=> "Clojure, the best language of them all. All the power of unhygienic macros, and the usability of Emacs Lisp."
"Clojure, the best language of them all. All the power of unhygienic macros, and the usability of Emacs Lisp."
user=>


Let us compare Clojure with some other Lisp implementations:

Racket
0]=> racket
Welcome to Racket v5.1.1.5.
#;> (define (f x) (car x))
#;> (f '(1))
1
#;> (let ((car cdr)) (f '(1)))
1
#;>

Chicken
0]=> csi

CHICKEN
(c)2008-2010 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.6.0
linux-unix-gnu-x86 [ manyargs dload ptables ]
compiled 2010-11-09 on archlinux (Linux)

#;1> (define (f x) (car x))
#;2> (f '(1))
1
#;3> (let ((car cdr)) (f '(1)))
1
#;4>

SBCL
0]=> sbcl
This is SBCL 1.0.48, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>;.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (defun f (x) (car x))

F
* (f '(1))

1
* (flet ((car (x) (cdr x))) (f '(1)))
; in: FLET ((CAR (X) (CDR X)))
;     (FLET ((CAR (X)
;              (CDR X)))
;       (F '(1)))
;
; caught WARNING:
;   Compile-time package lock violation:
;     Lock on package COMMON-LISP violated when binding CAR as a local function
;     while in package COMMON-LISP-USER.
;   See also:
;     The SBCL Manual, Node "Package Locks"
;     The ANSI Standard, Section 11.1.2.1.2
;
; caught ERROR:
;   Lock on package COMMON-LISP violated when binding CAR as a local function while
;   in package COMMON-LISP-USER.
;   See also:
;     The SBCL Manual, Node "Package Locks"
;     The ANSI Standard, Section 11.1.2.1.2
;
; compilation unit finished
;   caught 1 ERROR condition
;   caught 1 WARNING condition

debugger invoked on a SB-INT:COMPILED-PROGRAM-ERROR in thread #<THREAD
                                                                "initial thread" RUNNING
                                                                {AAA0679}>:
  Execution of a form compiled with errors.
Form:
  (FLET ((CAR (X)
         (CDR X)))
  (F '(1)))
Compile-time error:
  Lock on package COMMON-LISP violated when binding CAR as a local function while
in package COMMON-LISP-USER.
See also:
  The SBCL Manual, Node "Package Locks"
  The ANSI Standard, Section 11.1.2.1.2

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

((EVAL (FLET ((CAR (X) (CDR X))))))
0]

Emacs Lisp
*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (require 'cl) ; flet
cl
ELISP> (defun f (x) (car x))
f
ELISP> (f '(1))
1
ELISP> (flet ((car (x) (cdr x))) (f '(1)))
nil
ELISP>


Thus, Clojure is utterly broken. Rich Hickey is actually proud of dynamically bound functions.

Name: Anonymous 2011-05-18 19:08

>>8
Please, tell me who would ever do that.

>>5
Macro in LISP.

(defmacro aif (id/cond cond/then then/else &optional maybe-else)
  (let ((id (if (symbolp id/cond) id/cond 'it))
    (cond (if (symbolp id/cond) cond/then id/cond))
    (then (if (symbolp id/cond) then/else cond/then))
    (else (if (symbolp id/cond) maybe-else then/else)))
    `(let ((,id ,cond))
       (if ,id ,then ,else))))


Macro in Racket. (!= Scheme, look at ER macros, faggot)

(define-macro aif
  #:capture it
  ((cond then else)
   (let ((it cond))
     (if it then else)))
  ((id cond then else)
   #:require (identifier? #'id)
   (let ((id cond))
     (if id then else))))


Macro in LISP.

(defmacro acond (&rest cc)
  ; I'm not going to fucking write the whole thing
  ; (acond) => #f
  ; (acond (else b ...)) => (begin b ...)
  ; (acond (e => f)) => (and e (f e))
  ; (acond (e p => f)) => (and e (p e) (f e))
  ; (acond (p -> r b ...)) => (let ((r p)) (and r (begin b ...)))
  ; (acond (p b ...)) => (if p (begin b ...))
  )


Macro in Racket.

(define-macro acond
  #:keyword (else => ->)
  (() #f)
  (((else . b) (begin . b)))
  (((e => f) (r ...) ...)
   (let ((x e))
     (if x (f x) (acond (r ...) ...))))
  (((e p => f) (r ...) ...)
   (let ((x e))
     (if (and x (p x)) (f x) (acond (r ...) ...))))
  (((p -> r . b) (r ...) ...)
   #:require (identifier? #'r)
   (aif r (begin . b) (acond (r ...) ...)))
  (((p . b) (r ...) ...)
   (aif p (begin . b) (acond (r ...) ...))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List