Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Task 6 - 2nd set of arguments when k is 3
#1
What can we expect the second set of arguments to be if k = 3? Open paren followed by close paren or nothing at all or...?
Reply
#2
(09-03-2017, 05:38 PM)I\m etberryhill Wrote: What can we expect the second set of arguments to be if k = 3? Open paren followed by close paren or nothing at all or...?

Say I have a function "f" that takes 0 arguments. I can call f these ways: (f) or (f ()).
UA ACM Vice President
ACM has bi-weekly meetings Tuesdays at 5:15pm
We're UA's best organization for CS majors (website)
Join us on Slack for all kinds of discussion channels (including one for CS403)
Reply
#3
(09-03-2017, 06:17 PM)davidmccoy Wrote: Say I have a function "f" that takes 0 arguments. I can call f these ways: (f) or (f ()).

(f) is very different from (f ()).
Reply
#4
(09-03-2017, 09:01 PM)lusth Wrote:
(09-03-2017, 06:17 PM)davidmccoy Wrote: Say I have a function "f" that takes 0 arguments. I can call f these ways: (f) or (f ()).

(f) is very different from (f ()).

So what can we expect to see in the situation of k = 3 for the second arguments?
Reply
#5
(09-03-2017, 09:01 PM)lusth Wrote:
(09-03-2017, 06:17 PM)davidmccoy Wrote: Say I have a function "f" that takes 0 arguments. I can call f these ways: (f) or (f ()).

(f) is very different from (f ()).

Yeah, that's right.

Still, I think the intent is that, if k = 3, we produce a function that takes no arguments. I don't know how readExpr evaluates "()", but it seemed to work if I did
Code:
echo "()" >> task6.args

As this line evaluated correctly:
Code:
(define f3 (apply f2 third))

Where f2 was a function that took no arguments.

Code:
Welcome to the Scam Interpreter! To exit, enter <Ctl>-D, q, or quit
scam> (define (main)
more> (setPort (open "arg.args" 'read))
more> (inspect (readExpr))
more> )
<function main()>
scam> (main)
(readExpr) is nil

Apparently it evaluates to nil. I'm not sure why you can call a function that takes no parameters with (apply function nil).
UA ACM Vice President
ACM has bi-weekly meetings Tuesdays at 5:15pm
We're UA's best organization for CS majors (website)
Join us on Slack for all kinds of discussion channels (including one for CS403)
Reply
#6
(apply f ()) is very different from (f ()).
Reply
#7
(09-03-2017, 10:41 PM)lusth Wrote: (apply f ()) is very different from (f ()).

I guess (apply f nil) is passing in 0 arguments into f, while (f ()) is passing in 1 argument, an empty list (or something similar). It seems it would be appropriate to be defining f2 as a function that takes in 0 parameters if we are calling f2 as defined in task 6's description.
UA ACM Vice President
ACM has bi-weekly meetings Tuesdays at 5:15pm
We're UA's best organization for CS majors (website)
Join us on Slack for all kinds of discussion channels (including one for CS403)
Reply
#8
(09-03-2017, 05:38 PM)etberryhill Wrote: What can we expect the second set of arguments to be if k = 3? Open paren followed by close paren or nothing at all or...?

According to the task description, the function given to pfa is said to take in n arguments; however, the number n is never specified. Presumably, all we can assume is that
n >= k. This means that, just because k = 3, it does not mean that the function given to pfa does not need to take in any more arguments. In other words, the second set of arguments can either be 0 arguments or 1 argument or 2 arguments or etc.

So, how do we return a function that will take in any non-negative number of arguments? We use @. More specifically, we put a @ in the returned function's parameter list when we define it.

In short, we should have something like:
(pfa f k) which returns (lambda (a1 a2 .. ak) (...)) which returns (lambda (@) (...)).

[If anyone thinks I'm giving away too much, note that the line above is literally just what the task description says.]

Notes:
  • As discussed in another thread, you should note that k will only ever be 1, 2, or 3, so you can code pfa on a case-by-case basis. In fact, the grading procedure requires you to do so.
  • As stated in the task description, the final returned function must be variadic (must have an @ in its parameter list).
  • I could be wrong about anything discussed here. Use this information at your own peril.
Reply
#9
(09-04-2017, 12:08 AM)james_h Wrote:
(09-03-2017, 05:38 PM)etberryhill Wrote: What can we expect the second set of arguments to be if k = 3? Open paren followed by close paren or nothing at all or...?

According to the task description, the function given to pfa is said to take in n arguments; however, the number n is never specified. Presumably, all we can assume is that
n >= k. This means that, just because k = 3, it does not mean that the function given to pfa does not need to take in any more arguments. In other words, the second set of arguments can either be 0 arguments or 1 argument or 2 arguments or etc.

So, how do we return a function that will take in any non-negative number of arguments? We use @. More specifically, we put a @ in the returned function's parameter list when we define it.

In short, we should have something like:
(pfa f k) which returns (lambda (a1 a2 .. ak) (...)) which returns (lambda (@) (...)).

[If anyone thinks I'm giving away too much, note that the line above is literally just what the task description says.]

Notes:
  • As discussed in another thread, you should note that k will only ever be 1, 2, or 3, so you can code pfa on a case-by-case basis. In fact, the grading procedure requires you to do so.
  • As stated in the task description, the final returned function must be variadic (must have an @ in its parameter list).
  • I could be wrong about anything discussed here. Use this information at your own peril.

Based on a post of yours from earlier, it seems we should not be defining anything as variadic, since the parameter length is directly inspected in testing (and since we are given a function which we know will only take exactly three parameters).

Question for Lusth: if we're passing this test in the test1 box, do we have it right (I'm not defining it as variadic currently but I am passing)?
UA ACM Vice President
ACM has bi-weekly meetings Tuesdays at 5:15pm
We're UA's best organization for CS majors (website)
Join us on Slack for all kinds of discussion channels (including one for CS403)
Reply
#10
(09-04-2017, 12:22 AM)davidmccoy Wrote: Based on a post of yours from earlier, it seems we should not be defining anything as variadic, since the parameter length is directly inspected in testing (and since we are given a function which we know will only take exactly three parameters).

Question for Lusth: if we're passing this test in the test1 box, do we have it right (I'm not defining it as variadic currently but I am passing)?

There may be a misunderstanding here. There are two numbers to worry about, k and n.

The program I had written and discussed in that other thread worked for any k and any n >= k. It turns out that we only need to deal with k = 1, 2, or 3 and that we should deal with k on a case-by-case basis. However, n is still unbounded, so we must return a variadic function. In fact, it is stated explicitly in the task description.

From the task description:

Quote:Partial function application is the process of providing the first k arguments to a function that takes n arguments. The result is a new function that takes the remaining n - k arguments. Define a function, named pfa, that takes two arguments, a function to be partially applied and an integer specifying k. To make the task easier, k will limited to the values 1, 2, or 3. The pfa function will return a function that takes the k arguments. When called with the k arguments , the function that pfa returns will return a function that takes the remaining n - k functions. As an example, the last two expressions should evaluate to the same result:


  (define (f x y z) (+ x (* y z)))
  (f a b c)
  (((pfa f 2) a b) c)


The function that takes the remaining arguments will need to be variadic. You will also need to use the cons function and the apply function (the same function as found in your main function). Here are some examples of a variadic function using cons and apply:


In any case, I agree that there is a problem of ambiguity here.
It might be the case that Dr. Lusth expects that the parameter list length of the function that takes the remaining arguments to always be 1 since it is variadic.
It might also be the case that Dr. Lusth expects that the parameter list length of the function that takes the remaining arguments to be the value (n - k).

If it is the latter, then there is a problem, as it would contradict the task description.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)