SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
AI Programming
             Week Two:
 Procedures, the Stack & Debugging
Richard Price
rmp@cs.bham.ac.uk
Overview
    Introduction
•
•   Recap
•   Procedures
•   The Stack




                   2
Course Details
http://www.cs.bham.ac.uk/internal/courses/ai-prog-a/
• Lab sessions:
   – Monday 3pm - 5pm.
   – Friday 2pm-4pm.
• Assessment Deadline
   – Mondays 5pm.
• Late submissions until:
   – Wednesday 10am.
   – 50% penalty.

                                                       3
Recap
• Variables & Expressions
  – Print arrow
  – Semicolon
  – Declaration
  – Assignment
  – Data Types
  – Comments.




                            4
List
• Lists:
   [1 2 3] =>
   ** [1 2 3]

   lvars mylist = [19 18 25];
   mylist =>
   mylist(1) =>
   ** 19

   lvars listInAList = [1 [2 3]];
   listInAList(2) =>
   ** [2 3];


                                    5
Procedures
• Programs can become very large.
• Procedures break down code into pieces.
  – Reusable.
  – Recognisable.
  – Named mini-program.




                                       6
Built in procedures



• Addition and division are built in
  procedures.
• Other examples:
  max(2,5) =>
  ** 5
  min(2,5) =>
  ** 2

• In Xved, press Enter then type help max.
                                        7
Write your own procedures
• Note the brackets in max(2,5);

  define myprocedure()
      ;;; code goes here
  enddefine;
  myprocedure();

  define printTwo()
    2 =>
  enddefine;
  printTwo();
  ** 2

                                   8
Variables & Procedures
• lvars declares local variables.
  – Local to a procedure.




                                    9
Arguments & Procedues
• Procedures often take in arguments.
  – +(oneNumber, anotherNumber);
  – max(argument1, argument2);

  define printTwice(valueToPrint);
      valueToPrint =>
      valueToPrint =>
  enddefine;

  printTwice(‘Rich’);
  ** Rich
  ** Rich

                                        10
Arguments & Procedures
• Write a procedure called addition that:
  – Takes in two numbers as arguments.
  – Adds them together.
  – And prints the result.




                                         11
Returning results
• Procedures often return results:
  – Max returns the maximum of two numbers.

  define max(firstNumber, secondNumber) -> largerNumber;
    …
  enddefine;

  max(5,25) =>
  ** 25




                                                           12
Multiple Arguments & Results
• Procedures often return results:
  – Max returns the maximum of two numbers.

  define printAPlusBPlusC(a,b,c)
    a + b + c =>
  enddefine;


  define returnAthenB(a,b) -> (result1, result2);
    a -> result1;
    b -> result2;
  enddefine;



                                                    13
Procedures in Procedures

• Procedures can be used within
  procedures:
define minOfThree(number1, number2, number3) -> smallestOfThree;
lvars smallestOfTwo;
  min(number1, number2) -> smallestOfTwo;
  min(number3, smallestOfTwo) -> smallestOfThree;
enddefine;




                                                           14
The Pop-11 Stack

• Almost everything in Pop-11 uses the
  stack.
• If variables are just containers.
• Then the stack is a pile of boxes.




                                  15
Assignment and the Stack

• Assignment in Pop-11
  – Uses the stack!

  – lvars creates the x variable.
  – 4 is place on the stack
  – Assignment pops 4 off.
  – Into the x variable.


                                    16
17
Viewing the Stack
lvars myVariable;
5 -> myVariable;
myVariable =>




4;
5;
6;
=>
** 4 5 6

                    18
Procedures & the stack




3;
11;
max();
=>
                         19

Weitere ähnliche Inhalte

Andere mochten auch

網頁標準(FrontPage 213)
網頁標準(FrontPage 213)網頁標準(FrontPage 213)
網頁標準(FrontPage 213)
楊 騏
 
FP2003 ch 3~5
FP2003 ch 3~5FP2003 ch 3~5
FP2003 ch 3~5
楊 騏
 
Intro to IML Keypads
Intro to IML KeypadsIntro to IML Keypads
Intro to IML Keypads
SchoonhovenF
 
นำเสนอ นบอ. มกส.
นำเสนอ นบอ. มกส.นำเสนอ นบอ. มกส.
นำเสนอ นบอ. มกส.
Atthapong Sirisuwan
 
Indian Scientific Heritage part1
Indian Scientific Heritage part1Indian Scientific Heritage part1
Indian Scientific Heritage part1
versatile36
 
慧心菩提18
慧心菩提18慧心菩提18
慧心菩提18
yhs1993
 
Diagnostic Challenges In The Workshop
Diagnostic Challenges In The WorkshopDiagnostic Challenges In The Workshop
Diagnostic Challenges In The Workshop
guest7838f0a
 
Mechanics
MechanicsMechanics
Mechanics
PhysEM
 
B.I.D. Brochure Booklet
B.I.D. Brochure BookletB.I.D. Brochure Booklet
B.I.D. Brochure Booklet
dlawrence
 

Andere mochten auch (20)

網頁標準(FrontPage 213)
網頁標準(FrontPage 213)網頁標準(FrontPage 213)
網頁標準(FrontPage 213)
 
Lets take Mumbai's water crisis HEAD ON
Lets take Mumbai's water crisis HEAD ONLets take Mumbai's water crisis HEAD ON
Lets take Mumbai's water crisis HEAD ON
 
FP2003 ch 3~5
FP2003 ch 3~5FP2003 ch 3~5
FP2003 ch 3~5
 
Reform Presentation Med Society 2007
Reform Presentation Med Society 2007Reform Presentation Med Society 2007
Reform Presentation Med Society 2007
 
Intro to IML Keypads
Intro to IML KeypadsIntro to IML Keypads
Intro to IML Keypads
 
Health hazards of maida
Health hazards of maida Health hazards of maida
Health hazards of maida
 
Total Asset Visibility For Defense
Total Asset Visibility For DefenseTotal Asset Visibility For Defense
Total Asset Visibility For Defense
 
นำเสนอ นบอ. มกส.
นำเสนอ นบอ. มกส.นำเสนอ นบอ. มกส.
นำเสนอ นบอ. มกส.
 
Iteration
IterationIteration
Iteration
 
Indian Scientific Heritage part1
Indian Scientific Heritage part1Indian Scientific Heritage part1
Indian Scientific Heritage part1
 
慧心菩提18
慧心菩提18慧心菩提18
慧心菩提18
 
Diagnostic Challenges In The Workshop
Diagnostic Challenges In The WorkshopDiagnostic Challenges In The Workshop
Diagnostic Challenges In The Workshop
 
Mechanics
MechanicsMechanics
Mechanics
 
Global Strategy In Our Changing Aerospace Environment Stanford Ibc April 17...
Global Strategy In Our Changing Aerospace Environment   Stanford Ibc April 17...Global Strategy In Our Changing Aerospace Environment   Stanford Ibc April 17...
Global Strategy In Our Changing Aerospace Environment Stanford Ibc April 17...
 
Mdi Displays
Mdi DisplaysMdi Displays
Mdi Displays
 
Free Software in the Catalonia Telecentre Network
Free Software in the Catalonia Telecentre NetworkFree Software in the Catalonia Telecentre Network
Free Software in the Catalonia Telecentre Network
 
B.I.D. Brochure Booklet
B.I.D. Brochure BookletB.I.D. Brochure Booklet
B.I.D. Brochure Booklet
 
Taller d'Scratch
Taller d'ScratchTaller d'Scratch
Taller d'Scratch
 
Geo Social Recruiting by Craig Fisher
Geo Social Recruiting by Craig FisherGeo Social Recruiting by Craig Fisher
Geo Social Recruiting by Craig Fisher
 
20120920 Soutrik Portfolio Medium
20120920 Soutrik Portfolio Medium20120920 Soutrik Portfolio Medium
20120920 Soutrik Portfolio Medium
 

Ähnlich wie Procedures, the Pop-11 stack and debugging

Variables & Expressions
Variables & ExpressionsVariables & Expressions
Variables & Expressions
Rich Price
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With Maatkit
MySQLConference
 
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW SydneySoftware Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
julien.ponge
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Jesse Vincent
 
Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...
Odoo
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
ssuser454af01
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
jacksnathalie
 

Ähnlich wie Procedures, the Pop-11 stack and debugging (20)

Variables & Expressions
Variables & ExpressionsVariables & Expressions
Variables & Expressions
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With Maatkit
 
Week8
Week8Week8
Week8
 
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW SydneySoftware Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
 
What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?
 
Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
 
Valgrind tutorial
Valgrind tutorialValgrind tutorial
Valgrind tutorial
 
Multiprocessing with python
Multiprocessing with pythonMultiprocessing with python
Multiprocessing with python
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
lesson 2.pptx
lesson 2.pptxlesson 2.pptx
lesson 2.pptx
 
Lecture#2 Computer languages computer system and Programming EC-105
Lecture#2 Computer languages computer system and Programming EC-105Lecture#2 Computer languages computer system and Programming EC-105
Lecture#2 Computer languages computer system and Programming EC-105
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
WCTF 2018 binja Editorial
WCTF 2018 binja EditorialWCTF 2018 binja Editorial
WCTF 2018 binja Editorial
 
Tech Days 2015: Dynamic Analysis
Tech Days 2015: Dynamic AnalysisTech Days 2015: Dynamic Analysis
Tech Days 2015: Dynamic Analysis
 
Phpbase
PhpbasePhpbase
Phpbase
 
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docxE2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talk
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

Procedures, the Pop-11 stack and debugging

  • 1. AI Programming Week Two: Procedures, the Stack & Debugging Richard Price rmp@cs.bham.ac.uk
  • 2. Overview Introduction • • Recap • Procedures • The Stack 2
  • 3. Course Details http://www.cs.bham.ac.uk/internal/courses/ai-prog-a/ • Lab sessions: – Monday 3pm - 5pm. – Friday 2pm-4pm. • Assessment Deadline – Mondays 5pm. • Late submissions until: – Wednesday 10am. – 50% penalty. 3
  • 4. Recap • Variables & Expressions – Print arrow – Semicolon – Declaration – Assignment – Data Types – Comments. 4
  • 5. List • Lists: [1 2 3] => ** [1 2 3] lvars mylist = [19 18 25]; mylist => mylist(1) => ** 19 lvars listInAList = [1 [2 3]]; listInAList(2) => ** [2 3]; 5
  • 6. Procedures • Programs can become very large. • Procedures break down code into pieces. – Reusable. – Recognisable. – Named mini-program. 6
  • 7. Built in procedures • Addition and division are built in procedures. • Other examples: max(2,5) => ** 5 min(2,5) => ** 2 • In Xved, press Enter then type help max. 7
  • 8. Write your own procedures • Note the brackets in max(2,5); define myprocedure() ;;; code goes here enddefine; myprocedure(); define printTwo() 2 => enddefine; printTwo(); ** 2 8
  • 9. Variables & Procedures • lvars declares local variables. – Local to a procedure. 9
  • 10. Arguments & Procedues • Procedures often take in arguments. – +(oneNumber, anotherNumber); – max(argument1, argument2); define printTwice(valueToPrint); valueToPrint => valueToPrint => enddefine; printTwice(‘Rich’); ** Rich ** Rich 10
  • 11. Arguments & Procedures • Write a procedure called addition that: – Takes in two numbers as arguments. – Adds them together. – And prints the result. 11
  • 12. Returning results • Procedures often return results: – Max returns the maximum of two numbers. define max(firstNumber, secondNumber) -> largerNumber; … enddefine; max(5,25) => ** 25 12
  • 13. Multiple Arguments & Results • Procedures often return results: – Max returns the maximum of two numbers. define printAPlusBPlusC(a,b,c) a + b + c => enddefine; define returnAthenB(a,b) -> (result1, result2); a -> result1; b -> result2; enddefine; 13
  • 14. Procedures in Procedures • Procedures can be used within procedures: define minOfThree(number1, number2, number3) -> smallestOfThree; lvars smallestOfTwo; min(number1, number2) -> smallestOfTwo; min(number3, smallestOfTwo) -> smallestOfThree; enddefine; 14
  • 15. The Pop-11 Stack • Almost everything in Pop-11 uses the stack. • If variables are just containers. • Then the stack is a pile of boxes. 15
  • 16. Assignment and the Stack • Assignment in Pop-11 – Uses the stack! – lvars creates the x variable. – 4 is place on the stack – Assignment pops 4 off. – Into the x variable. 16
  • 17. 17
  • 18. Viewing the Stack lvars myVariable; 5 -> myVariable; myVariable => 4; 5; 6; => ** 4 5 6 18
  • 19. Procedures & the stack 3; 11; max(); => 19