From leavens@larch.cs.iastate.edu Sat Oct 29 16:42:27 2005 Date: Sat, 29 Oct 2005 16:42:27 -0500 (CDT) From: Gary T. Leavens To: Jonathan Bentz Cc: Ru He Subject: Re: CS 541 homework question Hi Jonathan, On Sat, 29 Oct 2005, Jonathan Bentz wrote: > On problem 2, why does the definition of "borrowed" only take one > arguement? Shouldn't it take a Database and a Book? It is a curried function. Just to see if we can do that in Scala; it is required to look like: def borrowed (db: Database) : Book => Boolean; Which means that after it takes the database, it returns a function that takes a book. See the test cases for more. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------- From leavens@larch.cs.iastate.edu Sun Oct 30 11:38:37 2005 Date: Sun, 30 Oct 2005 11:38:37 -0600 (CST) From: Gary T. Leavens To: Dave Doty Cc: Ru He Subject: Re: Scala/Eclipse Hi Dave, On Sun, 30 Oct 2005, Dave Doty wrote: > Can you tell me the exact version of Eclipse and Scala you used? I am > following the instructions on the Scala plugin for Eclipse webpage exactly, > but I am getting errors just trying to create files. I'm using Eclipse 3.0.2 (not 3.1, that may be the problem), and Scala plugin 1.0.3. I'm using the latest Scala, which is 1.4.0.2. I also have JDK 1.4.2, in case it makes a difference. Try using Eclipse 3.0.2; I think if the plugin was developed for Eclipse 3.0, it may not work under 3.1... Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------- From leavens@larch.cs.iastate.edu Sun Oct 30 15:43:25 2005 Date: Sun, 30 Oct 2005 15:43:25 -0600 (CST) From: Gary T. Leavens To: Dave Doty Cc: Ru He Subject: Re: Scala/Eclipse Hi Dave, On Sun, 30 Oct 2005, Dave Doty wrote: > How do we use the ConsoleTestRunner that was included? Is there a program > that runs it? I tried just "running it" as the homework suggested: > > scalarun.bat -classpath . scalahw/ListExamplesTest.scala -- > scalahw.ListExamplesTest > > from the parent directory of scalahw, but this gives this error: > > 12 FAILURES! > delete_all(3, Nil) failed due to scala.tools.util.debug.AbortError: illegal > tree: scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ res$0.elem) > delete_all(3, List(3,4,3)) failed due to scala.tools.util.debug.AbortError: > illegal tree: scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ res$0.elem) > delete_all(3, List(1,2,3)) failed due to scala.tools.util.debug.AbortError: > illegal tree: scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ res$0.elem) > delete_all(1, List(1, 2, 3, 2, 1, 2, 3, 2, 1)) failed due to > scala.tools.util.debug.AbortError: illegal tree: > scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ > res$0.elem) > delete_all_b(3, Nil) failed due to scala.tools.util.debug.AbortError: > illegal tree: scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ res$0.elem) > delete_all_b(3, List(3,4,3)) failed due to scala.tools.util.debug.AbortError: > illegal tree: scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ res$0.elem) > delete_all_b(3, List(1,2,3)) failed due to scala.tools.util.debug.AbortError: > illegal tree: scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ res$0.elem) > delete_all_b(1, List(1, 2, 3, 2, 1, 2, 3, 2, 1)) failed due to > scala.tools.util.debug.AbortError: illegal tree: > scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ > res$0.elem) > delete_all_c(3, Nil) failed due to scala.tools.util.debug.AbortError: > illegal tree: scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ res$0.elem) > delete_all_c(3, List(3,4,3)) failed due to scala.tools.util.debug.AbortError: > illegal tree: scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ res$0.elem) > delete_all_c(3, List(1,2,3)) failed due to scala.tools.util.debug.AbortError: > illegal tree: scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ res$0.elem) > delete_all_c(1, List(1, 2, 3, 2, 1, 2, 3, 2, 1)) failed due to > scala.tools.util.debug.AbortError: illegal tree: > scalac.ast.Tree$ExtReturn(return/*evalAnnounce*/ > res$0.elem) Under Eclipse I ran the program as described in the Scala Eclipse plugin web page, by creating an item to run Scala as an *external* tool as described in the Test Example section of http://scala.epfl.ch/docu/eclipse/ You can also use and adapt the Makefile (if you have cygwin installed on a Windows machine). > If I write my own program and place it in the scalahw directory and package, > the command I used above works to run the program, so I assume that there > must be some special way to run the ListExampleTest program, but I don't > know what it is. The Makefile that comes with the homework files (in the directory src/scalahw) shows exactly what I did to test it. For ListExampleTest, I did (from the src/scalahw directory): scalac -classpath .. -d ../../bin *.scala ../testing/*.scala to compile the code. And to run it, I did: scala -classpath ../../bin scalahw.ListExamplesTest You used: > scalarun.bat -classpath . scalahw/ListExamplesTest.scala -- scalahw.ListExamplesTest I didn't try using scalarun, but when I tried using it as you suggest, I get exactly the same errors you do. I'm not sure why, as this seems to follow the documentation. Perhaps a bug report should be filed? However, if you go to the src directory and do: scalac -classpath . -d ../bin scalahw/ListExamplesTest.scala scala -classpath ../bin scalahw.ListExamplesTest it works fine. > By the way, there is a catch-22 on Eclipse: versions before 3.1 don't seem > to have the update feature under Help, and versions 3.1 and later don't seem > to work with the Scala plugin. How did you install the plugin in Eclipse > 3.0.2? I believe that Eclipse 3.0 itself doesn't have this feature but 3.0.2 does. So you should get 3.0.2 if you want to use Eclipse. Get it from: http://eclipse.org/downloads/index.php or more directly from: http://download.eclipse.org/eclipse/downloads/drops/R-3.0.2-200503110845/index.php Sorry for all the bother... this is what we get from being on the bleeding edge of technology. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------- From leavens@larch.cs.iastate.edu Sun Oct 30 15:48:42 2005 Date: Sun, 30 Oct 2005 15:48:42 -0600 (CST) From: Gary T. Leavens To: Dave Doty Cc: Ru He Subject: Re: Pattern matching in Scala functions Hi Dave, On Sun, 30 Oct 2005, Dave Doty wrote: > Here's a tricky one. I want an anonymous function that takes a single > argument which is a Pair[Person,Book]. However, the natural thing to try > doesn't work: > > Pair(per,bk) => per > > I have to do this: > > pair: Pair[Person,Book] => pair._1 > > Is this really necessary? Yes, unfortunately. Scala doesn't do pattern matching automatically for every function definitions, just based on the form of formal parameters, as Haskell does. However, you could write: p => p match { case Pair(per,_) => per; /*...*/ } to do what you are trying to do if you want to use pattern matching. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------- From leavens@larch.cs.iastate.edu Mon Oct 31 09:20:38 2005 Date: Mon, 31 Oct 2005 09:20:38 -0600 (CST) From: Gary T. Leavens To: Kristina P Boysen Cc: Ru He Subject: Re: Getting the files for the homework into the Eclipse project Hi Kristina, On Mon, 31 Oct 2005, Kristina P Boysen wrote: > Ok, I tried using Eclipse again, and I'm having trouble understanding how to > get the packages to work. (This is in Eclipse 3.0.2). I've tried both > establishing a Scala project and importing just the src directory from the > zip file and establishing four projects with each of the sections within > them. Even if I cross-reference the projects, they don't seem to acknowledge > each other. For example, neither of the interp or interp2 packages recognize > the TestRunner from the package testing. How were you able to set all of > this up in Eclipse so that it worked? I would not have separate projects for Scala in Eclipse, that seems unnecessarily complicated. What I did was to first make a project in Eclipse (I called it ScalaDev), and then make a source directory, src. Then I copied the files by hand into the src directory, which you could do by unzipping from outside Eclipse and letting the files fall into eclipse/workspace/ScalaDev, which will put the packages inside src. Then I started Eclipse and did a refresh (from the File menu) on the ScalaDev project. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------- From leavens@larch.cs.iastate.edu Mon Oct 31 10:42:37 2005 Date: Mon, 31 Oct 2005 10:42:36 -0600 (CST) From: Gary T. Leavens To: Kristina P Boysen Subject: Re: Getting the files for the homework into the Eclipse project Hi Kristina, On Mon, 31 Oct 2005, Kristina P Boysen wrote: > At 09:20 AM 10/31/2005, you wrote: >> >> What I did was to first make a project in Eclipse (I called it >> ScalaDev), and then make a source directory, src. Then I copied the >> files by hand into the src directory, which you could do by unzipping >> from outside Eclipse and letting the files fall into >> eclipse/workspace/ScalaDev, which will put the packages inside src. >> Then I started Eclipse and did a refresh (from the File menu) on the >> ScalaDev project. > > Ok, I did that and it took care of some of the errors. Good. > I'm still getting > errors like in InterpreterTest.scala, it cannot find the type ExpTest, and > EOPLParsers cannot find type Parser. I didn't think this was part of the > homework to implement this, but I could be wrong... No, you have to implement both ExpTest and EOPLParsing to hook up to the testing. The trick is to make ExpTest parse with the new parser, which understands the new features. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------ From leavens@larch.cs.iastate.edu Tue Nov 1 22:55:39 2005 Date: Tue, 1 Nov 2005 22:55:39 -0600 (CST) From: Gary T. Leavens To: Kristina Boysen Cc: Ru He Subject: Re: Constructing Test Cases for Problem 3 Hi Kristina, On Tue, 1 Nov 2005, Kristina Boysen wrote: > In writing test cases for problem 3, I found out that I could get my test cases > for within and square root to work, but I could not get the ones for > approximations to work. I'm pretty sure the actual approximations function > works because it is used in square root, so I'm basically confused on how to > write the test cases for approximations. > > I translated the test cases presented in the homework to Scala code as well as I > could and came up with > > new Expect("approximations(1.0)(1.0).take(5)", > approximations(1.0)(1.0).take(5), > Stream.cons(1.0, Stream.cons(1.0, Stream.cons(1.0, Stream.cons(1.0, > Stream.cons(1.0, Stream.empty)))))) ... > > for the function defintion of > > def approximations(n: Double): Double => Stream[Double] = > iterate(next(n)); > > But if I run this, I get > > approximations(1.0)(1.0).take(5) > ==> Stream(1.0, ?) > EXPECTED: Stream(1.0, ?) > > I have no idea what the question mark means. I'm not even sure if I'm > constructing the new Stream correctly. I even tried defining > > val all1s: Stream[Double] = cons(1.0, all1s); > > with the same result. Any ideas? As you can see, there is no easy way to use the SUnit style Expect-based tests for approximations. I just print out several elements of the stream and eyeball them. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------- From leavens@larch.cs.iastate.edu Wed Nov 2 08:50:04 2005 Date: Wed, 2 Nov 2005 08:50:04 -0600 (CST) From: Gary T. Leavens To: Kristina Boysen Cc: Ru He Subject: Re: Understanding of Problem 4 Hi Kristina, On Wed, 2 Nov 2005, Kristina Boysen wrote: > (Hopefully this will be the last email on this section of the homework :) ). No problem. It's my fault for not making it clearer... > I'm attempting to understand problem 4 and its test cases. I've gotten some of > the tests to run correctly, but my program seems to be having trouble with the > recursive directory structure. Those are difficult to deal with in testing, certainly. > So let's see if I have this right... > > You have this definition root8::hd8::rushome::r541::gtlhome::g541::g342::Nil > that is a list of directories. I'm assuming this definition returns its > mapping, namely > > root1::hd::rushome::r541::gtlhome::g541::g342::Nil This definition: val (root8::hd8::rushome::r541::gtlhome::g541::g342::Nil): List[Dir] = { /* ... */ root1::hd::rushome::r541::gtlhome::g541::g342::Nil } does indeed define all the names root8, hd8, rushome, etc, in the same way as a Haskell pattern match binding would. > So let's take an interesting test case, say > > root8.fetch(List(dotdot, home)) eq hd8 > > Now from what I understand we want to use root8's mapping to follow the path > from dotdot to home and onwards. Yes. > root1 has a mapping to itself using dotdot, so > we consult root1's mapping for home. home points to hd...which does not seem > correct based on the test case going to hd8. But hd is a local name in the block that defines root8 and hd8. What is named hd locally in that block is really hd8 outside it (an alias). So the test case is correct. > Other than that, I'm not sure I understand why you are defining the def > > root8::hd8::rushome::r541::gtlhome::g541::g342::Nil > > in that way or even what it means. I'm really confused, so can you shed some > light on the meaning of all of this? It's defining all those names at once (as mentioned above). Like the Haskell binding: let (x:y:xs) = zs in E defines a binding for x, y, and xs by pattern matching. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------- From leavens@larch.cs.iastate.edu Wed Nov 2 22:31:44 2005 Date: Wed, 2 Nov 2005 22:31:44 -0600 (CST) From: Gary T. Leavens To: Dave Doty Cc: Ru He Subject: Re: testing code Hi Dave, On Wed, 2 Nov 2005, Dave Doty wrote: > Are there directions somewhere on how to use the Unit testing package? The > classes that you used, ConsoleTestRunner and Expect, do not appear anywhere > in the Scala API documentation online, nor do they turn up in a search of > the Scala Reference manual pdf file. Since there are no example tests in > your own code that use the Unit testing framework to test floating-point > values, I cannot figure out how to do this, besides using the ExpectTrue > class you used in FSEntityTest and writing the floating-point test myself as > a boolean expression. Sorry for the confusion about these. The classes that you mentioned are all in the testing package, which is in the src directory of files available for the homework. I included comments with them. If you have questions after looking at them that are unclear, please let me know. There are examples of how to use these classes both in the tests for the homework (src/*/*Test.scala) and in the samples of Scala code I have made available from the course web page. For testing the floating point numbers, I think using ExpectTrue is fine, and you can write a boolean-valued expression that says that the result should be close enough to the right answer to within some epsilon. For the floating point problems, you could also just print out numbers and look at them to see that they are right. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------- From leavens@larch.cs.iastate.edu Wed Nov 2 22:46:45 2005 Date: Wed, 2 Nov 2005 22:46:45 -0600 (CST) From: Gary T. Leavens To: hming@cs.iastate.edu Cc: Ru He Subject: Re: Two questions on Q1 of hw4 Hi Ming, On Wed, 2 Nov 2005 hming@cs.iastate.edu wrote: > I have two questions which I want to confirm wrt question1: > > 1. you said, at the end of quetion1 "To test ...scala.ListExamplesTest,..." I > guess what you meant is scalahw.ListExamplesTest. Right? Yes. I'll fix that. Thanks. > 2. in your file ListExamplesTest.scala in package scalahw, you had: > > package ... > > import ListExamples._; > import testing._; > > Did you mean "import ListExamples.scala"? instead? Since I didn't find any > package named "ListExamples". No, you don't import file names in Scala. You import names from namespaces, which can be packages, but also objects (in this case). The import ListExamples._; means to import all the top-level names from the object ListExamples, i.e., all the delete_all names, and make them available, so you can call them with just their names, like delete_all, instead of writing ListExamples.delete_all. > I eventually get eclipse work well. But it seems that 3.1 is OK. Hopefully > eclipse will not bug me anymore... But maybe it's a fun bug. Good, what did you have to do to make it work? Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------- From leavens@larch.cs.iastate.edu Mon Nov 7 10:55:57 2005 Date: Mon, 7 Nov 2005 10:55:57 -0600 (CST) From: Gary T. Leavens To: Jonathan Bentz Cc: Ru He Subject: Re: emacs scala syntax Hi Jonathan, On Mon, 7 Nov 2005, Jonathan Bentz wrote: > How do you get the scala syntax highlighting enabled using emacs? I have the following in my emacs initialization: ;;; Scala program mode (load "scala-mode-auto" t) I also put the Scala emacs files on my emacs load-path, as otherwise the above won't have any effect. I did this by copying the files into the equivalent of /usr/local/emacs on my computer. But putting their location on your emacs load-path or copying them to such a directory would work. Use something like the following: ;;; Files mentioned below are found in "~/emacs", "/usr/local/emacs", ;;; or "c:/cygwin/usr/unsup/emacs". ;;; This means if you're looking for leavens's files, ;;; they are in ~leavens/emacs. For example, for user leavens, ;;; (load "mode-customizations") loads the file whose source is in ;;; ~leavens/emacs/mode-customizations.el ;;; (setq load-path (cons "~/emacs" (append load-path (list (if (eq system-type 'windows-nt) "c:/cygwin/usr/unsup/emacs" "/usr/local/emacs"))))) My emacs files are available from my web site also. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------ From leavens@larch.cs.iastate.edu Mon Nov 7 17:55:37 2005 Date: Mon, 7 Nov 2005 17:55:37 -0600 (CST) From: Gary T. Leavens To: Dave Doty Cc: Ru He Subject: Re: parser Hi Dave, For the parsers, I followed the general outline in chapter 14 of Scala by Example. I suggest reading that first. On Mon, 7 Nov 2005, Dave Doty wrote: > Dr. Leavens: > > Can you explain how the parser you are using works? I have tried to > reverse-engineering it, but I already have a very shaky grasp of how Scala > itself works, and I really don't know what's happening in the file > EOPLParsers.scala. In particular, I have determined that this code: > > def number: Parser[Expression] = > for (val s: String <- nextToken(); s.matches("[0-9]+")) > yield LitExp(new java.lang.Long(s).longValue()); > > def identifier: Parser[Expression] = > for (val s: String <- nextToken(); s.matches("[^0-9].*")) > yield VarExp(new Symbol(s)); > > def primitiveApplication: Parser[Expression] = > for (val rator: Primitive <- primitive; > val _ <- check("("); > val rands: List[Expression] <- separatedList(expression, ","); > val _ <- check(")")) > yield PrimAppExp(rator, rands); > > is the way that you are parsing numbers, identifiers, and primitive > applications from the source code, and so I am trying to base how I will > parse an if statement on this. However, I don't understand how this works at > all. Why are these methods returning Parsers? Because that's what you want, a parser. A parser is defined as a type that takes an input and produces some pair of an output (in this case an Expression tree) and the remaining input. > Shouldn't a parser take a > String as input and return a computation tree (which, in our case, will be > an expression)? Yes, that's what the type alias Parser is. > What in the world is that last for comprehension doing? It > doesn't look anything like the examples in the Scala documentation. The code: def primitiveApplication: Parser[Expression] = for (val rator: Primitive <- primitive; val _ <- check("("); val rands: List[Expression] <- separatedList(expression, ","); val _ <- check(")")) yield PrimAppExp(rator, rands); is parsing a primitive and binding that to rator, checking to see that the next token is "(", parsing the list of operands and binding that to rands, and then checking that the next token is ")". There are similar examples in chapter 14 of Scala by example (see page 115 for example). > Also, I will have to miss class Tuesday, so I might be in your office later > asking about stuff you talk about Tuesday. Ok. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ----------------------- From leavens@larch.cs.iastate.edu Mon Nov 7 18:04:50 2005 Date: Mon, 7 Nov 2005 18:04:50 -0600 (CST) From: Gary T. Leavens To: Kristina Boysen Cc: Ru He Subject: Re: Interpreter problem Hi Kristina, On Mon, 7 Nov 2005, Kristina Boysen wrote: > I did finally get part of the tests to run by extending the interpreter more > like you suggested. Ok. Good. > However, the "if then else" part doesn't seem to work > correctly (still getting "key not found" errors), and I'm not sure why. This is probably because the parser isn't hooked up correctly (see below) > The interpreter for the if statement seems correct. ... Yes, your code for that seems fine to me. > I'm also pretty sure that the parser in interp2.EOPLParsers is correct as well, > since each keyword needs to be checked in that order, with the expressions being > recorded between each. > > def ifExpression: Parser[Expression] = /* ... */ Yes, that definition of ifExpression as a parser seems fine. However, I bet that either: - you did not also override the production for "expression", or that - you didn't have expression call your ifExpression parser *before* making the super.expression call. That would make it work. > The only thing I could think of was the fact that calling evalProgram from > interp2's copy from the superclass was actually calling the superclass' copy of > it (which shouldn't be right since it's overridden in interp2). So I don't > think I have to include an overrided copy of evalProgram in interp2.Interpreter. > I tried anyway just to check myself, and this did not help. Yes. > Am I missing anything blatant here? I'll check EOPL tonight to see what they > did in Scheme form and let you know if I find an obvious mistake. I am pretty sure that the error is as I pointed out above. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------- From leavens@larch.cs.iastate.edu Tue Nov 8 11:06:58 2005 Date: Tue, 8 Nov 2005 11:06:58 -0600 (CST) From: Gary T. Leavens To: Jonathan Bentz Cc: Ru He Subject: Re: cs541 homework Hi Jonathan, On Tue, 8 Nov 2005, Jonathan Bentz wrote: > I'm doing problem 10 and I can read the url into a string but I'm > having trouble converting the string into an XML node. I scanned the > scala api but can't find a method to do this. Is there such a method? > Basically I read the contents of the web page and then I have a > String, but once I get there I'm not sure how to parse the string as > an XML document. I am going to show this in class today, but see the file http://www.cs.iastate.edu/~cs541/scala/src/scalaxml/CopyXMLFromURL.scala for an example of how to do this. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------- From leavens@larch.cs.iastate.edu Tue Nov 8 21:19:48 2005 Date: Tue, 8 Nov 2005 21:19:48 -0600 (CST) From: Gary T. Leavens To: Kristina Boysen Cc: Ru He Subject: Re: Problems with homework 4 problem 8 Hi Kristina, [After trying validation of homework output from a file, using the W3C validator service at http://validator.w3.org/] On Tue, 8 Nov 2005, Kristina Boysen wrote: > Did that, it still doesn't like it for some reason. It gives me errors around > the image tags about not specifying the alt attribute, but I don't believe you > specified it either. Right, I see that now. I guess alt is actually required. I'll have to add that... > Line 10 column 52: required attribute "alt" not specified. > > > > The attribute given above is required for an element that you've used, but you > have omitted it. For instance, in most HTML and XHTML document types the "type" > attribute is required on the "script" element and the "alt" attribute is > required for the "img" element. > > I'll try it on your document just in case when I have the chance. I tried it and it also seems like, besides the alt attribute, you need something like

...

around the images. I'm updating the homework to reflect this. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------- From leavens@larch.cs.iastate.edu Thu Nov 10 10:34:00 2005 Date: Thu, 10 Nov 2005 10:34:00 -0600 (CST) From: Gary T. Leavens To: Dave Doty Cc: Ru He Subject: Re: curried methods Hi Dave, On Thu, 10 Nov 2005, Dave Doty wrote: > If I have a List[String] called listStr, and I want to concatenate all the > elements using foldLeft, it seems I have to do this: > > (listStr foldLeft "")((x: String, y: String) => x+y); > > It doesn't compile if I do this: > > (listStr foldLeft "")(+); > > but I swear I have passed operators around as functions in other contexts. > Did I forget something? The trouble is that + is a method, not a function (i.e., not an object), hence it's sent to a String with one argument, and even .+ would make a curried function, which doesn't work here. This is shown pretty clearly by the following, which does work: object FoldTests with Application { def uncurry[A](f: A => A => A): (A,A) => A = (x: A, y: A) => f(x)(y); val listStr = "hi"::" "::"J"::"M"::"L"::Nil; val concatenated = (listStr foldLeft "") (uncurry[String](.+)); Console.println(concatenated); val listInt = 1::2::3::4::Nil; val summed = (listInt foldLeft 0) (uncurry[Int](.+)); Console.println(summed); } Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------