Announcements for Programming Languages

Check here periodically during the semester for announcements. If I need to clarify a homework problem, change a due date, give advice about using the course software, or broadcast some other similar information to the class, I'll put the announcement here.


Final Exam: The final exam is Wednesday, May 7, 2:45-4:45 p.m., in Robinson 202.


How to get SWI-Prolog to display full lists: One of the annoying features of SWI-Prolog is that, by default, it abbreviates long lists. For example, instead of printing a full list like this:

ScoreList = [[r, 35], [h, 24], [m, 105], [p, 22], [g, 34], [c, 35], [o, 42], [e, 22], [k, 17]] 
it will print an abbreviated list like this:
ScoreList = [[r, 35], [h, 24], [m, 105], [p, 22], [g, 34], [c, 35], [o, 42], [e|...], [...|...]] 
Most Prolog interpreters display full lists; SWI-Prolog is unusual in this regard.

The magic incantation to make SWI-Prolog print full lists is this:

     ?- set_prolog_flag(toplevel_print_options,
                        [quoted(true), portray(true), attributes(portray),
                         max_depth(0),
                         priority(699)]).

You can either put this command in your program file, near the top, or you can put it in a file called .plrc in your home directory. (Note that the "?-" is part of it. Stick the whole thing, including "?-", in the file.)

If you like, you can copy my .plrc file into your home directory. That is, cd to your home directory and type

     cp ~nlt/.plrc .

Alternatively, when the interpreter prints its solution and then waits for <enter> or ";", you can type "w" to request the solution to be reprinted in full. (Thanks to Ben Hample for finding this second solution.)


Homework reminder: When emailing me your homework, please email only the source code file, and please send it as plain text (no doc, rtf, zip, or other formats). Unless your program is truly long enough that it needs to be split into several files, you should be mailing me only one file.

Any sample runs, supplementary documentation, or cover sheets should be turned in as paper printouts in class; these do not need to be emailed.


Scheme homework notes:

1) The integer division function in Scheme is quotient. For example,

     (quotient 89 10)
returns 8.

2) I have corrected the Scheme input format in the on-line version of the homework assignment.

3) I recommend using the member function in the portion of the program that determines a state's region. That is, I recommend

     (member State '(ME NH MA ...))
instead of
     (or (eq? State 'ME) (eq? State 'NH) (eq? State 'MA) ...)
The member function is described on p. 13 of the Scheme book.


Scheme index error: Due to an error in the pagination of the Scheme book, the index is uniformly one page off. If the index refers to page N, look at page N-1 instead. For example, the index entry for member refers you to page 14; look on page 13 instead.


Zip code string example: For those who missed the second Ada lecture, here is the zip code example illustrating fixed-length strings and arrays of records.


Scheme textbooks: The correct Scheme textbooks are now in the bookstore. Please go buy one, as we will be starting Scheme this week.

Prolog textbooks: The bookstore informs me that they are having difficulty obtaining enough copies of the Clocksin & Mellish textbook. Buy your Prolog book from the bookstore if you can, but if they are sold out, the Clocksin & Mellish text can also be purchased from several familiar on-line bookstores and from the publisher's web site.


Ada suggestions: You may code the Ada solution in any way you like. However, here are some excerpts from my type and variable declarations and from the I/O portion of my solution that you may use to guide your thinking. You have permission to use these exact lines of code in your homework solution, if you wish. And, of course, you have permission to change the code or discard it entirely.

procedure Prediction is
        Max_Candidates: constant Integer := 100;
        subtype State_Abbr is String(1..2);
        type Cand_Info is record
                Cand_Initial: Character;
                Cand_Score: Integer;
        end record;
        type Score_Array is array(1..Max_Candidates) of Cand_Info;

        Score: Score_Array;
        Current_State, Home_State: State_Abbr;
        Cand_Name: Character;
	-- MORE DECLARATIONS HERE
        Space: Character;
	-- MORE DECLARATIONS HERE, INCLUDING SOME FUNCTIONS AND/OR PROCEDURES

begin
	-- READ THE CURRENT STATE

	loop
                Get(Cand_Name);
                exit when Cand_Name = '.';
                Get(Space);	-- Skip the space character before reading the state

                Get(Home_State);
                Get(Commercials);
                Get(Days);
                Get(Wins);
                Skip_Line;	-- Skips past end-of-line character

		-- COMPUTE THE CANDIDATES' SCORES AND STORE THE RESULTS IN ARRAY "SCORE"
	end loop;
		-- PRINT THE CANDIDATES' SCORES

end Prediction;


Class cancellation: Class will be cancelled Thursday, January 24, due to a family emergency.


Homework correction: Shawn Rutter pointed out to me that I didn't include a list of regions in the homework specification. Oops. I've now added the region chart to the homework specification, and I've posted the revised specification at http://elvis.rowan.edu/~nlt/hw_pl_s08.html .


Answers to Frequently Asked Questions from previous semesters:

Question about using Scheme, Ada, and Prolog at home: I want to do my Scheme, Ada, and Prolog assignments at home, without having to dial in to campus. Are there interpreters and compilers I can use on my home computer?

Yes. Several free Scheme interpreters, including Scheme48, are available for Linux, Windows, Mac OS X, and other platforms. If you prefer to work on your home computer, you can install one of these interpreters.

I will be using Scheme48 on elvis to grade your programs, so make sure to ftp your program to elvis and test it there before handing it in. Most interpreters adhere to the standards for the Scheme language, but sometimes you will find minor incompatibilities. By testing your program on elvis, you can make sure that your program is portable to the UNIX version of Scheme48.

Similarly, free Ada compilers and free versions of SWI-Prolog and YAP ("Yet Another Prolog") are available for a variety of platforms. As with Scheme, make sure to ftp your programs to elvis and test them with the interpreters/compilers there before handing them in.

If your program does not compile under elvis's compilers/interpreters, I will grade the program as "not compiling" (about 50 points off). It is your responsibility to test your programs on elvis before handing them in.


Nancy Tinkham
Computer Science Department, Rowan University

Valid HTML 4.0!