UVA CS 150 - Lecture 3: Rules of Evaluation

Unformatted text preview:

1David Evanshttp://www.cs.virginia.edu/evansCS150: Computer ScienceUniversity of VirginiaComputer ScienceLecture 3: Rules of Evaluation2CS150 Fall 2005: Lecture 3: Rules of EvaluationMenu• Language Elements• Why don’t we just program computers using English?• Evaluation• Procedures3CS150 Fall 2005: Lecture 3: Rules of EvaluationAre there any non-recursive natural languages? What would happen to a society that spoke one? Not for humans at least. They would run out of original things to say.Chimps and Dolphins are able to learn non-recursive “languages” (some linguists argue they are not really “languages”), but only humans can learn recursive languages.4CS150 Fall 2005: Lecture 3: Rules of EvaluationRunning out of Ideas“Its all been said before.”Eventually true for a non-recursive language.Never true for a recursive language. There is always something original left to say! 5CS150 Fall 2005: Lecture 3: Rules of EvaluationLanguage ElementsWhen learning a foreign language, which elements are hardest to learn?• Primitives: lots of them, and hard to learn real meaning• Means of Combination– Complex, but, all natural languages have similar ones [Chomsky]SOV (45% of all languages) Sentence ::=Subject Object Verb (Korean)SVO (42%) Sentence::= Subject Verb Object VSO (9%)Sentence ::= Verb Subject Object (Welsh)“Lladdodd y ddraig y dyn.” (Killed the dragon the man.)OSV (<1%): Tobati (New Guinea)Schemish: Expression::= (Verb Object)• Means of Abstraction: few of these, but tricky to learn differences across languagesEnglish: I, weTok Pisin (Papua New Guinea): mi (I), mitupela (he/she and I), mitripela(both of them and I), mipela (all of them and I), yumitupela (you and I), yumitripela (both of you and I), yumipela (all of you and I)9CS150 Fall 2005: Lecture 3: Rules of EvaluationDeclarations, ClassesExpressions, StatementsProgram Structure Standard ProceduresPrimitive expressionsIdentifiers, numerals DefinitionsExpressionsProgram structureStandard ProceduresPrimitive expressionsIdentifiers, numerals776 pages total (includes no formal specification or examples)48 pages total (includes formal specification and examples)173½Means of Abstraction1973522Means of Combination356 301018 21PrimitivesPages in C++ Language Specification (1998)Pages in Revised5Report on the Algorithmic Language SchemeC++ Core language issues list has 529 items!210CS150 Fall 2005: Lecture 3: Rules of EvaluationPronounsGrammar RulesEnglish Grammar for DummiesBookMorphemesWords in Oxford English DictionaryDefinitionsExpressionsProgram structureStandard ProceduresPrimitive expressionsIdentifiers, numerals48 pages total (includes formal specification and examples)~20½Means of Abstraction100s (?)384 pages22Means of Combination?500,000 18 21PrimitivesEnglishPages in Revised5Report on the Algorithmic Language Scheme12CS150 Fall 2005: Lecture 3: Rules of EvaluationWhy don’t we just program computers using English?• Too hard and complexNon-native English speakers don’t need convincing. The rest of you have spent your whole life learning English (and first 5 years of your life doing little else) and still don’t know useful words like floccipoccinihilipilification! There are thoughts that even native speakers find it hard to express.By the end of today you will know enough Scheme (nearly the entire language) to express and understand everycomputation. By PS7, you will know enough to completely and precisely describe Scheme in terms of itself (try doing that in English!)13CS150 Fall 2005: Lecture 3: Rules of EvaluationWhy don’t we just program computers using English?• Not concise enoughEnglish:To find the maximum of two numbers, compare them. If the first number is greater than the second number, the maximum is the first number. Otherwise, the maximum is the second number.Scheme:(define (max a b) (if (> a b) a b))14CS150 Fall 2005: Lecture 3: Rules of EvaluationWhy don’t we just program computers using English?• Limited means of abstractionThere are only a few pronouns: he, she, it, they, these, …(English doesn’t even have a gender-neutral pronoun for a person!)Only Webster and Oxford can make up new ones.define allows any programmer to make up as many pronouns as she wants, and use them to represent anything.15CS150 Fall 2005: Lecture 3: Rules of EvaluationWhy don’t we just program computers using English?• Mapping between surface forms and meanings are ambiguous and impreciseWould you rather be paid biweekly or every week?The exact meaning(s) of every Scheme expression is determined by simple, unambiguous rules we will learn today (and refine later in the course).16CS150 Fall 2005: Lecture 3: Rules of EvaluationEssential Scheme Expression ::= (Expression1Expression*)Expression ::= (ifExpression1Expression2Expression3 )Expression ::= (definename Expression)Expression ::=PrimitivePrimitive ::= numberPrimitive ::= + | - | * | …Primitive ::= …Grammar is clear, justfollow the replacementrules. But what does itall mean?3Evaluation18CS150 Fall 2005: Lecture 3: Rules of EvaluationExpressions and Values• (Almost) every expressionhas a value – Have you seen any expressions that don’t have values?• When an expression with a value is evaluated, its value is produced19CS150 Fall 2005: Lecture 3: Rules of EvaluationEvaluation Rule 1: PrimitivesIf the expression is a primitive, it is self-evaluating.> 22> #t#t> +#<primitive:+>20CS150 Fall 2005: Lecture 3: Rules of EvaluationEvaluation Rule 2: NamesIf the expression is a name, it evaluates to the value associated with that name.> (define two 2)> two221CS150 Fall 2005: Lecture 3: Rules of EvaluationEvaluation Rule 3: Application3. If the expression is an application:a) Evaluate all the subexpressions of the combination (in any order)b) Apply the value of the first subexpression to the values of all the other subexpressions.(expression0expression1expression2… )22CS150 Fall 2005: Lecture 3: Rules of EvaluationRules for Application1. If the procedure to apply is a primitive, just do it.2. If the procedure is a compound procedure, evaluate the body of the procedure with each formal parameter replaced by the corresponding actual argument expression value.423CS150 Fall 2005: Lecture 3: Rules of EvaluationMaking Procedures• lambda means “make a procedure”Expression::= (lambda (Parameters)Expression)Parameters::= Parameters::= Name Parameters24CS150 Fall 2005: Lecture 3: Rules of EvaluationLambda Example:


View Full Document

UVA CS 150 - Lecture 3: Rules of Evaluation

Documents in this Course
Objects

Objects

6 pages

Load more
Download Lecture 3: Rules of Evaluation
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 3: Rules of Evaluation 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 3: Rules of Evaluation 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?