There are no reviews yet. Be the first to send feedback to the community and the maintainers!
This repository contains all the code examples from the book "The Little Schemer." The code in this book is presented in a subset version of the Scheme programming language. The book is a dialogue between you and the authors about interesting examples of Scheme programs and it teaches you to think recursively. If you're interested, get the book from Amazon: http://bit.ly/4GjWdP The code examples were copied (and completed where necessary) from "The Little Schemer" by Peteris Krumins ([email protected]). His blog is at http://www.catonmat.net -- good coders code, great reuse. ------------------------------------------------------------------------------ Table of contents: [01] Chapter 1: Toys 01-toys.ss [02] Chapter 2: Do It, Do It Again, and Again, and Again... 02-do-it-again.ss [03] Chapter 3: Cons the Magnificent 03-cons-the-magnificent.ss [04] Chapter 4: Numbers Games 04-numbers-games.ss [05] Chapter 5: *Oh My Gawd*: It's Full of Stars 05-full-of-stars.ss [06] Chapter 6: Shadows 06-shadows.ss [07] Chapter 7: Shadows 07-friends-and-relations.ss [08] Chapter 8: Lambda the Ultimate 08-lambda-the-ultimate.ss [09] Chapter 9: ... and Again, and Again, and Again ... 09-and-again.ss [10] Chapter 10: What Is the Value of All of This? 10-value-of-all-of-this.ss [01]-Chapter-1-Toys----------------------------------------------------------- See 01-toys.ss file for code examples. Chapter 1 introduces language primitives, operations and tests on them. The primitives include: atoms, lists and s-expressions. Operations include: car, cdr, cons. Tests include: null?, atom?, eq?. It also defines five rules on using car, cdr, cons, null? and eq?. The law of car: The primitive car is defined only for non-empty lists. The law of cdr: The primitive cdr is defined only for non-empty lists. The cdr of any non-empty list is always another list. The law of cons: The primitive cons takes two arguments. The second argument to cons must be a list. The result is a list. The law of null?: The primitive null? is defined only for lists. The law of eq?: The primitive eq? takes two arguments. Each must be a non-numeric atom. .----------------------------------------------------------------------------. | | | This space reserved for | | JELLY STAINS! | | | '----------------------------------------------------------------------------' [02]-Chapter-2-Do-It-Do-It-Again-and-Again-and-Again-------------------------- See 02-do-it-again.ss file for code examples. Chapter 2 introduces two recursive functions and steps through them again, and again, and again until you understand recursion. The first function introduced is lat? that tests if the given list consists only of atoms (lat stands for list of atoms). The second function introduced is member? that tests if an element is in a lat. It also defines a preliminary version of the first commandment that always should be followed when programming recursively. .----------------------------------------------------------------------------. | The first commandment: (preliminary version) | | | | Always ask null? as the first question in expressing any function. | '----------------------------------------------------------------------------' [03]-Chapter-3-Cons-the-Magnificent------------------------------------------- See 03-cons-the-magnificent.ss file for code examples. Chapter 3 explains how to build lists with cons. It's done via showing how to write a function that removes an element from the list. Then the second commandment is presented. .----------------------------------------------------------------------------. | The second commandment: | | | | Use cons to build lists. | '----------------------------------------------------------------------------' Next, it's precisely explained how to do recursion and when to stop recursing, this leads to the third commandment and a preliminary version of the fourth commandment. The examples include a function that inserts an element in a list to the right and to the left of the given element, and a function that removes the first occurrence of an element from a list. .----------------------------------------------------------------------------. | The third commandment: | | | | When building lists, describe the first typical element, and then cons it | | onto the natural recursion. | '----------------------------------------------------------------------------' Next the multi-versions of the same functions are written that insert element to the right and to the left of all occurrences of the given element in a list, and a function that removes all occurrences of an element from a list. .----------------------------------------------------------------------------. | The fourth commandment: (preliminary version) | | | | Always change at least one argument while recurring. It must be changed to | | be closer to termination. The changing argument must be tested in the | | termination condition: when using cdr, test the termination with null?. | '----------------------------------------------------------------------------' [04]-Chapter-4-Numbers-Games-------------------------------------------------- See 04-numbers-games.ss file for code examples. Chapter 4 builds the arithmetic system from the primitives add1 and sub1. Using add1 the usual + addition operation on two numbers is developed, next using sub1 the usual - subtraction operation is developed, then multiplication and exponentiation are written. Along the way the first and fourth commandments are revisited: .----------------------------------------------------------------------------. | The first commandment (first revision) | | | | When recurring on a list of atoms, lat, ask two questions about it: | | (null? lat) and else. | | When recurring on a number, n, ask two questions about it: (zero? n) and | | else. | '----------------------------------------------------------------------------' .----------------------------------------------------------------------------. | The fourth commandment (first revision) | | | | Always change at least one argument while recurring. It must be changed to | | be closer to termination. The changing argument must be tested in the | | termination condition: | | when using cdr, test the termination with null? and | | when using sub1, test termination with zero?. | '----------------------------------------------------------------------------' And the fifth commandment is postulated: .----------------------------------------------------------------------------. | The fifth commandment | | | | When building a value with o+, always use 0 for the value of the | | terminating line, for adding 0 does not change the value of an addition. | | | | When building a value with o*, always use 1 for the value of the | | terminating line, for multiplying by 1 does not change the value of a | | multiplication. | | | | When building a value with cons, always consider () for the value of the | | terminating line. | '----------------------------------------------------------------------------' Next the < greater than and > less than operations are derived, then the = equals operation and quotient operation. Then various utility functions are written, such as length that determines the length of a list, pick that picks the n-th element from the list, rempick that removes the n-th element from the list, no-nums that extracts all non-numeric elements from the list, all-nums that does the opposite and extracts all numeric elements from the list. [05]-Chapter-5-Oh-My-Gawd-It's-Full-of-Stars---------------------------------- See 05-full-of-stars.ss file for code examples. Chapter 5 introduces you to S-expressions and functions that manipulate them. The first commandment is finalized: .----------------------------------------------------------------------------. | The first commandment (final version) | | | | When recurring on a list of atoms, lat, ask two questions about it: | | (null? lat) and else. | | When recurring on a number, n, ask two questions about it: (zero? n) and | | else. | | When recurring on a list of S-expressions, l, ask three questions about | | it: (null? l), (atom? (car l)), and else. | '----------------------------------------------------------------------------' And the fourth commandment is stated: .----------------------------------------------------------------------------. | The fourth commandment (final version) | | | | Always change at least one argument while recurring. When recurring on a | | list of atoms, lat, use (cdr l). When recurring on a number, n, use | | (sub1 n). And when recurring on a list of S-expressions, l, use (car l) | | and (cdr l) if neither (null? l) nor (atom? (car l)) are true. | | | | It must be changed to be closer to termination. The changing argument must | | be tested in the termination condition: | | * when using cdr, test the termination with null? and | | * when using sub1, test termination with zero?. | '----------------------------------------------------------------------------' Functions rember, insertR, insertL, occur, subst, member are then rewritten to manipulate S-expressions and not just lists of atoms. Then functions for comparing two S-expressions are written, and rewritten several times to teach you Scheme for great good. Finally the sixth commandment is presented: .----------------------------------------------------------------------------. | The sixth commandment | | | | Simplify only after the function is correct. | '----------------------------------------------------------------------------' [06]-Chapter-6-Shadows-------------------------------------------------------- See 06-shadows.ss file for code examples. Chapter 6 develops an evaluator for simple arithmetic expressions involving only +, * and exp. The seventh commandment is formulated as evaluator is developed: .----------------------------------------------------------------------------. | The seventh commandment | | | | Recur on the subparts that are of the same nature: | | * On the sublists of a list. | | * On the subexpressions of an arithmetic expression. | '----------------------------------------------------------------------------' Next different representations for arithmetic expressions are introduced. An expression (1 + 2) can be written as (+ 1 2) and (1 2 +) or even (plus 1 2). The concept of abstraction from representations is introduced. The eighth commandment follows: .----------------------------------------------------------------------------. | The eighth commandment | | | | Use help functions to abstract from representations. | '----------------------------------------------------------------------------' Finally chapter shows how numbers 0, 1, 2, ... can be represented purely as lists. The number 0 becomes (), number 1 becomes (()), 2 becomes (() ()), 3 becomes (() () ()), ... . Then functions for adding, subtracting and checking if the new number is zero are written. But beware of shadows, the lat? function doesn't work on a list of these numbers. [07]-Chapter-7-Friends-and-Relations------------------------------------------ See 07-friends-and-relations.ss file for code examples. Chapter 7 is all about sets. It defines functions to test if the given list is a set, to construct a set from a list, to test if set1 is a subset of set2, to determine if two sets are equal, to find intersect of two sets, to fund intersect of a bunch of sets, to find union of two sets. Then it introduces pairs and writes several helper functions: first that returns the first element of a pair, second that returns the second element of a pair, and build that builds a pair. (Remember commandment eight.) Then it plays with mathematical functions. It introduces relations, creates functions to reverse relations, and test if the given list of relations is a function and is it a full function. [08]-Chapter-8-Lambda-the-Ultimate-------------------------------------------- See 08-lambda-the-ultimate.ss file for code examples. Chapter 8 introduces the concept that functions can be passed and returned from functions. It also introduces currying. Next it reviews several functions from Chapter 3 and shows how they differ only by two lines. Those lines can be factored out as separate functions that simplifies the whole thing. The ninth commandment follows. .----------------------------------------------------------------------------. | The ninth commandment | | | | Abstract common patterns with a new function. | '----------------------------------------------------------------------------' Finally continuations are introduced via a bunch of examples, for example, multirember&co function collects the elements to be removed in one list, and the elements that were not removed in the other. After it's done, the collector is called, which is your own function so you may do anything you wish with those two lists. The final, tenth commandment, is stated. .----------------------------------------------------------------------------. | The tenth commandment | | | | Build functions to collect more than one value at a time. | '----------------------------------------------------------------------------' And remember, an apple a day keeps the doctor away. [09]-Chapter-9-and-Again-and-Again-and-Again---------------------------------- See 09-and-again.ss file for code examples. ... Used this chapter to write an article on derivation of Y-Combinator: http://www.catonmat.net/blog/derivation-of-ycombinator/ ... [10]-Chapter-10-What-Is-the-Value-of-All-of-This------------------------------ See 10-value-of-all-of-this.ss file for code examples. Chapter 10 implements Scheme in Scheme. That's it. It was a great adventure and now it's time for banquet! ------------------------------------------------------------------------------ That's it. I hope you find these examples useful when reading "The Little Schemer" yourself! Go get it at http://bit.ly/4GjWdP, if you haven't already! Sincerely, Peteris Krumins http://www.catonmat.net
node-lazy
lazy lists for node.jsnodejs-proxy
A HTTP proxy server written in node.jsnode-tree-kill
kill trees of processesbash-redirections-cheat-sheet
Bash redirections cheat sheetperl1line.txt
collection of handy perl one-liner scriptsxgoogle
Python library to Google services (google search, google sets, google translate, sponsored links)node-gif
A node.js C++ module for creating GIF images and animated GIFs from RGB or RGBA buffers.node-video
A node.js module for streaming and recording HTML5 Theora videosnode-png
A nodejs C++ module that given a buffer with RGB or RGBA values creates a PNG image (in memory).stackvm
Configure, network, and interact with virtual machines entirely over the webhacker-top
A top-like program for monitoring hacker news from the consolenode-iptables
basic iptables control via nodejsnode-image
Unifies node-png, node-jpeg and node-gif (for great good)the-seasoned-schemer
All the Scheme code examples from the book "The Seasoned Schemer"bash-vi-editing-mode-cheat-sheet
Bash has two input modes - emacs and vi. This is vi input/editing mode keyboard shortcut cheat sheet.the-little-mler
All the ML code examples from the book "The Little MLer"awk-cheat-sheet
This is AWK programming language cheat sheet.bithacks.h
bithacks.h is a C header file containing useful bit manipulation macrosnode-jpeg
A nodejs C++ module that given a buffer with RGB or RGBA values creates a JPEG image in memory.node-base64
A base64 encoding and decoding C++ module for node.js that actually works! (node now has it's own base64 encoding, see docs!)perl-tcp-proxy
A simple TCP proxy written in Perl. Uses IO::Socket::INET and IO::Select for multiplexing.node-jsmin
javascript minimizer for node.jsreddit-top
A top-like program for monitoring reddit from the consolebash-history-cheat-sheet
This is the bash history cheat sheet. It summarizes everything there is to know about working efficiently with command line history in bash.the-reasoned-schemer
All the logic programming code examples from the book "The Reasoned Schemer"catonmat.net
The new catonmat.net website.node-browser
Provides a Browser for easy web browsing from node.jssed-cheat-sheet
This is sed (unix stream editor) cheat sheet.node-supermarket
A key/value store based on sqlite for node.js that actually works.screen-cheat-sheet
This is the screen terminal emulator cheat sheet. It lists the default keyboard shortcuts for working with screen.bash-emacs-editing-mode-cheat-sheet
Bash has two input modes - emacs and vi. This is emacs input/editing mode keyboard shortcut cheat sheet.set-operations-in-unix-shell
This is an implementation of 14 set operations by using only Unix utilities such as sort, uniq, diff, comm, cat, head, tail, awk, and others.social-scraper
Social scraper is a Perl program that scrapes reddit, digg, stumbleupon, delicious, furl, flickr, simpy, boingboing, wired for content that matches the given patterns.node-async
An example async library for node.jsbash-one-liners
Bash one-linersperl-tcp-proxy2
Program for my "A TCP Proxy in Perl" articlethe-little-prover
All code examples from "The Little Prover" bookadns
Asynchronous DNS resultion in Python by using adns C library.busy-beaver
Implementation of a Turing Machine that runs the Busy Beaver programs.social-submitter
Submit your stories to Reddit, Hacker News, Twitter, Plurk, Identi.ca, Facebook at once!youtube-uploader
A Perl program that uploads videos to YouTube without any APIs.invoice
generate pdf invoices from latex via pdflatexnode-passwd
Node.js module to manage /etc/passwdgnu-awk-youtube-downloader
A program written in GNU Awk that downloads YouTube Videos. Proof of concept that AWK can do binary IO and networking effectively.ed-cheat-sheet
This is ed (the unix text editor) cheat sheet. It lists all the commands and how to do line addressing.gnu-coreutils-cheat-sheet
Gnu Coreutils Cheat Sheetload-status-server
Windows load status server that returns cpu load, memory usage and disk usage through JSONutil-linux-cheat-sheet
Util-Linux Cheat Sheetnode-chess
Node chess - Node.js knockout competitionssh-key-manager
manage ssh keys on the server side (can be used with ssh-key-widget)node-des
A C++ node.js module that does DES encryption and actually works (node's crypto module didn't work.)node-rfb
implements the client-side of the rfb protocol that vnc usesperl-youtube-downloader-one-liner
This is a Perl one-liner that downloads YouTube videos.node-bufferdiff
A C++ module for node-js to test if two buffers are equal, fast (could add diff later).vbscript-youtube-downloader
A program written in VBScript that downloads YouTube videos.supermarket-cart
Connect session store using supermarketkeyboard
provides english keyboard (used as a widget for browserling)speak-text-files-to-wav
Speaks text files to wav using Microsoft Speech APIperl-predefined-variable-cheat-sheet
This is Perl special variable (predefined variable) cheat sheet. It lists all the Perl variables.dnode
Simple asynchronous remote method invocation for node.jsnode-time
This module provides some time functions for node.js (i forgot about Date() so this module is useless)reddit-comment-finder
A program that finds all the comments a given reddit user has made.dotfiles
bitly
shorten urls with bitly without apinode-quine
A node.js module that exports a function that prints itselffirefox-update-dialog-killer
a simple win32 program that detects and closes the firefox update dialognode-number-range
number rangesnode-png-sync
sync part of node-png that works on windows with node-gyp on node 0.6youtube-video-downloader-in-perl
Wrote this real quick as I needed to get some vidschrome-dialog-killer
Kills the nasty "your profile can not be used because it is from a newer version of Google Chrome" dialog by clicking OK buttonhwnd-finder
find hwnds easilyrfb-protocols
A node.js module for various RFB encoding (RRE, Hextile, Tight, etc.) conversion to RGB buffers.TextToWav
Converts text files to wav using Loquendo text-to-speech sdkperl-pack-unpack-printf-sprintf-cheat-sheet
This is Perl pack/unpack template parameter and printf/sprintf format specifier cheat sheetquick-cd
Quick cd is a utility for bash that keeps track of your most often used directories and allows you to cd to them with as few keystrokes as possible.feedburner-graph-generator
Current feedburner graphs suck. I wrote this Perl program to generate the nice graphs they used to have in 2008.install-computer
plurk-command-line-plurker
A Perl program for plurking from command linenode-bufferlist
Create linked lists of Buffer objectswebdev-template
Web development template with reset.cssreddit-river
The old reddit river website for mobile deviceshttp-async-retry
HTTP::Async with retryquick-history
Better interface to bash's (and other shell) CTRL+R for reverse-search-historydockerfiles
node-parse-users-exe-output
parses output from users.exe on windowsrackspace-tools
some tools to manage rackspace cloud serverscodinghorror-keyword-analyzer
A Perl program that parses public statcounter data for codinghorror.com blog and stores the search keywords in an SQLite database.node-rdesktop
Client side of the RDP protocol that Windows uses for remote deskopnode-crashing-async-buf
for ry - a crashing Buffer::New example in eio_custom.stacked-linux
A small linux distribution for use on routersutf8-length
return the number of bytes in a unicode stringlulzbot
An IRC bot for node.jslatex2html
convert latex to html (works for me)utf8-bytes
return an array of bytes from a unicode stringlwp-protocol-http-socketeer
http protocol implementation for LWP that uses a proxystartupsupper.github.com
Recipes for Bootstrappers & Hungry Hackerstestling-ci-badge-checker
This perl program checks github repos for testling-ci badgestestling-ci-test-example
testling-ci-test-examplepicurls.com
This is repository of picurls.com website. picurls: picture buzz! buzziest pictures on the net!digpicz
The old digpicz.com websiteLove Open Source and this site? Check out how you can help us