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

lol reddit

Name: Anonymous 2007-09-25 18:27 ID:hEE6B0ow

I was working my way through SICP last night when I came across a passage that at first struck me as curious, then interesting, then deeply interesting, and finally a little mind-blowing. Out of this little passage I got a little slice of enlightenment about first-order data, how Lisp can be rewritten in Lisp, domain-specific languages, how duck typing works, message-passing, and, finally, the clearest explanation and demonstration of a closed procedure that I have ever seen.

The passage addresses the question of complex data representations. If one establishes a satisfactory contract between the necessary constructor and selectors for a data representation, and if an implementation of that data representation can be shown to uphold that contract, then the details of the implementation don’t matter a bit.

That is certainly not controversial in the least. But Lisp’s treatment of procedures as first-class data allows for some surprising implementations. The particular items being re-implemented caught my attention too. Here is the code from the book, section 2.1.3:

(define (cons x y)
  (define (dispatch m)
    (cond ((= m 0) x)
            ((= m 1) y)
            (else (error "Argument not 0 or 1 -- CONS" m))))
  dispatch)

(define (car z) (z 0))

(define (cdr z) (z 1))

Yeah, that code re-implements cons, car, and cdr. And instead of returning a pair, this cons returns a procedure, named “dispatch” within the definition of cons. The name “dispatch” is just for our convenience. It could have just as easily been created as an anonymous procedure with (lambda ...).

A cons that doesn’t return a pair? How can that work? Well, what’s the contract that these procedures have to apply?

if (cons a b) => c
then (car c) => a
and (cdr c) => b

The re-implemented car and cdr take a procedure and apply it to a constant number, 0 or 1. If we define a variable c by passing a and b to cons, the procedure that has been labeled “dispatch” is what is returned for c. When we pass c to car and cdr, these call “dispatch” with a 0 or a 1, and that in turn returns a or b. The contract is upheld. It works.

What the book has to day about this:

    This may seem a curiosity now, but procedural representations of data will play a central role in our programming repertoire. This style of programming is often called message passing, and we will be using it as a basic tool in chapter 3 when we address the issues of modeling and simulation.

    – 2.1.3 What Is Meant by Data?

I have a few things to add.

   1. We can re-implement cons car and cdr in Scheme. Wow. It’s shocking to see a re-implementation of something so primitive to the language. But it drives home another point. As fundamental to Scheme as these procedures feel, they are still “only” abstractions.
   2. cons, car, and cdr are basic procedures that act on and build data. They are fundamental to Scheme’s recursive properties. If we can implement these easily in Scheme, it points to the possibility of creating all kinds of similar basic, fundamental abstractions and using them to construct all kinds of little languages. Here is the root of domain-specific languages.
   3. Talk about duck typing. The arguments passed to car and cdr don’t have to be lists or pairs. In fact, they could be any data type that upholds the contract. A lot has been written about design-by-contract. Here is an eloquent expression of it in a few lines of code. Scheme’s rules of rewriting make this possible. Scheme will substitute a process for a variable and evaluate it appropriately just as easily as it will substitute a list for the variable and proceed accordingly.
   4. “Message passing,” eh? That’s the basis of object-oriented programming, among other things, isn’t it?
   5. Finally, this is the best, clearest explanation and demonstration of a closure that I have ever seen! Where does the information passed to cons go? It essentially gets written into the dispatch procedure. And that procedure, first-class citizen of Scheme that it is, will wait until it is called, like a jack-in-the-box primed to pop up with our desired values. I really wasn’t expecting such an excellent example and explanation in one — I nearly tripped over it, like a snake in the grass.

Name: Anonymous 2007-09-25 18:29 ID:SQzH9TwU

Are you SUAVE?
 Are you a SPACE TOAD?
 Are you a SUAVE SPACE TOAD?
 
 If you answered "Yes" to all of the above questions, then SICP (STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS) might be exactly what you've been looking for!  Read SICP (STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS) today, and enjoy all the benefits of being a satorized SICP reader.  SICP (STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS) is the fastest-growing SMUG LISP WEENIE community with THOUSANDS of members all over the Internet! You, too, can be a part of SICP if you join today!  Why not? It's quick and easy - only 3 simple steps!
     * First, you have to obtain a copy of SICP and read it. You can read it online using your favorite web browser.
     * Second, you need to succeed in founding a Lisp-related meme in /prog/ on world4chan, a popular "programming for trolls" website.
     * Third, you need to join the official SICP home /prog/ on world4chan, and apply for membership.
 Talk to one of the satorized overlords or any of the other members in the board to sign up today! Upon submitting your application, you will be required to submit links to your successful meme, and you will be tested on your knowledge of STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS.  If you are having trouble locating /prog/, the official STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS board, you might be on a wrong web sight. The correct address is http://dis.4chan.org/prog/. Follow this link if you are using a http client such as telnet.  If you have Sussman points and would like to support SICP, please don't sage this post.

                        //`'''```,
              o        //SICP   `.,
        ,....OOo.   .c;.',,,.'``.,,.`
     .'      ____.,'.//
    / _____  \___/.'
   | / ||  \\---\|
   ||  ||   \\  ||
   co  co    co co

Name: Anonymous 2009-03-06 8:01

read the rest but   the whole way.

Name: Anonymous 2011-02-03 8:15

Name: Anonymous 2011-02-04 16:14

Name: Anonymous 2012-06-25 22:53

砳禃瘑€炅䑵ħ畔扇␵杴蒑䡗ᖆ鐴嘆垈入䌥䊓舢₅酱✨圩ܙ蝆ֆ噓䐃呑襲ޙ砃ĥ褃ᅆ冓祰䄆䢂钂衔捄脃襗ᜤ鞕⥣♑С⑶奖眙灂爘犅即鉦ᝈই❂皈栲砶儩碔㑘悖⌨卹ᠲ锂␇䌅虉甇瘴衁邁ȣ̖ᑱ蜡楡㝰獣遶捆掕ࠀ獹傆褁霙啃椘险腈琘܅爩ᤒv艕餹蜔䈓呠茢⌸靹㝨⥙㢙衧ᝐ䑧襒┡儉Р鍉扅琥硔ㄴ针攙㙩䆐塨䌸瑩匤␗䥓蝄掔⍣禐Ƃ䊃睅ٰ捩㐰萘頳睩⅒⦄锃怉䥠扅瑗卐攤㊔⥸獴㒅儦疄Ֆ瘃衹牣䅤薒㘡⑰ ⌔瘀㉆镴匕陉猘ц钘̵䐈፴莖払蚈銈灲䒂⡅ɥ昴攖➆ܱ脢堡᜸噥㙲㔔舱灤噒ᒃaᔷ疃Յ吕愣✴鐄ɐ♉╄Ⅶ兔攁ܥ餂陑失❇耕偐ɡ閉⤷႖䑙朆商☨偢瀘校隈⠑⑑蜥㐰ř䄓鈱䜰㥦䊙┸攅䀠頨蒙蔴㆑萲玀хݤᕴㅥ㎘椄ᢗ坕坕芒嚘假蝨睷敧蜒鄉┨鄸耖煗㐡焉䊂ㅀ᠑撑့ᦐᡰ㐦靷啧饦霔㡨䦓䠂剸⡉

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