From leavens@larch.cs.iastate.edu Sun Feb 6 21:07:14 2005 Date: Sun, 6 Feb 2005 21:07:14 -0600 (CST) From: Gary T. Leavens To: Adam Nelson Cc: Com S 342 TAs -- Brian Patterson , Daniel Patanroi Subject: Re: Homework 3 Question 4 Hi Adam, On Sun, 6 Feb 2005, Adam Nelson wrote: > How do you set up the define statement for an unknown number of arguments as > in question 4? > > IE in the statement: > (define append* (lambda (???) > what would be put in the place of the question marks? You have to use the form (define append* (lambda args ; code here that uses args as a list ...)) See also the R^5RS which says about procedure formals in the section on procedures: " should have one of the following forms: * ( ...): The procedure takes a fixed number of arguments; when the procedure is called, the arguments will be stored in the bindings of the corresponding variables. * : The procedure takes any number of arguments; when the procedure is called, the sequence of actual arguments is converted into a newly allocated list, and the list is stored in the binding of the ." This last syntax for formals is the one you want for this problem. 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 Feb 7 14:26:09 2005 Date: Mon, 7 Feb 2005 14:26:09 -0600 (CST) From: Gary T. Leavens To: Adam Nelson , Brian Patterson Cc: Daniel Patanroi Subject: Re: Homework 3 Question 5 Hi Brian, Adam, Sorry I didn't see your query earlier, Adam. Brian's answer is right, but I have one technical quibble with it. The first argument to append-map is a procedure of type (-> (S) (list-of T)), which means that it takes an argument of type S and returns a list of values of type T. It can't return an arbitrary type, but has to return a list type. otherwise, Brian's answer, including examples is exactly right. Thanks, Brian. On Mon, 7 Feb 2005, Brian Patterson wrote: > Append-map takes two arguments: A function from type S to type T and a list > of Ss. So, for example, you need to give append-map a function and > append-map should run that function on each element of the list. So, an > example input if S is integers and T is booleans is a function that checks if > each element of the list is equal to 3, returning a list of just n if not and > a null list otherwise applied to a list of numbers. So the two inputs are > > (lambda (n) (if (= n 3) '() (list n))) > > and > > '(3 4 2 3 7) > > so > > (append-map (lambda (n) (if (= n 3) '() (list n))) '(3 4 2 3 7)) > > returns > > (4 2 7) > > as the null lists get appended into the list of non-3 items. So there are > only two arguments and your function should start (define append-map (lambda > (f lst) .... ) with f being a function you use later on elements of lst. The > main point of this problem (as opposed to problems 3 and 4) is using a > passed-in function to do stuff. > > Brian > > On Feb 7, 2005, at 12:18 PM, Adam Nelson wrote: > >> I don't understand what append-map is looking for. I understand that the >> list- >> of-S is the initial list, but I don't understand what the other two >> arguments >> are for. 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 ---------------------------