COMP 251 Programming Languages [3-0-1:3]
2006 Fall Term
Lecture 1, TuTh 13:30-14:50, Rm 2502
Prof. Dekai WU, Rm 3539, 2358-6989,
Announcements<- Important

Always check for up-to-the-minute announcements.
Lab info is at
Newsgroup is hkust.cs.class.251. Always read before asking/posting/emailing your question.

2006.11.22: Assignment 6 will be due Sun Dec 3, 2006 at 23:59 via CASS.

2006.10.26: Assignment 5 will be due Wed Nov 10, 2006 at 23:59 via CASS.

2006.09.29: Assignment 4 will be due Wed Oct 20, 2006 at 23:59 via CASS.

2006.09.01: Welcome to COMP251 L1! Our first lecture will be on Tue 12 Sep, and labs will begin Week 3.



Lecture section 1 of this course is a continuation of our integrated COMP151-251 yearlong sequence, designed to give you an enhanced holistic perspective, comparing and contrasting the most important paradigms of programming languages. We will be continuing with the C++ and Scheme/Lisp concepts you have learned last semester, and further transitioning to better understand their functional and generic programming roots and foundations. We will also learn about the syntactic description and analysis of programming languages, and their runtime environments. Toward the end we will extend our learning to logic programming, which is a powerful paradigm that has yet to become widely exploited in typical C++ environments.


Comparative studies of programming languages, programming language concepts and constructs. Non-imperative programming paradigms: object-oriented, functional, logic, concurrent programming. Basic concepts of program translation and interpretation. Storage allocation and run-time organization. Prerequisite: COMP151/151H and COMP171/171H


  1. Programming Languages: Concepts and Constructs (2nd Edition), by Ravi SETHI. Addison-Wesley, 1996.


  1. Structure and Interpretation of Computer Programs (2nd edition), by Harold ABELSON and Gerald Jay SUSSMAN, with Julie SUSSMAN. MIT Press, 1984. ISBN: 0-262-01077-1
  2. Elements of ML Programming (2nd Edition), by Jeffrey D. ULLMAN. Prentice-Hall, 1998. ISBN: 0-13-790387-1.
  3. Programming in Prolog (5th Edition), by William F. CLOCKSIN and Christopher S. MELLISH. Springer-Verlag, 2003. ISBN: 3-54-000678-8.
  4. Thinking in C++, Volume One: Introduction to Standard C++ (2nd Edition), by Bruce ECKEL. Prentice-Hall, 2000. ISBN: 0-13-979809-9.
  5. Thinking in C++, Volume Two: Practical Programming, by Bruce ECKEL and Chuck ALLISON. Prentice-Hall, 2004. ISBN: 0-13-035313-2.
Full text and code for the Scheme book (Structure and Interpretation of Computer Programs) is available online at no cost at

Full text and code for both Thinking in C++ volumes are available online at no cost at
An official Hong Kong mirror site for fast downloading is at




You are welcome to knock on the doors of the instructor any time. The TA's office hours are posted at


To receive a passing grade, you are required to sign an honor statement acknowledging that you understand and will uphold all policies on plagiarism and collaboration.


All materials submitted for grading must be your own work. You are advised against being involved in any form of copying (either copying other people's work or allowing others to copy yours). If you are found to be involved in an incident of plagiarism, you will receive a failing grade for the course and the incident will be reported for appropriate disciplinary actions.

University policy requires that students who cheat more than once be expelled. Please review the cheating topic from your UST Student Orientation.

Warning: sophisticated plagiarism detection systems are in operation!


You are encouraged to collaborate in study groups. However, you must write up solutions on your own. You must also acknowledge your collaborators in the write-up for each problem, whether or not they are classmates. Other cases will be dealt with as plagiarism.


No reading material is allowed during the examinations. No make-ups will be given unless prior approval is granted by the instructor, or you are in unfavorable medical condition with physician's documentation on the day of the examination. In addition, being absent at the final examination results in automatic failure of the course according to university regulations, unless prior approval is obtained from the department head.

There will be one midterm worth 250 points (25%), and one final exam worth 350 points (35%).


All programming assignments must be submitted at the beginning of lecture on the due date. Programming assignments must be in C++ on Unix and will be collected electronically using the automated ACS (assignment collection system). Late assignments cannot be accepted. Sorry, in the interest of fairness, exceptions cannot be made.

Programming assignments will account for a total of 300 points (30%).


All information for laboratory assignments is at

Laboratory assignments will be announced at the end of each week, and will be due on the following Friday at 23:00. Laboratory assignments must be in C++ on Unix and will be collected electronically using the automated CASS assignment collection system. Late assignments cannot be accepted. Sorry, in the interest of fairness, exceptions cannot be made.

You will also have the option to turn in your laboratory assignments in lab by demonstrating to the TA. This will also give you an opportunity to get an early indication of whether your assignment is correct. If not, you may still decide to fix it, and then wait until the Friday 23:00 CASS collection to turn in your assignment.

There will be approximately 10 laboratory assignments, each accounting for 10 points, for a total of 100 points (10%).


The total points you can achieve in the course is 1000.  The course will be graded on a curve, but subject to the following guarantees:
If you achieve 900 points you will receive no less than a A grade.
800 points B
700 points C
600 points D

Schedule Wk Event Paradigm Topic Notes Reading Assignments
2006.02.01 1 Lecture Administrivia (honor statement, HKUST classroom conduct) Business Week, The Perils of JavaSchools
2006.02.03 1 Lecture SwEngr Introduction: C++ and software engineering (doxygen notes: Marine's, Adam's) V1.Ch1
2006.02.06 2 Lecture SwEngr Introduction: Data abstraction V1.Ch2
2006.02.08 2 Lecture SwEngr Introduction: Data abstraction (cont) (YourPets2a.cpp, YourPets2b.cpp)
2006.02.10 2 Lecture SwEngr Separate compilation (CheckDate.cpp, Date.cpp, Date.hpp) V1.Ch3 (p202-210)
2006.02.13 3 Lecture SwEngr Separate compilation (cont) (UseSqrt.cpp, CheckDate2.cpp, Date2.cpp, Date2.hpp, DayOfWeek.cpp, DayOfWeek.hpp, Lang.cpp, Lang.hpp)
2006.02.15 3 Lecture Procedural Declaration and definition (reverse_print.cpp, use_reverse_print.cpp) V1.Ch4
2006.02.17 3 Lecture Procedural Declaration and definition (cont) (reverse_print.hpp) V1.Ch5
2006.02.20 4 Lecture Procedural Pointers V1.Ch3, ref V1.Ch13
2006.02.22 4 Lecture Procedural Pointers (cont), allocating 2D arrays (4-up)
2006.02.24 4 Lecture Procedural References V1.Ch3
2006.02.27 5 Lecture Procedural Const, argc & argv V1.Ch8
2006.03.01 5 Lecture StaticOO Overloading and constructors V1.Ch6
2006.03.06 6 Lecture StaticOO Overloading and constructors (cont)
2006.03.08 6 Lecture StaticOO Destructors V1.Ch6
2006.03.10 6 Lecture StaticOO Order of construction/destruction, Post Office example V1.Ch6
2006.03.13 7 Lecture StaticOO Inheritance: Introduction V1.Ch14
2006.03.15 7 Lecture StaticOO Inheritance: Substitution principle V1.Ch14
2006.03.17 7 Lecture StaticOO Inheritance: Substitution principle (cont) V1.Ch14
2006.03.20 8 Lecture StaticOO Inheritance: Access control: public, protected, private V1.Ch14
2006.03.22 8 Lecture DynamicOO Inheritance: Virtual functions V1.Ch15
2006.03.24 8 Lecture DynamicOO Inheritance: Overriding vs overloading V1.Ch15
2006.03.27 9 Lecture DynamicOO Inheritance: Abstract base classes, ex1, ex2, ex3, ex4 V1.Ch15
2006.03.29 9 Lecture StaticOO The "this" pointer V1.Ch4
2006.03.31 9 Lecture StaticOO Inheritance: Public, private, protected inheritance V1.Ch14
2006.04.03 10 Lecture SwEngr Namespaces V1.Ch10
2006.04.05 10 Holiday Ching Ming Festival
2006.04.07 10 Exam No lecture: Midterm (LTA 19:00-21:00; sample exam for your practice)
2006.04.10 11 Lecture Generic Introduction to generic programming V1.Ch16
2006.04.12 11 Lecture Generic Function and class templates V1.Ch16
2006.04.14 11 Holiday Mid-Semester Break
2006.04.17 11 Holiday Mid-Semester Break
2006.04.19 11 Holiday Mid-Semester Break
2006.04.21 11 Lecture Generic Overloading operators V1.Ch12
2006.04.24 12 Lecture Generic Container classes V2.Ch7
2006.04.26 12 Lecture Generic STL: Sequences & Iterators V2.Ch6
2006.04.28 12 Lecture Generic STL: Sequences & Iterators (cont'd) V2.Ch6 A1 due
2006.05.01 13 Holiday Labor Day
2006.05.03 13 Lecture Generic STL: Introduction to algorithms V2.Ch6
2006.05.05 13 Holiday The Birthday of the Buddha
2006.05.08 14 Lecture Generic STL: Function pointers V2.Ch6, ref V1.Ch3
2006.05.09 14 A2 due
2006.05.10 14 Lecture Generic STL: Function objects or functors V2.Ch6
2006.05.12 14 Lecture Generic STL: More algorithms V2.Ch6
2006.05.15 15 Lecture SwEngr Static V1.Ch2
2006.05.17 15 Lecture SwEngr Exceptions V2.Ch1
2006.05.22 15 A3 due
2006.05.30 16 Exam Final (12:30-15:30, LG4204; sample final exam plus a sample midterm and another sample midterm for your practice)
COMP251 (tentative)
2006.09.12 2 Lecture Introduction, Administrivia (honor statement, HKUST classroom conduct) Ch1
2006.09.14 2 Lecture Syntax Language Description Ch2.1 - Ch2.3
2006.09.19 3 Lecture Syntax Grammar Ch2.4 - Ch2.5
2006.09.21 3 Lecture Syntax Grammar, cont'd  
2006.09.26 4 Lecture Syntax Regular Grammars  
2006.09.28 4 Lecture Syntax Lex (GNU Flex) Flex user manual
2006.10.03 5 Lecture Syntax Yacc (GNU Bison) Bison user manual, FLEX and BISON on WIN32 platform
2006.10.05 5 Lecture Syntax Yacc (GNU Bison), cont'd
2006.10.10* 6 Lecture Procedural Scope and Parameter Passing Ch5.1 - Ch5.4
2006.10.12* 6 Lecture Procedural Activation Records Ch5.5 - Ch5.7
2006.10.16 7 Exam Midterm (Room TBA 18:00-21:00 )
2006.10.17 7 Lecture Functional Activation Records, cont'd
2006.10.19 7 Lecture Functional Scheme/Lisp, Function Values, Lambda Ch10.1 - Ch10.3, Scheme R5RS
2006.10.20 7 A4 due
2006.10.24 8 Lecture Functional Functions and Lambda Ch10.1, Ch8.3-Ch8.4, Ch9.2 - Ch9.4
2006.10.26 8 Lecture Functional Lambda Calculus Ch14.1
2006.10.31 9 Lecture Functional Scope and Let Statement Ch10.1, Ch8.5
2006.11.02 9 Lecture Generic/Functional Introduction to SML, Types Ch8, Ch8.6, Ch9.1
2006.11.07 10 Lecture Generic/Functional Datatypes, Miscellaneous and Summary Ch9.5, Ch9.6
2006.11.09 10 Lecture Logic Introduction to Prolog Ch11.1
2006.10.20 10 A5 due
2006.11.14 11 Lecture Logic Fact, Rule, and Program Ch11.2
2006.11.16 11 Lecture Logic List Ch11.3
2006.11.18 12 Lecture Logic Unification and Substitutions Ch11.5
2006.11.23 12 Lecture Logic Unification and Substitutions, cont'd  
2006.11.28* 13 Lecture Logic Cuts Ch11.6
2006.11.30* 13 Lecture Logic Programming Techniques Ch11.4
2006.12.03 14 A6 due
2006.12.05 14 Lecture Review    
2006.12.07 14 Lecture Review
2006.12.20 16 Exam Final (16:30-19:30, LG4204)
Last update: 2006.12.06