News for hackers. Stuff that matters.
Re:The Land of Lisp by hellofunk on Friday October 06, 2017 @05:38PM (#15420680)
That's a neat example (the first one) but it's using compile time constants in the type check, which is not as impressive. You could write a similar macro in Clojure that does that.
Re:The Land of Lisp by lispm on Friday October 06, 2017 @05:56PM (#15420775)

  (declaim (ftype (function (integer string) cons)
		  foo))
  (defun foo (a b)
    (list a b))


  (declaim (ftype (function (integer) cons)
		  bar))
  (defun bar (a) (foo a a))


  (declaim (ftype (function (integer) integer)
		  baz))
  (defun baz (a) (+ (foo a "b") 42))
The SBCL compiler:

in BAR: an argument of the wrong type.

  ; in: DEFUN BAR
  ;     (FOO A A)
  ; 
  ; note: deleting unreachable code
  ; 
  ; caught WARNING:
  ;   Derived type of A is
  ;     (VALUES INTEGER &OPTIONAL),
  ;   conflicting with its asserted type
  ;     STRING.
  ;   See also:
  ;     The SBCL Manual, Node "Handling of Types"

in BAZ: the wrong return type

  ; compiling (DECLAIM (FTYPE # ...))
  ; compiling (DEFUN BAZ ...)
  ; file: /private/tmp/test.lisp
  ; in: DEFUN BAZ
  ;     (+ (FOO A "b") 42)
  ; 
  ; note: deleting unreachable code
  ; 
  ; caught WARNING:
  ;   Derived type of (FOO A "b") is
  ;     (VALUES CONS &REST T),
  ;   conflicting with its asserted type
  ;     NUMBER.
  ;   See also:
  ;     The SBCL Manual, Node "Handling of Types"