Artificial Intelligence Computers that think? Artificial Intelligence Computers that think?
ARTIFICIAL INTELLIGENCE LANGUAGES · Artificial Intelligence Languages Subject 1.Subject...
Transcript of ARTIFICIAL INTELLIGENCE LANGUAGES · Artificial Intelligence Languages Subject 1.Subject...
ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE
CÓRDOBA UNIVERSITYCÓRDOBA UNIVERSITYCÓRDOBA UNIVERSITYCÓRDOBA UNIVERSITY
SUPERIOR POLYTECHNIC SCHOOLSUPERIOR POLYTECHNIC SCHOOLSUPERIOR POLYTECHNIC SCHOOLSUPERIOR POLYTECHNIC SCHOOL
DEPARTMENT OFDEPARTMENT OFDEPARTMENT OFDEPARTMENT OFCOMPUTER SCIENCE AND NUMERICAL ANALYSIS COMPUTER SCIENCE AND NUMERICAL ANALYSIS COMPUTER SCIENCE AND NUMERICAL ANALYSIS COMPUTER SCIENCE AND NUMERICAL ANALYSIS
LANGUAGESLANGUAGESLANGUAGESLANGUAGESLANGUAGESLANGUAGESLANGUAGESLANGUAGESTECHNICAL ENGINEERING IN MANAGEMENT COMPUTER SCIENCETECHNICAL ENGINEERING IN MANAGEMENT COMPUTER SCIENCETECHNICAL ENGINEERING IN MANAGEMENT COMPUTER SCIENCETECHNICAL ENGINEERING IN MANAGEMENT COMPUTER SCIENCE
TECHNICAL ENGINEERING IN SYSTEMS COMPUTER SCIENCETECHNICAL ENGINEERING IN SYSTEMS COMPUTER SCIENCETECHNICAL ENGINEERING IN SYSTEMS COMPUTER SCIENCETECHNICAL ENGINEERING IN SYSTEMS COMPUTER SCIENCE
SECOND YEARSECOND YEARSECOND YEARSECOND YEAR
FIRST FOURFIRST FOURFIRST FOURFIRST FOUR----MONTH PERIODMONTH PERIODMONTH PERIODMONTH PERIOD
ARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGES PROGRAMPROGRAMPROGRAMPROGRAMPROGRAMPROGRAMPROGRAMPROGRAM
FirstFirstFirstFirst part: part: part: part: SchemeSchemeSchemeScheme
Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Subject 2.Subject 2.Subject 2.Subject 2.---- Expressions and FunctionsExpressions and FunctionsExpressions and FunctionsExpressions and Functions
Subject 3.Subject 3.Subject 3.Subject 3.---- Conditional Predicates and SentencesConditional Predicates and SentencesConditional Predicates and SentencesConditional Predicates and Sentences
Subject 4.Subject 4.Subject 4.Subject 4.---- Iteration and RecursionIteration and RecursionIteration and RecursionIteration and Recursion
Subject 5.Subject 5.Subject 5.Subject 5.---- Compound Data Types Compound Data Types Compound Data Types Compound Data Types
Subject 6.Subject 6.Subject 6.Subject 6.---- Data Abstraction Data Abstraction Data Abstraction Data Abstraction
2
Second part: Second part: Second part: Second part: PrologPrologPrologProlog
Subject 6.Subject 6.Subject 6.Subject 6.---- Data Abstraction Data Abstraction Data Abstraction Data Abstraction
Subject 7.Subject 7.Subject 7.Subject 7.---- Reading and WritingReading and WritingReading and WritingReading and Writing
Subject 8.Subject 8.Subject 8.Subject 8.---- IntroductionIntroductionIntroductionIntroduction totototo Prolog languageProlog languageProlog languageProlog language
Subject 9.Subject 9.Subject 9.Subject 9.---- Basic Elements of PrologBasic Elements of PrologBasic Elements of PrologBasic Elements of Prolog
Subject 10.Subject 10.Subject 10.Subject 10.---- ListsListsListsLists
Subject 11.Subject 11.Subject 11.Subject 11.---- ReReReRe----evaluation and the “cut” evaluation and the “cut” evaluation and the “cut” evaluation and the “cut”
Subject 12.Subject 12.Subject 12.Subject 12.---- Input and OutputInput and OutputInput and OutputInput and Output
ARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGESARTIFICIAL INTELLIGENCE LANGUAGES PROGRAMPROGRAMPROGRAMPROGRAMPROGRAMPROGRAMPROGRAMPROGRAM
FirstFirstFirstFirst part: part: part: part: SchemeSchemeSchemeScheme
Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Subject 2.Subject 2.Subject 2.Subject 2.---- Expressions and FunctionsExpressions and FunctionsExpressions and FunctionsExpressions and Functions
Subject 3.Subject 3.Subject 3.Subject 3.---- Conditional Predicates and SentencesConditional Predicates and SentencesConditional Predicates and SentencesConditional Predicates and Sentences
3
Subject 4.Subject 4.Subject 4.Subject 4.---- Iteration and RecursionIteration and RecursionIteration and RecursionIteration and Recursion
Subject 5.Subject 5.Subject 5.Subject 5.---- Compound Data Types Compound Data Types Compound Data Types Compound Data Types
Subject 6.Subject 6.Subject 6.Subject 6.---- Data Abstraction Data Abstraction Data Abstraction Data Abstraction
Subject 7.Subject 7.Subject 7.Subject 7.---- Reading and WritingReading and WritingReading and WritingReading and Writing
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ContentsContentsContentsContents
1. Fundamental Characteristics of Functional Programming
2. Historic Summary of Scheme
4
2. Historic Summary of Scheme
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ContentsContentsContentsContents
1. Fundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional Programming
2. Historic Summary of Scheme
5
2. Historic Summary of Scheme
1.1.1.1. Fundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional Programming
� FunctionalFunctionalFunctionalFunctional Programming is a subtypesubtypesubtypesubtype of DeclarativeDeclarativeDeclarativeDeclarative Programming
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
6
1.1.1.1. Fundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional Programming
� DeclarativeDeclarativeDeclarativeDeclarative Programming (1 / 2)Programming (1 / 2)Programming (1 / 2)Programming (1 / 2)
� ObjectiveObjectiveObjectiveObjective: Problem descriptionProblem descriptionProblem descriptionProblem description
“What”“What”“What”“What” problem must be resolved?
� NoticeNoticeNoticeNotice:
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
7
� NoticeNoticeNoticeNotice:
- It does notnotnotnot mind “how”how”how”how” the problem is resolved
- It avoidsavoidsavoidsavoids the implementation features.
1.1.1.1. Fundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional Programming
� DeclarativeDeclarativeDeclarativeDeclarative Programming (2 / 2)Programming (2 / 2)Programming (2 / 2)Programming (2 / 2)
� FeaturesFeaturesFeaturesFeatures
� Expressivity
� Extensible: 10% - 90% rule
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
8
� Protection
� Mathematic Elegance
� TypesTypesTypesTypes:
� Functional Functional Functional Functional or Applicative Programming:
- Lisp, SchemeSchemeSchemeScheme, Haskell, …
� LogicLogicLogicLogic Programming: PrologPrologPrologProlog
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
1. Fundamental Characteristics of Functional Programming Fundamental Characteristics of Functional Programming Fundamental Characteristics of Functional Programming Fundamental Characteristics of Functional Programming
� PrinciplePrinciplePrinciplePrinciple of the “Pure”“Pure”“Pure”“Pure” FunctionalFunctionalFunctionalFunctional Programming
“The expression valueexpression valueexpression valueexpression value only depends ondepends ondepends ondepends on its subsubsubsub----expressionsexpressionsexpressionsexpressions values,
if such sub-expressions exist ”.
� NonNonNonNon collateral effectscollateral effectscollateral effectscollateral effects
9
The value of “a + b” onlyonlyonlyonly depends on “a” and “b”.
� The functionfunctionfunctionfunction term is used in its mathematicalmathematicalmathematicalmathematical sense.
� No instructionsNo instructionsNo instructionsNo instructions: programming withoutwithoutwithoutwithout assignments
� The impureimpureimpureimpure Functional programming allowsallowsallowsallows the
“assignment instruction”“assignment instruction”“assignment instruction”“assignment instruction”
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
1.1.1.1. Fundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional Programming
� ProgramProgramProgramProgram structurestructurestructurestructure in FunctionalFunctionalFunctionalFunctional Programming
� The The The The programprogramprogramprogram is a function is a function is a function is a function composedcomposedcomposedcomposed of simpler functionsof simpler functionsof simpler functionsof simpler functions
� Function execution:Function execution:Function execution:Function execution:
� Receives the input dataReceives the input dataReceives the input dataReceives the input data: functions arguments or parameters
10
� Evaluates the expressionsEvaluates the expressionsEvaluates the expressionsEvaluates the expressions
� Returns the ResultReturns the ResultReturns the ResultReturns the Result: computed value of the function
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
1. Fundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional ProgrammingFundamental Characteristics of Functional Programming
� TypeTypeTypeType of Functional Languagesof Functional Languagesof Functional Languagesof Functional Languages
� MostMostMostMost of them are interpreted interpreted interpreted interpreted languages
� Some of them have compiledcompiledcompiledcompiled versions
� Memory managementMemory managementMemory managementMemory management
� Implicit memory managementImplicit memory managementImplicit memory managementImplicit memory management:
11
� Implicit memory managementImplicit memory managementImplicit memory managementImplicit memory management:
� Memory management is a task of the interpreter.
� The programmer must notnotnotnot worry about memory management.
� Garbage collectionGarbage collectionGarbage collectionGarbage collection: task of the interpreter.
In shortIn shortIn shortIn short: the programmer must only worry about the Problem descriptionProblem descriptionProblem descriptionProblem description
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ContentsContentsContentsContents
1. Fundamental Characteristics of Functional Programming
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
12
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISP
� Compilation versus Interpretation
� Lexical (or static) versus dynamical scope
� Origin of Scheme
13
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISPLISPLISPLISP
� Compilation versus Interpretation
� Lexical (or static) versus dynamical scope
� Origin of Scheme
14
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISPLISPLISPLISP
� John McCarthyJohn McCarthyJohn McCarthyJohn McCarthy (MIT)
� “Advice Taker”“Advice Taker”“Advice Taker”“Advice Taker” program:
� Theoretical basis: Logic Mathematics
15
� Objective: Deduction and Inferences
� LISPLISPLISPLISP: LISLISLISLISt PPPProcessing (1956 – 1958)
� Second historic language of Artificial IntelligenceArtificial IntelligenceArtificial IntelligenceArtificial Intelligence (after IPL)
� At present time, second historic language in usein usein usein use (after Fortran)
� LISP is based on Lambda Calculus (Alonzo ChurchAlonzo ChurchAlonzo ChurchAlonzo Church)
� SchemeSchemeSchemeScheme is a dialectdialectdialectdialect of LISPLISPLISPLISP
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISPLISPLISPLISP
� Functional Programming Characteristics Functional Programming Characteristics Functional Programming Characteristics Functional Programming Characteristics
� RecursionRecursionRecursionRecursion
� ListsListsListsLists
16
� ImplicitImplicitImplicitImplicit memory management
� Interactive and interpretedinterpretedinterpretedinterpreted programs
� SymbolicSymbolicSymbolicSymbolic Programming
� DynamicallyDynamicallyDynamicallyDynamically scopedscopedscopedscoped for nonnonnonnon local variables
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISPLISPLISPLISP
� LISP’s contributionscontributionscontributionscontributions:
� Built Built Built Built –––– inininin functions
� Garbage collectionGarbage collectionGarbage collectionGarbage collection
17
� Definition Formal LanguageDefinition Formal LanguageDefinition Formal LanguageDefinition Formal Language: LISPLISPLISPLISP itselfitselfitselfitself
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISPLISPLISPLISP
� ApplicationsApplicationsApplicationsApplications: Artificial IntelligenceArtificial IntelligenceArtificial IntelligenceArtificial Intelligence Programs
� Theorem verification and testing
� Symbolic differentiation and integration
� Search Problems
18
� Search Problems
� Natural Language Processing
� Computer Vision
� Robotics
� Knowledge Representation Systems
� Expert Systems
� And so on
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISPLISPLISPLISP
� Dialects (1 /2)Dialects (1 /2)Dialects (1 /2)Dialects (1 /2)
� Mac LISPMac LISPMac LISPMac LISP (Man and computer or Machine – aided cognition): EastEastEastEast Coast Version
� Inter LISPInter LISPInter LISPInter LISP (Interactive LISP): WestWestWestWest Coast Version
19
� Inter LISPInter LISPInter LISPInter LISP (Interactive LISP): WestWestWestWest Coast Version
- Bolt, Beranek y Newman Company (BBN)
- Research Center of Xerox at Palo Alto (Texas)
- LISP MachineLISP MachineLISP MachineLISP Machine
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISPLISPLISPLISP
� DialectsDialectsDialectsDialects (2 / 2)
� Mac LISPMac LISPMac LISPMac LISP (Man and computer or Machine – aided cognition): East Coast Version
- C-LISP: Massachusetts University
20
- C-LISP: Massachusetts University
- Franz LISP: California University (Berkeley). Compiled Compiled Compiled Compiled versionversionversionversion.
- NIL (New implementation of LISP): MIT.
- PSL (Portable Standard LISP): Utah University
- SchemeSchemeSchemeScheme: MIT.
- T (True):Yale University.
- Common LISP
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISP
� Compilation versus InterpretationCompilation versus InterpretationCompilation versus InterpretationCompilation versus Interpretation
� Lexical (or static) versus dynamical scope
� Origin of Scheme
21
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� CompilationCompilationCompilationCompilation:
� The source code source code source code source code (high levelhigh levelhigh levelhigh level) is transformedtransformedtransformedtransformed into executable executable executable executable code code code code (low levellow levellow levellow level), which can be independently run.
22
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� CompilationCompilationCompilationCompilation
23
Source codeSource codeSource codeSource codeSource codeSource codeSource codeSource code�� CompilerCompilerCompilerCompilerCompilerCompilerCompilerCompiler
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� CompilationCompilationCompilationCompilation
24
Compilation errorsCompilation errorsCompilation errorsCompilation errorsCompilation errorsCompilation errorsCompilation errorsCompilation errors
��
Source codeSource codeSource codeSource codeSource codeSource codeSource codeSource code�� CompilerCompilerCompilerCompilerCompilerCompilerCompilerCompiler
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� CompilationCompilationCompilationCompilation
25
Source codeSource codeSource codeSource codeSource codeSource codeSource codeSource code�� CompilerCompilerCompilerCompilerCompilerCompilerCompilerCompiler �� Executable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable code
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
��
Input dataInput dataInput dataInput dataInput dataInput dataInput dataInput data
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� CompilationCompilationCompilationCompilation
26
Source codeSource codeSource codeSource codeSource codeSource codeSource codeSource code�� CompilerCompilerCompilerCompilerCompilerCompilerCompilerCompiler �� Executable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable code
��
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
��
Input dataInput dataInput dataInput dataInput dataInput dataInput dataInput data
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� CompilationCompilationCompilationCompilation
27
Execution errorsExecution errorsExecution errorsExecution errorsExecution errorsExecution errorsExecution errorsExecution errors
Source codeSource codeSource codeSource codeSource codeSource codeSource codeSource code�� CompilerCompilerCompilerCompilerCompilerCompilerCompilerCompiler �� Executable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable code
��
OutputOutputOutputOutputOutputOutputOutputOutput
��
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
��
Input dataInput dataInput dataInput dataInput dataInput dataInput dataInput data
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� CompilationCompilationCompilationCompilation
28
Source codeSource codeSource codeSource codeSource codeSource codeSource codeSource code�� CompilerCompilerCompilerCompilerCompilerCompilerCompilerCompiler �� Executable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable codeExecutable code
��
OutputOutputOutputOutputOutputOutputOutputOutput
��
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� InterpretationInterpretationInterpretationInterpretation
29
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretation interpretation interpretation interpretation
� Interpretation Interpretation Interpretation Interpretation or simulationsimulationsimulationsimulation: consists of a cycle of three stages
30
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� Interpretation Interpretation Interpretation Interpretation or simulation: consists of a cycle of three stages
1. AnalysisAnalysisAnalysisAnalysis: the source code is analysed to determine the following correct sentence to be run.
31
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� Interpretation Interpretation Interpretation Interpretation or simulation: consists of a cycle of three stages
1. AnalysisAnalysisAnalysisAnalysis: the source code is analysed to determine the following correct sentence to be run.
2. GenerationGenerationGenerationGeneration: the sentence is transformed into executable
32
2. GenerationGenerationGenerationGeneration: the sentence is transformed into executable code.
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� Interpretation Interpretation Interpretation Interpretation or simulation: consists of a cycle of three stages
1. AnalysisAnalysisAnalysisAnalysis: the source code is analysed to determine the following correct sentence to be run.
2. GenerationGenerationGenerationGeneration: the sentence is transformed into executable
33
2. GenerationGenerationGenerationGeneration: the sentence is transformed into executable code.
3. ExecutionExecutionExecutionExecution: the executable code is run.
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� InterpretationInterpretationInterpretationInterpretation
34
Source codeSource codeSource codeSource codeSource codeSource codeSource codeSource code�� InterpreterInterpreterInterpreterInterpreterInterpreterInterpreterInterpreterInterpreter
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Input dataInput dataInput dataInput dataInput dataInput dataInput dataInput data Interpretation errorsInterpretation errorsInterpretation errorsInterpretation errorsInterpretation errorsInterpretation errorsInterpretation errorsInterpretation errors
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� InterpretationInterpretationInterpretationInterpretation
35
Source codeSource codeSource codeSource codeSource codeSource codeSource codeSource code�� InterpreterInterpreterInterpreterInterpreterInterpreterInterpreterInterpreterInterpreter
��
Input dataInput dataInput dataInput dataInput dataInput dataInput dataInput data Interpretation errorsInterpretation errorsInterpretation errorsInterpretation errorsInterpretation errorsInterpretation errorsInterpretation errorsInterpretation errors
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Input dataInput dataInput dataInput dataInput dataInput dataInput dataInput data
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� InterpretationInterpretationInterpretationInterpretation
36
Source codeSource codeSource codeSource codeSource codeSource codeSource codeSource code�� InterpreterInterpreterInterpreterInterpreterInterpreterInterpreterInterpreterInterpreter
OutputOutputOutputOutputOutputOutputOutputOutput
����
Input dataInput dataInput dataInput dataInput dataInput dataInput dataInput data
Execution errorsExecution errorsExecution errorsExecution errorsExecution errorsExecution errorsExecution errorsExecution errors
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Input dataInput dataInput dataInput dataInput dataInput dataInput dataInput data
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
� InterpretationInterpretationInterpretationInterpretation
37
Source codeSource codeSource codeSource codeSource codeSource codeSource codeSource code�� InterpreterInterpreterInterpreterInterpreterInterpreterInterpreterInterpreterInterpreter
OutputOutputOutputOutputOutputOutputOutputOutput
����
Input dataInput dataInput dataInput dataInput dataInput dataInput dataInput data
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
� CompilationCompilationCompilationCompilation
- IndependentIndependentIndependentIndependent
- Memory necessitiesMemory necessitiesMemory necessitiesMemory necessities
� InterpretationInterpretationInterpretationInterpretation
- DependentDependentDependentDependent
- No memory necessitiesNo memory necessitiesNo memory necessitiesNo memory necessities
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Compilation Compilation Compilation Compilation versusversusversusversus interpretationinterpretationinterpretationinterpretation
38
- EfficientEfficientEfficientEfficient
- GlobalGlobalGlobalGlobal
- No interactionNo interactionNo interactionNo interaction
- ClosedClosedClosedClosed code during executioncode during executioncode during executioncode during execution
- Less efficientLess efficientLess efficientLess efficient
- LocalLocalLocalLocal
- InteractionInteractionInteractionInteraction
- OpenOpenOpenOpen code during executioncode during executioncode during executioncode during execution
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISP
� Compilation versus Interpretation
� Lexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scope
� Origin of Scheme
39
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Lexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scope
� The scope rulesscope rulesscope rulesscope rules determine the declarationdeclarationdeclarationdeclaration of nonnonnonnon local identifiers
� Non Non Non Non local identifiers:
� VariablesVariablesVariablesVariables or functionsfunctionsfunctionsfunctions which can be usedusedusedused in a function or procedure but are notnotnotnot declared in that function or procedure
40
� Two typesTwo typesTwo typesTwo types
� Lexical or static scopeLexical or static scopeLexical or static scopeLexical or static scope
- WithWithWithWith “blocks structure”: Pascal, SchemeSchemeSchemeScheme
- WithoutWithoutWithoutWithout “blocks structure”: C, Fortran
� Dynamical scope:Dynamical scope:Dynamical scope:Dynamical scope:
- Always withAlways withAlways withAlways with “blocks structure”: Lisp, SNOBOL, APL
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Lexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scope
� Block structureBlock structureBlock structureBlock structure
� A procedure or function can callcallcallcall
- Itself
- Its children (but notnotnotnot its grandchildren…)
- Its brothers (but notnotnotnot its nephews)
41
- Its brothers (but notnotnotnot its nephews)
- Its father, grandfather, great-grandfather, …
- The brothers of its father, grandfather, …
� A procedure or function can be calledbe calledbe calledbe called by
- Itself
- Its father (but notnotnotnot by its grandfather, …)
- Its children, grandchildren, great-grandchildren, …
- Its brothers and their children, grandchildren, ...
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
P
Declaration of procedure f
Declaration of procedure g
Declaration of procedure h
Declaration of procedure k
Example of Example of Example of Example of blocks structureblocks structureblocks structureblocks structure
42
Declaration of procedure l
Declaration of procedure m
Declaration of procedure n
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
P
f l
43
m ng h
k Hierarchical blocks structureHierarchical blocks structureHierarchical blocks structureHierarchical blocks structure
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
f l
P
44
m ng h
k Functions which can be called by ffff
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
f l
P
45
m ng h
k Functions which can call f
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
f l
P
46
m ng h
k Functions which can be called by h
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
f l
P
47
m ng h
k Functions which can call h
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Lexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scope
� LexicalLexicalLexicalLexical or static scopeor static scopeor static scopeor static scope
� The declarationdeclarationdeclarationdeclaration of a nonnonnonnon local identifier depends on the closest closest closest closest lexical context: lexical context: lexical context: lexical context:
You only have to readreadreadread the program
48
to determine the declaration of an identifier.
� The closest nesting rules:The closest nesting rules:The closest nesting rules:The closest nesting rules:
- The scopescopescopescope of a procedure (****) ffff includes the procedure ffff.
- If a nonnonnonnon local identifier xxxx is used in f f f f then the declaration of xxxx must be found in the closestclosestclosestclosest procedure gggg which includes ffff
- NoticeNoticeNoticeNotice (****) : procedure, function or block
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Example: Example: Example: Example:
Lexical scope Lexical scope Lexical scope Lexical scope
withwithwithwith “block structure”“block structure”“block structure”“block structure”
Declaration of procedure hDeclaration of variable x (x1)Declaration of variable y (y1)Declaration of variable z (z1)
Declaration of procedure gDeclaration of variable x (x2) Declaration of variable y (y2)
Declaration of procedure fDeclaration of variable x (x3)
49
withwithwithwith “block structure”“block structure”“block structure”“block structure”Use of x (���� x3)Use of y (���� y2)Use of z (���� z1)
Use of x (���� x2)Use of y (���� y2)Use of z (���� z1)Call to f
Use of x (���� x1)Use of y (���� y1)Use of z (���� z1)Call to g
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Lexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scope
� LexicalLexicalLexicalLexical or static scopeor static scopeor static scopeor static scope
� WithoutWithoutWithoutWithout block structure:
- If xxxx is notnotnotnot local for a specificspecificspecificspecific function then it is notnotnotnot local for allallallall functions
50
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
int x; /* x1 */int y; /* y1 */int z; /* z1 */
main(){
int x; /* x2 */int y; /* y2 */
/* Use of x ���� x2 *//* Use of y ���� y2 */
Example in C:Example in C:Example in C:Example in C:
Global variablesGlobal variablesGlobal variablesGlobal variables arearearearenot not not not recommendedrecommendedrecommendedrecommended
51
/* Use of y ���� y2 *//* Use of z ���� z1 *//* Call to f */f ();
}
f(){int x; /* x3 *//* Use of x ���� x3 *//* Use of y ���� y1 *//* Use of z ���� z1 */}
withoutwithoutwithoutwithout
“block structure”“block structure”“block structure”“block structure”
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Lexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scope
� DynamicalDynamicalDynamicalDynamical scope:scope:scope:scope:
� The declarationdeclarationdeclarationdeclaration of an identifieridentifieridentifieridentifier depends on the execution of the execution of the execution of the execution of the programprogramprogramprogram
You have to runrunrunrun the program
52
You have to runrunrunrun the program
to determine the declaration of an identifier
� The closest activation rules:The closest activation rules:The closest activation rules:The closest activation rules:
- The scopescopescopescope of a procedure (****) ffff includes the procedure ffff.
- If a nonnonnonnon local identifier xxxx is used in the activationactivationactivationactivation of f f f f then the declaration of xxxx must be found in the closestclosestclosestclosest activeactiveactiveactiveprocedure gggg with a declaration of x
- NoticeNoticeNoticeNotice (****) : procedure, function or block
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Lexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scopeLexical (or static) versus dynamical scope
� NoticeNoticeNoticeNotice:
� The dynamical scopedynamical scopedynamical scopedynamical scope allows that an identifieridentifieridentifieridentifier can be associated to different declarationsdifferent declarationsdifferent declarationsdifferent declarations during the program execution
53
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x
Declaration of procedure h
Example:Example:Example:Example:
LexicalLexicalLexicalLexical
versus versus versus versus
54
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
DynamicalDynamicalDynamicalDynamical
scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
55
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
56
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
57
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
f
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
58
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
59
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
60
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
g
f
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
61
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
g
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
62
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
h
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
f
63
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
h
f
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
64
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
h
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
65
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
66
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
67
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
f
Program
Programg
Program g
Program
f
Program
68
Program
g
Programg
Program
h
Changes in the activation Stack (1 / 2)Changes in the activation Stack (1 / 2)Changes in the activation Stack (1 / 2)Changes in the activation Stack (1 / 2)
f
g
Program
h
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
f
g
Program
h
g
Program
hg
Program
69Changes in the activation Stack (2 / 2)Changes in the activation Stack (2 / 2)Changes in the activation Stack (2 / 2)Changes in the activation Stack (2 / 2)
Program
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
70
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope
71
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
72
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of x1Call to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope� Use of Use of Use of Use of x1x1x1x1 of of of of ProgramProgramProgramProgram in in in in ProgramProgramProgramProgram
73
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
74
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x1
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
75
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope� Use of Use of Use of Use of x1x1x1x1 of of of of ProgramProgramProgramProgram in in in in ffff
76
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
f
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope
77
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
78
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope
79
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
80
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x1
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
81
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope� Use of Use of Use of Use of x1x1x1x1 of of of of ProgramProgramProgramProgram in in in in ffff
82
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
g
f
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope
83
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
g
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
84
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
85
Declaration of procedure hUse of x2Call to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope� Use of Use of Use of Use of x2x2x2x2 of of of of gggg in in in in hhhh
86
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
h
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
87
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x1
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
88
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
f
Lexical scopeLexical scopeLexical scopeLexical scope� Use of Use of Use of Use of x1x1x1x1 of of of of ProgramProgramProgramProgram in in in in ffff
89
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
h
f
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope
90
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
h
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x2
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
91
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x2
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope� Use of Use of Use of Use of x2x2x2x2 of of of of gggg in in in in gggg
92
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x2
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
lexicallexicallexicallexical scopescopescopescope
93
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x2
Use of xCall to fCall to g
lexicallexicallexicallexical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope
94
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Lexical scopeLexical scopeLexical scopeLexical scope
95
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
96
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope
97
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
98
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of x1Call to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope� Use of Use of Use of Use of x1x1x1x1 of of of of ProgramProgramProgramProgram in in in in ProgramProgramProgramProgram
99
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
100
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x1
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
101
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope� Use of Use of Use of Use of x1x1x1x1 of of of of ProgramProgramProgramProgram in in in in ffff
102
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
f
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope
103
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
104
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope
105
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
106
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x2
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
107
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope� NoticeNoticeNoticeNotice: use of : use of : use of : use of x2x2x2x2 of of of of gggg in in in in ffff
108
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
g
f
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope
109
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
g
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
110
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
111
Declaration of procedure hUse of x2Call to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope� Use of Use of Use of Use of x2x2x2x2 of of of of gggg in in in in hhhh
112
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
h
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
113
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x2
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
114
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
f
Dynamical scopeDynamical scopeDynamical scopeDynamical scope� NoticeNoticeNoticeNotice: use of : use of : use of : use of x2x2x2x2 of of of of gggg in in in in ffff
115
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
h
f
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope
116
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
h
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
117
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x2
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope� Use of Use of Use of Use of x2x2x2x2 of of of of gggg in in in in gggg
118
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Program
g
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
ProgramDeclaration of variable x (x1)
Declaration of procedure fUse of x
Declaration of procedure gDeclaration of variable x (x2)
Declaration of procedure h
Run with Run with Run with Run with
dynamicaldynamicaldynamicaldynamical scopescopescopescope
119
Declaration of procedure hUse of xCall to f
Call to fCall to hif condition = true then Call to gelse Use of x2
Use of xCall to fCall to g
dynamicaldynamicaldynamicaldynamical scopescopescopescope
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope
120
f
f
h
Activation StackActivation StackActivation StackActivation Stack
Program
Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
Program
f g
Dynamical scopeDynamical scopeDynamical scopeDynamical scope
121
f
f
h
Activation StackActivation StackActivation StackActivation Stack Activation TreeActivation TreeActivation TreeActivation Tree
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� LISP
� Compilation versus Interpretation
� Dynamically versus statically scope
� Origin of SchemeOrigin of SchemeOrigin of SchemeOrigin of Scheme
122
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� Origin of SchemeOrigin of SchemeOrigin of SchemeOrigin of Scheme:
� Gerald Jay SussmanSussmanSussmanSussman (MIT) and Guy Lewis SteeleSteeleSteeleSteele Jr.
� QuestionQuestionQuestionQuestion:
How would LISPLISPLISPLISP be with lexicallexicallexicallexical or static static static static scopescopescopescope rules?
� AnswerAnswerAnswerAnswer: new language � SchemeSchemeSchemeScheme
123
� AnswerAnswerAnswerAnswer: new language � SchemeSchemeSchemeScheme
� More efficientefficientefficientefficient implementation of recursionrecursionrecursionrecursion
� First class functionsFirst class functionsFirst class functionsFirst class functions.
� Rigorous semanticsemanticsemanticsemantic rules
� InfluenceInfluenceInfluenceInfluence on Common LISP: lexical scope rules
� Revised Revised Revised Revised 5555 Report on the Algorithmic Language SchemeReport on the Algorithmic Language SchemeReport on the Algorithmic Language SchemeReport on the Algorithmic Language Scheme
Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Artificial Intelligence Languages Subject 1.Subject 1.Subject 1.Subject 1.---- Introduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme languageIntroduction to Scheme language
2. Historic Summary of SchemeHistoric Summary of SchemeHistoric Summary of SchemeHistoric Summary of Scheme
� SchemeSchemeSchemeScheme:
� Structure of scheme programsStructure of scheme programsStructure of scheme programsStructure of scheme programs
� Sequence of
- definitionsdefinitionsdefinitionsdefinitions of functions and variables
- and expressionsexpressionsexpressionsexpressions
124
- and expressionsexpressionsexpressionsexpressions
CÓRDOBA UNIVERSITYCÓRDOBA UNIVERSITYCÓRDOBA UNIVERSITYCÓRDOBA UNIVERSITY
SUPERIOR POLYTECHNIC SCHOOLSUPERIOR POLYTECHNIC SCHOOLSUPERIOR POLYTECHNIC SCHOOLSUPERIOR POLYTECHNIC SCHOOL
DEPARTAMENT OFDEPARTAMENT OFDEPARTAMENT OFDEPARTAMENT OFCOMPUTER SCIENCE AND NUMERICAL ANALYSIS COMPUTER SCIENCE AND NUMERICAL ANALYSIS COMPUTER SCIENCE AND NUMERICAL ANALYSIS COMPUTER SCIENCE AND NUMERICAL ANALYSIS
ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE ARTIFICIAL INTELLIGENCE LANGUAGESLANGUAGESLANGUAGESLANGUAGESLANGUAGESLANGUAGESLANGUAGESLANGUAGES
TECHNICAL ENGINEERING IN MANAGEMENT COMPUTER SCIENCETECHNICAL ENGINEERING IN MANAGEMENT COMPUTER SCIENCETECHNICAL ENGINEERING IN MANAGEMENT COMPUTER SCIENCETECHNICAL ENGINEERING IN MANAGEMENT COMPUTER SCIENCE
TECHNICAL ENGINEERING IN SYSTEMS COMPUTER SCIENCETECHNICAL ENGINEERING IN SYSTEMS COMPUTER SCIENCETECHNICAL ENGINEERING IN SYSTEMS COMPUTER SCIENCETECHNICAL ENGINEERING IN SYSTEMS COMPUTER SCIENCE
SECOND COURSESECOND COURSESECOND COURSESECOND COURSE
FIRST FIRST FIRST FIRST FOURFOURFOURFOUR----MONTH PERIODMONTH PERIODMONTH PERIODMONTH PERIOD