SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Downloaden Sie, um offline zu lesen
Designing by Accident
Guy Steele
Sun Microsystems Laboratories

June 2007
Designing by Accident




            Copyright © 2006, 2007 Sun Microsystems, Inc. (quot;Sunquot;). All rights are reserved by Sun except as expressly stated as
            follows.
            Permission is given to the Association for Computing Machinery to distribute this work in any form as part of the
            conference proceeding materials distributed by it for the 2007 ACM FCRC Conference in San Diego, California, provided
            that the work is distributed in its entirety, including this notice. Permission to make digital or hard copies of all or part of
            this work for personal or classroom use is granted, provided that copies are not made or distributed for profit or
            commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, or
            republish, to post on servers, or to redistribute to lists, requires prior specific written permission of Sun.
                                                                                                                                               2
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Design Strategies
          • Additive
                 > Accretion of features
          • Subtractive
                 > Omission
                 > Simplification
                 > Unification
          • Intentional
          • Accidental


                                                           3
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        It Started with Lisp
          • Atoms
                 HELLO FIRST COND 0 27 -13
          • Lists
                 (RED GREEN BLUE)
                 (THIS IS A LIST OF 7 ATOMS)
                 (COLORS (RED GREEN BLUE)
                  SOUNDS (BUZZ CLANG)
                  TASTES (SWEET SOUR SALTY BITTER))
                 ()
                 (PLUS 3 4)
                                                           4
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




      Lists Are a Great Way to Write Code
     (PLUS 3 (TIMES 4 5)) evaluates to 23
     (DEFINE LENGTH (X)
       (COND ((NULL X) 0)
             (T (PLUS 1 (LENGTH (REST X))))))
     (LENGTH (RED GREEN BLUE))
      is an error: no function named RED
     (LENGTH (QUOTE (RED GREEN BLUE)))
      evaluates to 3
     NOTE: Notation has been modernized for modern audiences!
                                                                5
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Constructing Lists
        (CONS (QUOTE RED) (QUOTE (GREEN BLUE)))
         evaluates to (RED GREEN BLUE)
        (CONS (QUOTE RED)
                (CONS (QUOTE GREEN)
                        (CONS (QUOTE BLUE)
                              (QUOTE ()))))
         evaluates to (RED GREEN BLUE)
        (LIST (QUOTE RED)
                (QUOTE GREEN)
                (QUOTE BLUE))
         evaluates to (RED GREEN BLUE)
                                                           6
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Lambda Expressions as Functions
        ((LAMBDA (X Y) (LIST X Y X))
          (QUOTE RUN)
          (QUOTE LOLA))
          evaluates to (RUN LOLA RUN)
        because when the lambda expression is used as a function,
        its body, the expression (LIST X Y X), is evaluated in an
        environment in which the value of the parameter X is RUN
        and the value of the parameter Y is LOLA




                                                                    7
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Functional Arguments
        (DEFINE MAP (FN X)
          (COND ((NULL X) (QUOTE ()))
                (T (CONS (FN (FIRST X))
                         (MAP FN (REST X))))))
        applies the function FN to each element of the list X
        and returns a list of the results
        (MAP (QUOTE (LAMBDA (X) (LIST X X)))
               (QUOTE (CHITTY BANG)))
         evaluates to ((CHITTY CHITTY) (BANG BANG))


                                                                8
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The Evaluator Is Easy to Write in Lisp
        (DEFINE EVAL (X ENV)
          (COND ((NUMBERP X) X)
                ((ATOM X) (LOOKUP X ENV))
                ((EQ (FIRST X) (QUOTE QUOTE))
                 (SECOND X))
                ((EQ (FIRST X) (QUOTE COND))
                 (EVCOND (REST X) ENV))
                (T (APPLY (FIRST FORM)
                          (EVLIS (REST FORM)
                                 ENV)
                          ENV))))
                                                           9
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Representation of Environments
        An “environment” is just a list of name-value pairs:
        ((N 3) (X (RED GREEN BLUE)) (Y HELLO))
        We say that the name N is bound to the value 3,
        the name X is bound to the value (RED GREEN BLUE),
        the name Y is bound to the value HELLO, and so on.
        If a name appears more than once, the leftmost pair is used.
        (DEFINE LOOKUP (X ENV)
          (COND ((NULL ENV) (ERROR))
                ((EQ (FIRST (FIRST ENV)) X)
                 (SECOND (FIRST ENV)))
                (T (LOOKUP X (REST ENV)))))
                                                                       10
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Conditionals and Argument Lists
        (DEFINE EVCOND (C ENV)
          (COND ((NULL C) (QUOTE ()))
                ((ATOM (FIRST C)) (ERROR))
                ((EVAL (FIRST (FIRST C)) ENV)
                 (EVAL (SECOND (FIRST C)) ENV))
                (T (EVCOND (REST C) ENV))))
        (DEFINE EVLIS (X ENV)
          (COND ((NULL X) (QUOTE ()))
                (T (CONS (EVAL (FIRST X) ENV)
                         (EVLIS (REST X)
                                ENV)))))
                                                           11
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Applying Functions
        (DEFINE APPLY (FN ARGS ENV)
          (COND ((NULL FN) (ERROR))
                ((PRIMOP FN) (PRIMAPP FN ARGS))
                ((ATOM FN)
                 (APPLY (LOOKUP FN ENV)
                        ARGS ENV))
                ((EQ (FIRST FN) (QUOTE LAMBDA))
                 (EVAL (THIRD FN)
                       (BIND (SECOND FN)
                              ARGS ENV)))
                (T (APPLY (EVAL FN ENV)
                           ARGS ENV))))         12
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Applying Primitive Functions
        (DEFINE PRIMAPP (FN ARGS)
          (COND ((EQ FN (QUOTE FIRST))
                 (FIRST (FIRST ARGS)))
                ((EQ FN (QUOTE SECOND))
                 (SECOND (FIRST ARGS)))
                ((EQ FN (QUOTE ATOM))
                 (ATOM (FIRST ARGS)))
                ((EQ FN (QUOTE CONS))
                 (CONS (FIRST ARGS) (SECOND ARGS)))
                ((EQ FN (QUOTE PLUS))
                 (PLUS (FIRST ARGS) (SECOND ARGS)))
                ((EQ FN (QUOTE LIST)) ARGS)
                ... ))                                     13
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Binding Parameters to Arguments
        (DEFINE BIND (PARAMS ARGS ENV)
          (COND ((NULL PARAMS)
                 (COND ((NULL ARGS) ENV)
                       (T (ERROR))))
                ((NULL ARGS) (ERROR))
                (T (CONS (LIST (FIRST PARAMS)
                               (FIRST ARGS))
                         (BIND (REST PARAMS)
                               (REST ARGS)
                               ENV)))))

                                                           14
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The “Funarg Problem”
        (DEFINE MAP (FN X)
          (COND ((NULL X) (QUOTE ()))
                (T (CONS (FN (FIRST X))
                         (MAP FN (REST X))))))
        (DEFINE CONSALL (X YS)
          (MAP (QUOTE (LAMBDA (Y) (CONS X Y))) YS))
        (CONSALL (QUOTE BEAT)
                      (QUOTE ((HARVARD) (YALE))))
        we expect to get:
        ((BEAT HARVARD) (BEAT YALE))
        we actually get:
        ((((HARVARD) (YALE)) HARVARD) (((YALE)) YALE))
                                                           15
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




       Fixing the Evaluator
      (DEFINE EVAL (X ENV)
        (COND ((NUMBERP X) X)
              ...
              ((EQ (FIRST X) (QUOTE FUNCTION))
               (LIST (QUOTE FUNARG)
                     (SECOND X)
                     ENV)))
              ...
              (T (APPLY (FIRST FORM)
                        (EVLIS (REST FORM)
                               ENV)
                        ENV))))              16
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Fixing Function Application
        (DEFINE APPLY (FN ARGS ENV)
          (COND ((NULL FN) (ERROR))
                ...
                ((EQ (FIRST FN) (QUOTE FUNARG))
                 (APPLY (SECOND FN)
                        ARGS
                        (THIRD FN)))
                ...
                (T (APPLY (EVAL FN ENV)
                          ARGS ENV))))

                                                           17
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The Funarg Solution
        (DEFINE MAP (FN X)
          (COND ((NULL X) (QUOTE ()))
                (T (CONS (FN (FIRST X))
                         (MAP FN (REST X))))))
        (DEFINE CONSALL (X YS)
          (MAP (FUNCTION (LAMBDA (Y) (CONS X Y))) YS))
        (CONSALL (QUOTE BEAT)
                      (QUOTE ((HARVARD) (YALE))))
        we actually get:
           ((BEAT HARVARD) (BEAT YALE))
        as desired

                                                           18
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Objects and Actors
          • Inspired in part by SIMULA and Smalltalk, Carl Hewitt
            developed a model of computation around “actors”
                       Every agent of computation is an actor
                 >
                       Every datum or data structure is an actor
                 >
                       An actor may have “acquaintances” (other actors it knows)
                 >
                       Actors react to messages sent from other actors
                 >
                       An actor can send messages only to acquaintances
                 >
                       and to actors received in messages
          • “You don’t add 3 and 2 to get 5; instead, you send 3 a
            message asking it to add 2 to itself”

                                                                                   19
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Factorial Function in Lisp
        (DEFINE FACTORIAL (N)
          (COND ((ZEROP N) 1)
                (T (TIMES N (FACTORIAL
                              (DIFFERENCE
                                 N 1)))))
        returns the product of the integers from 1 to N
        (FACTORIAL 5)
         evaluates to 120



                                                           20
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The “Factorial” Actor (1 of 8)
                                                                       –
                                                            ZEROP
                                                                           !

                                                           FACTORIAL




                                                                               21
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The “Factorial” Actor (2 of 8)
                                                                               –
                                                                    ZEROP
                                    USER                                           !
                                                               K
                                                           5

                                                                   FACTORIAL




                                                                                       22
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The “Factorial” Actor (3 of 8)
                                    USER                                               !
                                                               K
                                                           5

                                                                   FACTORIAL
                                                                                           L
                                                                               –   1

                                                                           5




                                                                                               23
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The “Factorial” Actor (4 of 8)
                                    USER                                                    !
                                                               K
                                                           5

                                                                   FACTORIAL
                                                                                                L
                                                                                    –   1

                                                                            5

                                                                                4
                                                                        L




                                                                                                    24
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The “Factorial” Actor (5 of 8)
                                    USER                                                       !
                                                               K
                                                           5

                                                                   FACTORIAL
                                                                                                   L
                                                                                       –   1

                                                                               5
                                                                       M
                                                                   4

                                                                                   4
                                                                   !
                                                                           L




                                                                                                       25
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The “Factorial” Actor (6 of 8)
                                    USER                                                                !
                                                                        K
                                                                    5

                                                                            FACTORIAL
                                                                                                            L
                                                                                                –   1
                                                               24

                                                                    ...                 5
                                                                                M
                                                                            4
                                                           M
                                                                                            4
                                                                            !
                                                                                    L




                                                                                                                26
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The “Factorial” Actor (7 of 8)
                                    USER                                                                !
                                                                        K
                                                                    5

                                                                            FACTORIAL
                                                                                                            L
                                                                                                –   1
                                                               24

                                                                    ...                 5
                                                                                M
                                                                            4
                                                           M
                                           K
                              24
                  !                                                                         4
                                                                            !
                                                                                    L
                                          5



                                                                                                                27
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        The “Factorial” Actor (8 of 8)
                                    USER                                                                  !
                                                                          K
                                                                      5

                                                                              FACTORIAL
                                                                                                          L
                                                                                                  –   1
                                                                 24

                                                                      ...                 5
                                                                                  M
                                                                              4
                                                           M
                                           K
                   ! 24                                                                       4
                                                                              !
                                                                                      L
                                                           120
                                          5

                                                                      ...
                                                                 K

                                                                                                              28
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Factorial in the PLASMA Language
        Carl had an actors-based language with a difficult syntax,
        described with what seemed like difficult terminology.
                 (define
                  [factorial !
                    (!!> (message: [=n] (reply-to: =c))
                     (rules n
                                                            From an early working draft,
                       (!> 1 (c <== (message: 1)))          dated December 1975, of
                                                            “Viewing Control Structures as
                       (else (factorial <==                 Patterns of Passing Messages”
                                                            by Carl Hewitt; after multiple
                                (message: (n – 1)           revisions, this became MIT AI
                                 (reply-to:                 Memo 410 in December 1976.

                                   (!!> (message: =y)
                                    (c <== (message: (y * n))))))))))])                    29
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




             Gerry Sussman and I wanted to understand
                           Carl Hewitt’s ideas,
              which seemed to have intellectual power,
       but we couldn’t get past the complexity and the notation
                   to see “what was really going on.”
        So we decided to implement a “toy” actors language.
       We hoped that it could capture the essence of the ideas
            while remaining simple enough to understand.
              It might even turn into something useful.

                                                                  30
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        A Sequence of AI Languages at MIT
                               LISP (McCarthy et al., 1958)
                                 METEOR (Bobrow, 1964)
                                CONVERT (Guzman, 1969)
                                 PLANNER (Hewitt, 1969)
                           MUDDLE (Sussman, Hewitt, et al., 1970)
                           MICROPLANNER (Sussman et al., 1971)
                             CONNIVER (Sussman et al., 1972)
                               PLASMA (Hewitt et al., 1973)
                           SCHEMER (Sussman and Steele, 1975)
                                                                    31
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




         We decided to start with a small Lisp interpreter and
               then graft on exactly two more constructs:
         a way to make actors and a way to send messages.
            Gerry had been studying and teaching Algol 60,
              so we decided to use the full funarg solution
          so that our toy language would have lexical scope.
                  Our intuition was that this would also
             keep track of actor’s acquaintances correctly.
           (Also inspired by Algol 60, the first toy interpreter
              was call-by-name rather than call-by-value!
                 I will gloss over that distinction here.)
                                                                   32
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




                          For making an actor, we chose the syntax
                            (alpha (parameters) body)
         It would be just like a lambda expression, but its body
            had to send a message rather than return a value.
                  For sending messages, we considered
             (send actor argument ... argument)
     but then realized apply could tell actors from functions
     and so we could just use the same keyword-free syntax
           for calling functions and sending messages.

                                                                     33
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




             We would also need some primitive actors.
                   We decided on (among others):
                          send product of m and n to actor k
         (* m n k)
                          send difference of m and n to actor k
         (- m n k)
         (= m n k q) if m and n equal, send an empty
                          message to actor k; otherwise send
                          an empty message to actor q
             Note that these actors never return a value.
            They always send a message to another actor.
                                                                  34
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




          We wanted to try out this definition of factorial:
          (define factorial
            (alpha (n c)
              (= n 0
                 (alpha () (c 1))
                 (alpha ()
                   (- n 1
                      (alpha (z)
                        (factorial z
                          (alpha (y)
                            (* n y c)))))))))
          Note that this was not very different in structure from Carl’s,
          but somehow it was much less intimidating to us in the details.   35
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




                        IMPORTANT DISCLAIMER
          The original Scheme interpreter was written in a very
           machine-language-like style of Lisp so as to expose
            every implementation detail. It was very much like
             Peter Landin’s SECD machine and did not take
               advantage of recursive function calls in the
                         implementation language.
           Here I want to gloss over the implementation details
             so as not to obscure the main point of this talk.
          Therefore I am going to show you a simplified version
             of the interpreter, in the same style as the Lisp
                    interpreter shown on earlier slides.
                                                                  36
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        A Scheme Evaluator
        (DEFINE EVAL (X ENV)
          (COND ((NUMBERP X) X)
                ((ATOM X) (LOOKUP X ENV))
                ((EQ (FIRST X) (QUOTE QUOTE))
                 (SECOND X))
                ((EQ (FIRST X) (QUOTE COND))
                 (EVCOND (REST X) ENV))
                ((EQ (FIRST X) (QUOTE LAMBDA))
                 (LIST (QUOTE BETA) X ENV))
                (T ((LAMBDA (EV)
                      (APPLY (FIRST EV) (REST EV)))
                    (EVLIS FORM ENV)))))

                                                           37
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Applying Functions
        (DEFINE APPLY (FN ARGS ENV)
          (COND ((NULL FN) (ERROR))
                ((PRIMOP FN) (PRIMAPP FN ARGS))
                ((EQ (FIRST FN) (QUOTE BETA))
                 (EVAL (THIRD (SECOND FN))
                       (BIND (SECOND (SECOND FN))
                              ARGS
                              (THIRD FN))))
                (T (ERROR))))

        Everything else (LOOKUP, EVCOND, EVLIS, PRIMOP,
        PRIMAPP, BIND) is the same as before.

                                                           38
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Sending to Primitive Actors (1 of 2)
        (DEFINE PRIMSEND (ACTOR ARGS)
          (COND ((EQ ACTOR (QUOTE *))
                 (APPLY (THIRD ARGS)
                        (LIST (TIMES
                                (FIRST ARGS)
                                (SECOND ARGS)))))
                ((EQ ACTOR (QUOTE -))
                 (APPLY (THIRD ARGS)
                        (LIST (DIFFERENCE
                                (FIRST ARGS)
                                (SECOND ARGS)))))
                ...
                                                           39
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Sending to Primitive Actors (2 of 2)
                                      ...
                                      ((EQ ACTOR (QUOTE =))
                                       (APPLY (COND ((EQUAL (FIRST ARGS)
                                                            (SECOND ARGS))
                                                     (THIRD ARGS))
                                                    (T (FOURTH ARGS)))
                                              (QUOTE ())))
                                      ... ))




                                                                             40
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        A Scheme Evaluator with Actors
        (DEFINE EVAL (X ENV)
          (COND ((NUMBERP X) X)
                ((ATOM X) (LOOKUP X ENV))
                ((EQ (FIRST X) (QUOTE QUOTE))
                 (SECOND X))
                ((EQ (FIRST X) (QUOTE COND))
                 (EVCOND (REST X) ENV))
                ((EQ (FIRST X) (QUOTE LAMBDA))
                 (LIST (QUOTE BETA) X ENV))
                ((EQ (FIRST X) (QUOTE ALPHA))
                 (LIST (QUOTE GAMMA) X ENV))
                (T ((LAMBDA (EV)
                      (APPLY (FIRST EV) (REST EV)))
                    (EVLIS FORM ENV)))))                   41
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Sending Messages to Actors
        (DEFINE APPLY (FA ARGS ENV)
          (COND ((NULL FA) (ERROR))
                ((PRIMOP FA) (PRIMAPP FA ARGS))
                ((PRIMACTOR FA) (PRIMSEND FA ARGS))
                ...
                ((EQ (FIRST FA) (QUOTE GAMMA))
                 (EVAL (THIRD (SECOND FA))
                       (BIND (SECOND (SECOND FA))
                              ARGS
                              (THIRD FA))))
                (T (ERROR))))


                                                           42
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




                                        Now evaluating the message send
                                                     (factorial 5 fred)

                       results in sending a message containing 120
                                  to the actor named fred.


                                                           Oh, joy!



                                                                          43
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        A Startling Equivalence
        (DEFINE APPLY (FA ARGS ENV)
          (COND ...
                ((EQ (FIRST FA) (QUOTE BETA))
                 (EVAL (THIRD (SECOND FA))
                       (BIND (SECOND (SECOND FA))
                              ARGS
                              (THIRD FA))))
                ((EQ (FIRST FA) (QUOTE GAMMA))
                 (EVAL (THIRD (SECOND FA))
                       (BIND (SECOND (SECOND FA))
                              ARGS
                              (THIRD FA))))
                (T (ERROR))))
                                                           44
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        An Astonishing Conclusion
                     Actor constructors and lambda expressions
                  in our toy language are operationally equivalent.
                    Does it follow that actors are “merely” functions
                     in a tail-recursive, lexically scoped language?
                           They are the same mechanism.
                   Any difference is not inherent, but depends only
                            on what you put in their bodies.
                   If your primitive operators are functions,
              you will tend to write programs in a functional style.
                     If your primitive operators are actors,
               you will tend to write programs in an actor style.       45
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        A New Language Is Born
              After some discussion, Carl Hewitt agreed with our
                    conclusions (with two minor exceptions).
                  In a way, this ended the “language competition.”
        Our great new AI language “Schemer” turned out to be
          a small dialect of Lisp with some nice properties.

                                                           Oh, yes: the name?
              File names in that OS were limited to 6 characters.
                                                              “SCHEME”
                                                                                46
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Success
                      I wrote a compiler for Scheme (called Rabbit).
                                    Soon, other people built much better
                                       implementations of Scheme.
                                      Lots of other people found it useful.
                        The Scheme standard is in its sixth revision.


             Very few people bother to cite our papers anymore.
                                                           We are delighted.
                                                                               47
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




        Lessons


          • Exploration can be fruitful
          • Always be alert for simplifying insights
                 > They are more plentiful than you think
                 > But they are hard to plan for
          • Serendipity happens to those who are ready for it




                                                                48
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
Designing by Accident




                  Luck favors the prepared.
                                                           —Edna Mode




                                                                        49
© 2006, 2007 Sun Microsystems, Inc. All rights reserved.
guy.steele@sun.com

Weitere ähnliche Inhalte

Mehr von CS, NcState

GALE: Geometric active learning for Search-Based Software Engineering
GALE: Geometric active learning for Search-Based Software EngineeringGALE: Geometric active learning for Search-Based Software Engineering
GALE: Geometric active learning for Search-Based Software EngineeringCS, NcState
 
Big Data: the weakest link
Big Data: the weakest linkBig Data: the weakest link
Big Data: the weakest linkCS, NcState
 
Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...
Three Laws of Trusted Data Sharing:(Building a Better Business Case for Dat...Three Laws of Trusted Data Sharing:(Building a Better Business Case for Dat...
Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...CS, NcState
 
Lexisnexis june9
Lexisnexis june9Lexisnexis june9
Lexisnexis june9CS, NcState
 
Welcome to ICSE NIER’15 (new ideas and emerging results).
Welcome to ICSE NIER’15 (new ideas and emerging results).Welcome to ICSE NIER’15 (new ideas and emerging results).
Welcome to ICSE NIER’15 (new ideas and emerging results).CS, NcState
 
Icse15 Tech-briefing Data Science
Icse15 Tech-briefing Data ScienceIcse15 Tech-briefing Data Science
Icse15 Tech-briefing Data ScienceCS, NcState
 
Kits to Find the Bits that Fits
Kits to Find  the Bits that Fits Kits to Find  the Bits that Fits
Kits to Find the Bits that Fits CS, NcState
 
Ai4se lab template
Ai4se lab templateAi4se lab template
Ai4se lab templateCS, NcState
 
Automated Software Enging, Fall 2015, NCSU
Automated Software Enging, Fall 2015, NCSUAutomated Software Enging, Fall 2015, NCSU
Automated Software Enging, Fall 2015, NCSUCS, NcState
 
Requirements Engineering
Requirements EngineeringRequirements Engineering
Requirements EngineeringCS, NcState
 
172529main ken and_tim_software_assurance_research_at_west_virginia
172529main ken and_tim_software_assurance_research_at_west_virginia172529main ken and_tim_software_assurance_research_at_west_virginia
172529main ken and_tim_software_assurance_research_at_west_virginiaCS, NcState
 
Automated Software Engineering
Automated Software EngineeringAutomated Software Engineering
Automated Software EngineeringCS, NcState
 
Next Generation “Treatment Learning” (finding the diamonds in the dust)
Next Generation “Treatment Learning” (finding the diamonds in the dust)Next Generation “Treatment Learning” (finding the diamonds in the dust)
Next Generation “Treatment Learning” (finding the diamonds in the dust)CS, NcState
 
Tim Menzies, directions in Data Science
Tim Menzies, directions in Data ScienceTim Menzies, directions in Data Science
Tim Menzies, directions in Data ScienceCS, NcState
 
Dagstuhl14 intro-v1
Dagstuhl14 intro-v1Dagstuhl14 intro-v1
Dagstuhl14 intro-v1CS, NcState
 
The Art and Science of Analyzing Software Data
The Art and Science of Analyzing Software DataThe Art and Science of Analyzing Software Data
The Art and Science of Analyzing Software DataCS, NcState
 
What Metrics Matter?
What Metrics Matter? What Metrics Matter?
What Metrics Matter? CS, NcState
 

Mehr von CS, NcState (20)

Future se oct15
Future se oct15Future se oct15
Future se oct15
 
GALE: Geometric active learning for Search-Based Software Engineering
GALE: Geometric active learning for Search-Based Software EngineeringGALE: Geometric active learning for Search-Based Software Engineering
GALE: Geometric active learning for Search-Based Software Engineering
 
Big Data: the weakest link
Big Data: the weakest linkBig Data: the weakest link
Big Data: the weakest link
 
Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...
Three Laws of Trusted Data Sharing:(Building a Better Business Case for Dat...Three Laws of Trusted Data Sharing:(Building a Better Business Case for Dat...
Three Laws of Trusted Data Sharing: (Building a Better Business Case for Dat...
 
Lexisnexis june9
Lexisnexis june9Lexisnexis june9
Lexisnexis june9
 
Welcome to ICSE NIER’15 (new ideas and emerging results).
Welcome to ICSE NIER’15 (new ideas and emerging results).Welcome to ICSE NIER’15 (new ideas and emerging results).
Welcome to ICSE NIER’15 (new ideas and emerging results).
 
Icse15 Tech-briefing Data Science
Icse15 Tech-briefing Data ScienceIcse15 Tech-briefing Data Science
Icse15 Tech-briefing Data Science
 
Kits to Find the Bits that Fits
Kits to Find  the Bits that Fits Kits to Find  the Bits that Fits
Kits to Find the Bits that Fits
 
Ai4se lab template
Ai4se lab templateAi4se lab template
Ai4se lab template
 
Automated Software Enging, Fall 2015, NCSU
Automated Software Enging, Fall 2015, NCSUAutomated Software Enging, Fall 2015, NCSU
Automated Software Enging, Fall 2015, NCSU
 
Requirements Engineering
Requirements EngineeringRequirements Engineering
Requirements Engineering
 
172529main ken and_tim_software_assurance_research_at_west_virginia
172529main ken and_tim_software_assurance_research_at_west_virginia172529main ken and_tim_software_assurance_research_at_west_virginia
172529main ken and_tim_software_assurance_research_at_west_virginia
 
Automated Software Engineering
Automated Software EngineeringAutomated Software Engineering
Automated Software Engineering
 
Next Generation “Treatment Learning” (finding the diamonds in the dust)
Next Generation “Treatment Learning” (finding the diamonds in the dust)Next Generation “Treatment Learning” (finding the diamonds in the dust)
Next Generation “Treatment Learning” (finding the diamonds in the dust)
 
Tim Menzies, directions in Data Science
Tim Menzies, directions in Data ScienceTim Menzies, directions in Data Science
Tim Menzies, directions in Data Science
 
Goldrush
GoldrushGoldrush
Goldrush
 
Dagstuhl14 intro-v1
Dagstuhl14 intro-v1Dagstuhl14 intro-v1
Dagstuhl14 intro-v1
 
Know thy tools
Know thy toolsKnow thy tools
Know thy tools
 
The Art and Science of Analyzing Software Data
The Art and Science of Analyzing Software DataThe Art and Science of Analyzing Software Data
The Art and Science of Analyzing Software Data
 
What Metrics Matter?
What Metrics Matter? What Metrics Matter?
What Metrics Matter?
 

Kürzlich hochgeladen

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Kürzlich hochgeladen (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Designing by Accident

  • 1. Designing by Accident Guy Steele Sun Microsystems Laboratories June 2007
  • 2. Designing by Accident Copyright © 2006, 2007 Sun Microsystems, Inc. (quot;Sunquot;). All rights are reserved by Sun except as expressly stated as follows. Permission is given to the Association for Computing Machinery to distribute this work in any form as part of the conference proceeding materials distributed by it for the 2007 ACM FCRC Conference in San Diego, California, provided that the work is distributed in its entirety, including this notice. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted, provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, or republish, to post on servers, or to redistribute to lists, requires prior specific written permission of Sun. 2 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 3. Designing by Accident Design Strategies • Additive > Accretion of features • Subtractive > Omission > Simplification > Unification • Intentional • Accidental 3 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 4. Designing by Accident It Started with Lisp • Atoms HELLO FIRST COND 0 27 -13 • Lists (RED GREEN BLUE) (THIS IS A LIST OF 7 ATOMS) (COLORS (RED GREEN BLUE) SOUNDS (BUZZ CLANG) TASTES (SWEET SOUR SALTY BITTER)) () (PLUS 3 4) 4 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 5. Designing by Accident Lists Are a Great Way to Write Code (PLUS 3 (TIMES 4 5)) evaluates to 23 (DEFINE LENGTH (X) (COND ((NULL X) 0) (T (PLUS 1 (LENGTH (REST X)))))) (LENGTH (RED GREEN BLUE)) is an error: no function named RED (LENGTH (QUOTE (RED GREEN BLUE))) evaluates to 3 NOTE: Notation has been modernized for modern audiences! 5 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 6. Designing by Accident Constructing Lists (CONS (QUOTE RED) (QUOTE (GREEN BLUE))) evaluates to (RED GREEN BLUE) (CONS (QUOTE RED) (CONS (QUOTE GREEN) (CONS (QUOTE BLUE) (QUOTE ())))) evaluates to (RED GREEN BLUE) (LIST (QUOTE RED) (QUOTE GREEN) (QUOTE BLUE)) evaluates to (RED GREEN BLUE) 6 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 7. Designing by Accident Lambda Expressions as Functions ((LAMBDA (X Y) (LIST X Y X)) (QUOTE RUN) (QUOTE LOLA)) evaluates to (RUN LOLA RUN) because when the lambda expression is used as a function, its body, the expression (LIST X Y X), is evaluated in an environment in which the value of the parameter X is RUN and the value of the parameter Y is LOLA 7 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 8. Designing by Accident Functional Arguments (DEFINE MAP (FN X) (COND ((NULL X) (QUOTE ())) (T (CONS (FN (FIRST X)) (MAP FN (REST X)))))) applies the function FN to each element of the list X and returns a list of the results (MAP (QUOTE (LAMBDA (X) (LIST X X))) (QUOTE (CHITTY BANG))) evaluates to ((CHITTY CHITTY) (BANG BANG)) 8 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 9. Designing by Accident The Evaluator Is Easy to Write in Lisp (DEFINE EVAL (X ENV) (COND ((NUMBERP X) X) ((ATOM X) (LOOKUP X ENV)) ((EQ (FIRST X) (QUOTE QUOTE)) (SECOND X)) ((EQ (FIRST X) (QUOTE COND)) (EVCOND (REST X) ENV)) (T (APPLY (FIRST FORM) (EVLIS (REST FORM) ENV) ENV)))) 9 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 10. Designing by Accident Representation of Environments An “environment” is just a list of name-value pairs: ((N 3) (X (RED GREEN BLUE)) (Y HELLO)) We say that the name N is bound to the value 3, the name X is bound to the value (RED GREEN BLUE), the name Y is bound to the value HELLO, and so on. If a name appears more than once, the leftmost pair is used. (DEFINE LOOKUP (X ENV) (COND ((NULL ENV) (ERROR)) ((EQ (FIRST (FIRST ENV)) X) (SECOND (FIRST ENV))) (T (LOOKUP X (REST ENV))))) 10 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 11. Designing by Accident Conditionals and Argument Lists (DEFINE EVCOND (C ENV) (COND ((NULL C) (QUOTE ())) ((ATOM (FIRST C)) (ERROR)) ((EVAL (FIRST (FIRST C)) ENV) (EVAL (SECOND (FIRST C)) ENV)) (T (EVCOND (REST C) ENV)))) (DEFINE EVLIS (X ENV) (COND ((NULL X) (QUOTE ())) (T (CONS (EVAL (FIRST X) ENV) (EVLIS (REST X) ENV))))) 11 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 12. Designing by Accident Applying Functions (DEFINE APPLY (FN ARGS ENV) (COND ((NULL FN) (ERROR)) ((PRIMOP FN) (PRIMAPP FN ARGS)) ((ATOM FN) (APPLY (LOOKUP FN ENV) ARGS ENV)) ((EQ (FIRST FN) (QUOTE LAMBDA)) (EVAL (THIRD FN) (BIND (SECOND FN) ARGS ENV))) (T (APPLY (EVAL FN ENV) ARGS ENV)))) 12 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 13. Designing by Accident Applying Primitive Functions (DEFINE PRIMAPP (FN ARGS) (COND ((EQ FN (QUOTE FIRST)) (FIRST (FIRST ARGS))) ((EQ FN (QUOTE SECOND)) (SECOND (FIRST ARGS))) ((EQ FN (QUOTE ATOM)) (ATOM (FIRST ARGS))) ((EQ FN (QUOTE CONS)) (CONS (FIRST ARGS) (SECOND ARGS))) ((EQ FN (QUOTE PLUS)) (PLUS (FIRST ARGS) (SECOND ARGS))) ((EQ FN (QUOTE LIST)) ARGS) ... )) 13 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 14. Designing by Accident Binding Parameters to Arguments (DEFINE BIND (PARAMS ARGS ENV) (COND ((NULL PARAMS) (COND ((NULL ARGS) ENV) (T (ERROR)))) ((NULL ARGS) (ERROR)) (T (CONS (LIST (FIRST PARAMS) (FIRST ARGS)) (BIND (REST PARAMS) (REST ARGS) ENV))))) 14 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 15. Designing by Accident The “Funarg Problem” (DEFINE MAP (FN X) (COND ((NULL X) (QUOTE ())) (T (CONS (FN (FIRST X)) (MAP FN (REST X)))))) (DEFINE CONSALL (X YS) (MAP (QUOTE (LAMBDA (Y) (CONS X Y))) YS)) (CONSALL (QUOTE BEAT) (QUOTE ((HARVARD) (YALE)))) we expect to get: ((BEAT HARVARD) (BEAT YALE)) we actually get: ((((HARVARD) (YALE)) HARVARD) (((YALE)) YALE)) 15 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 16. Designing by Accident Fixing the Evaluator (DEFINE EVAL (X ENV) (COND ((NUMBERP X) X) ... ((EQ (FIRST X) (QUOTE FUNCTION)) (LIST (QUOTE FUNARG) (SECOND X) ENV))) ... (T (APPLY (FIRST FORM) (EVLIS (REST FORM) ENV) ENV)))) 16 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 17. Designing by Accident Fixing Function Application (DEFINE APPLY (FN ARGS ENV) (COND ((NULL FN) (ERROR)) ... ((EQ (FIRST FN) (QUOTE FUNARG)) (APPLY (SECOND FN) ARGS (THIRD FN))) ... (T (APPLY (EVAL FN ENV) ARGS ENV)))) 17 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 18. Designing by Accident The Funarg Solution (DEFINE MAP (FN X) (COND ((NULL X) (QUOTE ())) (T (CONS (FN (FIRST X)) (MAP FN (REST X)))))) (DEFINE CONSALL (X YS) (MAP (FUNCTION (LAMBDA (Y) (CONS X Y))) YS)) (CONSALL (QUOTE BEAT) (QUOTE ((HARVARD) (YALE)))) we actually get: ((BEAT HARVARD) (BEAT YALE)) as desired 18 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 19. Designing by Accident Objects and Actors • Inspired in part by SIMULA and Smalltalk, Carl Hewitt developed a model of computation around “actors” Every agent of computation is an actor > Every datum or data structure is an actor > An actor may have “acquaintances” (other actors it knows) > Actors react to messages sent from other actors > An actor can send messages only to acquaintances > and to actors received in messages • “You don’t add 3 and 2 to get 5; instead, you send 3 a message asking it to add 2 to itself” 19 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 20. Designing by Accident Factorial Function in Lisp (DEFINE FACTORIAL (N) (COND ((ZEROP N) 1) (T (TIMES N (FACTORIAL (DIFFERENCE N 1))))) returns the product of the integers from 1 to N (FACTORIAL 5) evaluates to 120 20 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 21. Designing by Accident The “Factorial” Actor (1 of 8) – ZEROP ! FACTORIAL 21 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 22. Designing by Accident The “Factorial” Actor (2 of 8) – ZEROP USER ! K 5 FACTORIAL 22 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 23. Designing by Accident The “Factorial” Actor (3 of 8) USER ! K 5 FACTORIAL L – 1 5 23 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 24. Designing by Accident The “Factorial” Actor (4 of 8) USER ! K 5 FACTORIAL L – 1 5 4 L 24 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 25. Designing by Accident The “Factorial” Actor (5 of 8) USER ! K 5 FACTORIAL L – 1 5 M 4 4 ! L 25 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 26. Designing by Accident The “Factorial” Actor (6 of 8) USER ! K 5 FACTORIAL L – 1 24 ... 5 M 4 M 4 ! L 26 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 27. Designing by Accident The “Factorial” Actor (7 of 8) USER ! K 5 FACTORIAL L – 1 24 ... 5 M 4 M K 24 ! 4 ! L 5 27 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 28. Designing by Accident The “Factorial” Actor (8 of 8) USER ! K 5 FACTORIAL L – 1 24 ... 5 M 4 M K ! 24 4 ! L 120 5 ... K 28 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 29. Designing by Accident Factorial in the PLASMA Language Carl had an actors-based language with a difficult syntax, described with what seemed like difficult terminology. (define [factorial ! (!!> (message: [=n] (reply-to: =c)) (rules n From an early working draft, (!> 1 (c <== (message: 1))) dated December 1975, of “Viewing Control Structures as (else (factorial <== Patterns of Passing Messages” by Carl Hewitt; after multiple (message: (n – 1) revisions, this became MIT AI (reply-to: Memo 410 in December 1976. (!!> (message: =y) (c <== (message: (y * n))))))))))]) 29 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 30. Designing by Accident Gerry Sussman and I wanted to understand Carl Hewitt’s ideas, which seemed to have intellectual power, but we couldn’t get past the complexity and the notation to see “what was really going on.” So we decided to implement a “toy” actors language. We hoped that it could capture the essence of the ideas while remaining simple enough to understand. It might even turn into something useful. 30 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 31. Designing by Accident A Sequence of AI Languages at MIT LISP (McCarthy et al., 1958) METEOR (Bobrow, 1964) CONVERT (Guzman, 1969) PLANNER (Hewitt, 1969) MUDDLE (Sussman, Hewitt, et al., 1970) MICROPLANNER (Sussman et al., 1971) CONNIVER (Sussman et al., 1972) PLASMA (Hewitt et al., 1973) SCHEMER (Sussman and Steele, 1975) 31 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 32. Designing by Accident We decided to start with a small Lisp interpreter and then graft on exactly two more constructs: a way to make actors and a way to send messages. Gerry had been studying and teaching Algol 60, so we decided to use the full funarg solution so that our toy language would have lexical scope. Our intuition was that this would also keep track of actor’s acquaintances correctly. (Also inspired by Algol 60, the first toy interpreter was call-by-name rather than call-by-value! I will gloss over that distinction here.) 32 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 33. Designing by Accident For making an actor, we chose the syntax (alpha (parameters) body) It would be just like a lambda expression, but its body had to send a message rather than return a value. For sending messages, we considered (send actor argument ... argument) but then realized apply could tell actors from functions and so we could just use the same keyword-free syntax for calling functions and sending messages. 33 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 34. Designing by Accident We would also need some primitive actors. We decided on (among others): send product of m and n to actor k (* m n k) send difference of m and n to actor k (- m n k) (= m n k q) if m and n equal, send an empty message to actor k; otherwise send an empty message to actor q Note that these actors never return a value. They always send a message to another actor. 34 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 35. Designing by Accident We wanted to try out this definition of factorial: (define factorial (alpha (n c) (= n 0 (alpha () (c 1)) (alpha () (- n 1 (alpha (z) (factorial z (alpha (y) (* n y c))))))))) Note that this was not very different in structure from Carl’s, but somehow it was much less intimidating to us in the details. 35 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 36. Designing by Accident IMPORTANT DISCLAIMER The original Scheme interpreter was written in a very machine-language-like style of Lisp so as to expose every implementation detail. It was very much like Peter Landin’s SECD machine and did not take advantage of recursive function calls in the implementation language. Here I want to gloss over the implementation details so as not to obscure the main point of this talk. Therefore I am going to show you a simplified version of the interpreter, in the same style as the Lisp interpreter shown on earlier slides. 36 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 37. Designing by Accident A Scheme Evaluator (DEFINE EVAL (X ENV) (COND ((NUMBERP X) X) ((ATOM X) (LOOKUP X ENV)) ((EQ (FIRST X) (QUOTE QUOTE)) (SECOND X)) ((EQ (FIRST X) (QUOTE COND)) (EVCOND (REST X) ENV)) ((EQ (FIRST X) (QUOTE LAMBDA)) (LIST (QUOTE BETA) X ENV)) (T ((LAMBDA (EV) (APPLY (FIRST EV) (REST EV))) (EVLIS FORM ENV))))) 37 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 38. Designing by Accident Applying Functions (DEFINE APPLY (FN ARGS ENV) (COND ((NULL FN) (ERROR)) ((PRIMOP FN) (PRIMAPP FN ARGS)) ((EQ (FIRST FN) (QUOTE BETA)) (EVAL (THIRD (SECOND FN)) (BIND (SECOND (SECOND FN)) ARGS (THIRD FN)))) (T (ERROR)))) Everything else (LOOKUP, EVCOND, EVLIS, PRIMOP, PRIMAPP, BIND) is the same as before. 38 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 39. Designing by Accident Sending to Primitive Actors (1 of 2) (DEFINE PRIMSEND (ACTOR ARGS) (COND ((EQ ACTOR (QUOTE *)) (APPLY (THIRD ARGS) (LIST (TIMES (FIRST ARGS) (SECOND ARGS))))) ((EQ ACTOR (QUOTE -)) (APPLY (THIRD ARGS) (LIST (DIFFERENCE (FIRST ARGS) (SECOND ARGS))))) ... 39 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 40. Designing by Accident Sending to Primitive Actors (2 of 2) ... ((EQ ACTOR (QUOTE =)) (APPLY (COND ((EQUAL (FIRST ARGS) (SECOND ARGS)) (THIRD ARGS)) (T (FOURTH ARGS))) (QUOTE ()))) ... )) 40 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 41. Designing by Accident A Scheme Evaluator with Actors (DEFINE EVAL (X ENV) (COND ((NUMBERP X) X) ((ATOM X) (LOOKUP X ENV)) ((EQ (FIRST X) (QUOTE QUOTE)) (SECOND X)) ((EQ (FIRST X) (QUOTE COND)) (EVCOND (REST X) ENV)) ((EQ (FIRST X) (QUOTE LAMBDA)) (LIST (QUOTE BETA) X ENV)) ((EQ (FIRST X) (QUOTE ALPHA)) (LIST (QUOTE GAMMA) X ENV)) (T ((LAMBDA (EV) (APPLY (FIRST EV) (REST EV))) (EVLIS FORM ENV))))) 41 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 42. Designing by Accident Sending Messages to Actors (DEFINE APPLY (FA ARGS ENV) (COND ((NULL FA) (ERROR)) ((PRIMOP FA) (PRIMAPP FA ARGS)) ((PRIMACTOR FA) (PRIMSEND FA ARGS)) ... ((EQ (FIRST FA) (QUOTE GAMMA)) (EVAL (THIRD (SECOND FA)) (BIND (SECOND (SECOND FA)) ARGS (THIRD FA)))) (T (ERROR)))) 42 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 43. Designing by Accident Now evaluating the message send (factorial 5 fred) results in sending a message containing 120 to the actor named fred. Oh, joy! 43 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 44. Designing by Accident A Startling Equivalence (DEFINE APPLY (FA ARGS ENV) (COND ... ((EQ (FIRST FA) (QUOTE BETA)) (EVAL (THIRD (SECOND FA)) (BIND (SECOND (SECOND FA)) ARGS (THIRD FA)))) ((EQ (FIRST FA) (QUOTE GAMMA)) (EVAL (THIRD (SECOND FA)) (BIND (SECOND (SECOND FA)) ARGS (THIRD FA)))) (T (ERROR)))) 44 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 45. Designing by Accident An Astonishing Conclusion Actor constructors and lambda expressions in our toy language are operationally equivalent. Does it follow that actors are “merely” functions in a tail-recursive, lexically scoped language? They are the same mechanism. Any difference is not inherent, but depends only on what you put in their bodies. If your primitive operators are functions, you will tend to write programs in a functional style. If your primitive operators are actors, you will tend to write programs in an actor style. 45 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 46. Designing by Accident A New Language Is Born After some discussion, Carl Hewitt agreed with our conclusions (with two minor exceptions). In a way, this ended the “language competition.” Our great new AI language “Schemer” turned out to be a small dialect of Lisp with some nice properties. Oh, yes: the name? File names in that OS were limited to 6 characters. “SCHEME” 46 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 47. Designing by Accident Success I wrote a compiler for Scheme (called Rabbit). Soon, other people built much better implementations of Scheme. Lots of other people found it useful. The Scheme standard is in its sixth revision. Very few people bother to cite our papers anymore. We are delighted. 47 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 48. Designing by Accident Lessons • Exploration can be fruitful • Always be alert for simplifying insights > They are more plentiful than you think > But they are hard to plan for • Serendipity happens to those who are ready for it 48 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.
  • 49. Designing by Accident Luck favors the prepared. —Edna Mode 49 © 2006, 2007 Sun Microsystems, Inc. All rights reserved.