SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
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

Contenu connexe

En vedette

網頁標準(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 ONAziz Khatri
 
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 2007jmahan
 
Intro to IML Keypads
Intro to IML KeypadsIntro to IML Keypads
Intro to IML KeypadsSchoonhovenF
 
Health hazards of maida
Health hazards of maida Health hazards of maida
Health hazards of maida Johnson C.J
 
Total Asset Visibility For Defense
Total Asset Visibility For DefenseTotal Asset Visibility For Defense
Total Asset Visibility For Defenseguestd6e8425b
 
นำเสนอ นบอ. มกส.
นำเสนอ นบอ. มกส.นำเสนอ นบอ. มกส.
นำเสนอ นบอ. มกส.Atthapong Sirisuwan
 
Indian Scientific Heritage part1
Indian Scientific Heritage part1Indian Scientific Heritage part1
Indian Scientific Heritage part1versatile36
 
慧心菩提18
慧心菩提18慧心菩提18
慧心菩提18yhs1993
 
Diagnostic Challenges In The Workshop
Diagnostic Challenges In The WorkshopDiagnostic Challenges In The Workshop
Diagnostic Challenges In The Workshopguest7838f0a
 
Mechanics
MechanicsMechanics
MechanicsPhysEM
 
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...enginerd
 
Mdi Displays
Mdi DisplaysMdi Displays
Mdi DisplaysYamani
 
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 Networkframbla
 
B.I.D. Brochure Booklet
B.I.D. Brochure BookletB.I.D. Brochure Booklet
B.I.D. Brochure Bookletdlawrence
 
Taller d'Scratch
Taller d'ScratchTaller d'Scratch
Taller d'Scratchframbla
 
Geo Social Recruiting by Craig Fisher
Geo Social Recruiting by Craig FisherGeo Social Recruiting by Craig Fisher
Geo Social Recruiting by Craig FisherCraig Fisher
 
20120920 Soutrik Portfolio Medium
20120920 Soutrik Portfolio Medium20120920 Soutrik Portfolio Medium
20120920 Soutrik Portfolio Mediumsoutrikdd
 

En vedette (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
 

Similaire à AI Programming Procedures, the Stack & Debugging

Variables & Expressions
Variables & ExpressionsVariables & Expressions
Variables & ExpressionsRich Price
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMySQLConference
 
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 Sydneyjulien.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 SauceJesse Vincent
 
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?Christophe Porteneuve
 
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.docxssuser454af01
 
Valgrind tutorial
Valgrind tutorialValgrind tutorial
Valgrind tutorialSatabdi Das
 
Multiprocessing with python
Multiprocessing with pythonMultiprocessing with python
Multiprocessing with pythonPatrick Vergain
 
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-105NUST Stuff
 
WCTF 2018 binja Editorial
WCTF 2018 binja EditorialWCTF 2018 binja Editorial
WCTF 2018 binja EditorialCharo_IT
 
Tech Days 2015: Dynamic Analysis
Tech Days 2015: Dynamic AnalysisTech Days 2015: Dynamic Analysis
Tech Days 2015: Dynamic AnalysisAdaCore
 
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.docxjacksnathalie
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talkdesistartups
 

Similaire à AI Programming Procedures, the Stack & 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
 

Dernier

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 SolutionsEnterprise Knowledge
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
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 textsMaria Levchenko
 
[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.pdfhans926745
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Dernier (20)

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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
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
 
[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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

AI Programming Procedures, the Stack & 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