DOC PREVIEW
Berkeley COMPSCI 61A - Lecture 28

This preview shows page 1-2-3-4 out of 13 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

61A Lecture 28Friday, November 4Friday, November 4, 2011The Logo Programming LanguageA teaching language: designed for introductory programmingOne syntactic form for all purposes: invoking a procedureOnly two data types: words and sentencesCode is data: a line of code is a sentenceAn elegant tagline: no threshold, no ceilingA bit of fun: turtle graphics2DemoFriday, November 4, 2011http://imgs.xkcd.com/comics/lisp_cycles.pngLogo is a Dialect of LispWhat are people saying about Lisp?•"The greatest single programming language ever designed." -Alan Kay (from the UI video), co-inventor of Smalltalk•"The only computer language that is beautiful." -Neal Stephenson, John's favorite sci-fi author•"God's programming language." -Brian Harvey, Father of CS 61A3Friday, November 4, 2011Logo FundamentalsCall expressions are delimited by spacesLogo procedures are equivalent to Python functions•A procedure takes inputs (arguments) that are values•A procedure returns an output (return value)•A procedure may output None to indicate no return value4? print 55Multiple expressions can appear in a single line? print 1 print 212Friday, November 4, 2011Nested Call ExpressionsThe syntactic structure of expressions is determined by the number of arguments required by named procedures5? print sum 10 difference 7 314print takes one argument (input)sum takes two inputsdifference takes two inputs tooOne nested call expressionversusTwo expressions on one line? print 1 print 212DemoFriday, November 4, 2011Data Types and QuotationWords are strings without spaces, representing text, numbers, and boolean values6? print "hellohello? print "sumsum? print "22Sentences are immutable sequences of words and sentences? print [hello world]hello world? show [hello world][hello world]Friday, November 4, 2011Sentence (List) Processing in LogoSentences can be constructed from words or sentences7Procedure Effectsentence Output a sentence containing all elements of two sentences. Input words are converted to sentences.list Output a sentence containing the two inputs.fput Output a sentence containing the first input and all elements in the second input.DemoFriday, November 4, 2011Expressions are SentencesThe run procedure evaluates a sentence as a line of Logo code and outputs its value8? run [print sum 1 2]3? run sentence "print [sum 1 2]3? print run sentence "sum sentence 10 run [difference 7 3]14Its argument can be constructed from other procedure calls4[10 4]14Friday, November 4, 2011ProceduresProcedure definition is a special form, not a call expression9? to double :x> output sum :x :x> end? print double 48Procedure name Formal parameterBodyProcedures are not first-class objects in Logo; they can only ever be referenced by their original procedure nameProcedure names can be inputs or outputsFriday, November 4, 2011Conditional ProceduresIf and ifelse are regular procedures in LogoMeaning: They do not have a special evaluation procedureThey take sentences as inputs and run them conditionally10? to reciprocal :x> if not :x = 0 [output 1 / :x]> output "infinity> end? print reciprocal 20.5? print reciprocal 0infinityFriday, November 4, 2011Dynamic ScopeWhen one function calls another, the names bound in the local frame for the first are accessible to the body of the secondNo isolation of formal parameters to function bodies, as we saw with lexical scope11? to print_x :x> print_last_x> end? to print_last_x> print :x> end? print_x 55Friday, November 4, 2011Logo ExamplesDemo12Friday, November 4, 2011Decoding a sequence of bits:Homework: Huffman Encoding TreesEfficient encoding of strings as ones and zeros (bits).13 A 0 C 1010 E 1100 G 1110 B 100 D 1011 F 1101 H 1111ABC DE F G H0 10 10 10 10 10 1 0 11 0 0 0 1 0 1 0B A CFriday, November 4,


View Full Document

Berkeley COMPSCI 61A - Lecture 28

Documents in this Course
Lecture 1

Lecture 1

68 pages

Midterm

Midterm

5 pages

Midterm

Midterm

6 pages

Lecture 35

Lecture 35

250 pages

Lecture 14

Lecture 14

125 pages

Lecture 2

Lecture 2

159 pages

Lecture 6

Lecture 6

113 pages

Lecture 3

Lecture 3

162 pages

Homework

Homework

25 pages

Lecture 13

Lecture 13

117 pages

Lecture 29

Lecture 29

104 pages

Lecture 11

Lecture 11

173 pages

Lecture 7

Lecture 7

104 pages

Midterm

Midterm

6 pages

Midterm

Midterm

6 pages

Lecture 8

Lecture 8

108 pages

Lab 4

Lab 4

4 pages

Lecture 7

Lecture 7

52 pages

Lecture 20

Lecture 20

129 pages

Lecture 15

Lecture 15

132 pages

Lecture 9

Lecture 9

95 pages

Lecture 30

Lecture 30

108 pages

Lecture 17

Lecture 17

106 pages

Load more
Download Lecture 28
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 28 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 28 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?