Courses/CS 460/Fall 2005/Questions and comments
From CSWiki
References | Homework | Questions | Course notes | Oz notes
This page is for questions and comments about Oz, Mozart, and other issues related to this course.
Let's format this as a series of postings, without a thread structure. That is, all postings are on the same level.
Please add new postings at the top of the page. This makes it easy to see what's new without scrolling down to the bottom of the page.
Please enter each new posting as a Headline (== Headline ==) followed by the text of your posting followed by four tildes (~~~~), which will be converted into a pointer to your user page and the date of the posting.
Contents |
[edit] File output with Oz
With the recent homework assignment (Divisible) I had wanted to check all the answers output but I had to go through a bit of work to get the output into a friendly form for my test program. I found out it's fairly easy to write out to a file in Oz, but the trick is everything must be a virtual string. I'm including a version of the Divisible homework here with the procs for doing the output. This is for writing out a result set that is a collection of lists so if your result set is even further nested with lists you'll have to do some modification to make it work.
local
% Borrowed from Brian
fun {Num L}
{FoldL L fun{$ A B} {FD.plus {FD.times A 10} B} end 0 }
end
proc {Divisible S}
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9
A = [A0 A1 A2 A3 A4 A5 A6 A7 A8 A9]
in
S = A
A ::: 0#9
{FD.distinct A}
A0 \=: 0
{FD.modI A9 2} =: 0
{FD.modI {Num [A8 A9]} 4} =: 0
A9 :: [0 5]
%% Borrowed from Jeff
{FD.modI {FoldL S fun {$ I J} {FD.plus {FD.times 3 I} J} end 0} 7} =: 0
{FD.modI {Num [A7 A8 A9]} 8} =: 0
{FD.distribute ff A}
end
R F
in
% Save the result set into a variable.
R = {SearchAll Divisible}
% Open a new file with a path to the desired location.
F={New Open.file
init(name: '/Users/kellyb/Desktop/ozwrite.txt'
flags: [write create]
mode: mode(owner: [read write]
group: [read write]))}
% For each list in the result set convert it to a tuple, then write a newline character.
% The resulting file will give you one answer per line, in this case 11,460 of them.
{ForAll R proc {$ X}
{F write(vs:{List.toTuple '#' X})}
{F write(vs:"\n")}
end
}
% Don't forget to close the file.
{F close}
end
Kellyb 21:42, 13 November 2005 (PST)
[edit] Subpages
Brian Smith pointed out that MediaWiki supports subpages (if it is enabled in a namespace). Apparently is it enabled in the CS460 namespace.
I have converted the subpages of this course website to use the subpage mechanism. Instead of writing [[{{NAMESPACE}}:PageName | link text]], one can write [[/PageName | link text]]. That will create PageName as a subpage of the current page. This is like the Unix path system. Apparently any depth of pages may be created. You can even refer to pages using the parent (../) convention
I would like you to do the following for your homework pages.
- Create a page for yourself under the Homework page. (Note that the link in the preceding sentence from here to the Homework page is written as [[../Homework | Homework]] .)
- For each week's homework, create a page under your page and point to it from both your page and the Homework page.
As an example, I did Cynthia York's homework pointer from last week. Look at the Homework page and the pages I created for her to see what I mean.
- Notice that the homework pointer for Oct 1 is Cynthia York. (From here it is written [[../Homework/Cynthia York/Oct 1| '''Cynthia York''']] . From the Homework page it is written [[/Cynthia York/Oct 1| '''Cynthia York''']] .) It points to her Oct 1 homework submission.
- The higher level page Cynthia York ([[../Homework/Cynthia York| '''Cynthia York''']]) also points to that same homework submission. I want you to create the higher level page so that all the pointers to your homework submissions are collected in a single place.
- There is no direct pointer from the Homework page to Cynthia Yorks Homework page. The only link from the Homework page is to her individual homeworks.
The subpage mechanism is enabled in the User namespace. That means that you can create pages for yourself under your User page. I would prefer that you put your homework pages for this class under this class's page hierarchy. Use subpages of your User page for your own web stuff.
Thanks.
[edit] Templates
I've created a simple wiki Template for displaying code. To get the effect
yourCode
insert the line
{{Code|<pre>
before yourCode and the line
</pre>}}
after yourCode.
Unfortunately, the <pre> and </pre> tags can't be included in the template. When they are, the wiki takes them seriously and ignores the Template parameter.
If you want to look at the Template itself, it's on the page Template:Code. It's simply a <blockquote> with some style parameters. When you get there, click edit this page to see the actual code.
The notation {{{1}}} specifies a Template parameter. This is a Template with a single parameter. When calling a Template, parameters are separated by |.
If anyone can figure out how to get boldface inside a <pre> … </pre>, please let me know.
I've also created a slightly more general Template:Div, which is identical to the Template:Code except that it's first parameter is a color. Thus
{{Div | #ddaa44 | stuff}}
It would be nice to define Template:Code in terms of Template:Div as {{Div | #ccddee | {{{1}}} }}. That doesn't seem to work. It appears that the Template parsing code parses "}}" in {{1}}} as the end of the embedded Template. If anyone can figure a way around this, let me know.
Or, since MediaWiki is open source, someone should just re-write the Template code. I think it has other problems as well.
[edit] An Oz disappointment
This simple program is supposed to bind Out to 1 if In is 1. It should bind Out to 2 if In is 2. Otherwise, it should do nothing. In all of those cases, it should produce Browse output. But the only output I get is for 'before'.
Apparently, the fact that Out is uninstantiated causes Oz to wait until it gets explicitly instantiated. It doesn't get instantiated as part of the case pattern matching.
Or does anyone see something I'm missing?
local Test
proc {P In Out}
{Browse before}
case In#Out of
1#1 then {Browse 1}
[] 2#2 then {Browse 2}
else {Browse neither}
end
{Browse after}
end
in
{P 1 Test}
{Browse Test}
end
Comment from Kelly: After looking this over I can't figure out what would be binding Out to anything at all. The tuple constructor is being used so the pattern matching of the case statement is attempting to match against 1#<unassigned identifier name> since the process has been sent the integer 1 and the unassigned identifier Test, which should cause "neither" to be output, but it doesn't. In any case "after" should be output, but it isn't either.
On page 67 of the book (which is a bit confusing to me) it says that if the activation condition of the case statement is false (undetermined) the execution is suspended. As I understand it, the activation statement here is In#Out, which is undetermined since Out is unassigned. Yes? No?
Reply from Russ Abbott: I have had a number of discussions with the Oz user mailing list. The program is attempting to match In#Out to 1#1 or 2#2. But since Out is a variable which is being matched to a non-variable (1 or 2), execution suspends waiting for Out to get a value from elsewhere to see if it matches. But that never happens since there is no other thread.
