Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

SBCL at compile time:

    * (defun bake (pie temp time)
      "Bakes a cake for a certain amount of time, returning a cake with a new
      :tastiness level."
      (setf (tastiness pie)
            (condp (* temp time) #'<
                   (400 :burned)
                   (350 :perfect)
                   (300 :soggy))))
    ; in: DEFUN BAKE
    ;     (CONDP (* TEMP TIME)
    ;         #'<
    ;       (400 :BURNED)
    ;       (350 :PERFECT)
    ;       (300 :SOGGY))
    ; ==>
    ;   (LET ((#:PREDICATE2 (* TEMP TIME)) (#:EXPRESSION3 #'<))
    ;     (DECLARE (TYPE FUNCTION #:PREDICATE2))
    ;     (CHECK-TYPE #:PREDICATE2 FUNCTION "a predicate in CONDP")
    ;     (COND ((FUNCALL #:PREDICATE2 #:EXPRESSION3 400) :BURNED)
    ;           ((FUNCALL #:PREDICATE2 #:EXPRESSION3 350) :PERFECT)
    ;           ((FUNCALL #:PREDICATE2 #:EXPRESSION3 300) :SOGGY)))
    ;
    ; caught WARNING:
    ;   Derived type of (* TEMP TIME) is
    ;     (VALUES NUMBER &OPTIONAL),
    ;   conflicting with its asserted type
    ;     FUNCTION.
    ;   See also:
    ;     The SBCL Manual, Node "Handling of Types"
    ;
    ; compilation unit finished
    ;   caught 1 WARNING condition
Pretty cool...


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: