I got this email today from a student who has given up. It would be
useful for you all to see the answer. Read the email (and the attached
image) before reading the response.
Answer:
Your inability to read and understand the assignment is not
necessarily a problem with the assignment. It is not even a compelling
argument given the number of students who have understood the parts
you comment on without any advice from me.
In your commentary on =fail, for instance, you have a long winded
explanation of failure and claim that "I had to infer it all from the
sentence \"Never succeeds\"" However, your sentence is almost
identical (modulo confusing verbiage) to the paragraph that starts "A
failure-continuation? is ...". In particular you divide up the
definition of failure into two cases, backtracking and total failure.
This is the exact same definition in the cited paragraph on the
assignment page. Regurgitating (poorly) a sentence from the assignment
is not an "inference" that you made from one sentence.
Second, to help you see the error of your ways, let's just look at the
types involved in =fail.
The assignment says:
=fail : prolog-expression?
prolog-expression? : failure-continuation? -> success-continuation?
failure-continuation? : anything -> doesn't return, but FAILS [recall
that continuations don't return, a basic fact from October]
success-continuations : anything -> doesn't return, but TRIES AGAIN
Based solely on this information, you can trivially expand the type of =fail:
=fail : failure-continuation? -> success-continuation?
=fail : (anything -> doesn't return, but FAILS) -> success-continuation?
Now, if =fail "never succeeds" than by basic understanding of English,
that means it "Always and immediately fails". So, you have a function,
that takes one argument, that causes failure, and you want to fail.
Hmm, how could you possibility implement this?
Just to show you how absurd your argument is, let's just change all
the names and you'll see how trivial it is.
......
A printing expression is a function that takes a printing function and
returns a reading function.
A printing function is a function that takes an argument (that it
ignores) and prints something.
A reading function is a function that takes an argument (that it
ignores) and reads something.
=prints is a printing expression that never reads anything, and thus
always prints something.
Expressed as types:
PE : PF -> RF
PF : Any -> Prints
RF : Any -> Reads
=prints : PE
Thus
=prints : (PF -> RF)
=prints : (Any -> Prints) -> RF
=prints should print.
Simply by looking at the types alone, there is only one possible
implementation of =prints:
(define (=prints pf) (pf "anything"))
There's no other way to get a "Prints", so it must be this way.
=succeed, =and2, and =or2 can be written almost completely by looking
the types alone. The majority of errors that I see in my office when
people ask questions are people ignoring the types.
Jay
---------- Forwarded message ----------
From: A student
Date: Wed, Dec 5, 2012 at 4:18 PM
Subject: Re: Prolog
To: Jay McCarthy <
jay.mc...@gmail.com>
I've given up on this assignment. It's just completely broken me after
spending 12 hours just trying to figure out what "fail" means,
continuation-wise
And then doing the same for "success", "or", "and", and so forth. It's
getting old.
I'm kind of angry as you can tell so I probably shouldn't be writing
an email now, wait for it to cool off, etc, etc. but whatever.
You say that the everything for the assignment that we need to know is
"right there". Yes, it's right there, in the sense that everything we
want to know about Kolob is right there in the facsimiles of Abraham.
I've had a hard time expressing exactly in words why the assignment
descriptions are so infuriatingly vague and ambiguous, leaving us to
either spend hours trying to decipher them, or else going to the
oracle (you) to try and understand them (Hence, the party in your
office right now). I figure the best way to approach this would be
constructive criticism, so I'll give an example suggestion to try and
elucidate what I mean. Actually I'll just attach it as an image since
I don't know how html works. Maybe I'm just not seeing your principle
of "letting the students learn to figure things out on their own",
because most of the time I don't feel like I'm learning anything new
when I'm trying to decipher what you mean in these descriptions.
I guess I do have one other dumb suggestion, which would be to rewrite
this assignment to use the (amb) function and a global fail stack, but
then I know that would cause issues with recursion (overwriting a
single mutable stack) and universe of discourse issues (amb would
require a list of all possible values, already precalculated). So
that's shot down. I guess my point is, I understand that
implementation naturally, but I still have no idea what Prolog is
supposed to do. I was never able to grasp the big picture.
Regrettably yours
- The student
On Tue, Dec 4, 2012 at 9:25 PM, Jay McCarthy <
jay.mc...@gmail.com> wrote:
>
> Your =or2 is mostly right, but you can't discover the (small) error
> until you do find-some
>
> Sent from my iPhone
>
> On 2012/12/04, at 21:20, Logan Stromberg <
loganst...@gmail.com> wrote:
>
> > Can you at least tell me if this is right? I don't want to go back to
> > the drawing board but better sooner than later
> >
> > ;This value is returned if a fail has occurred
> > ;Should be (void)
> >
> > (define fail-value "FAIL")
> >
> > ;Define the falsum value to mark the "end" of an undelimited
> > continuation. This function is the final failure continuation in all
> > evaluation paths, and its invocation indicates that there is no possible
> > solution to the expression.
> >
> > (define falsum (λ (x) fail-value))
> >
> > ;A failure means it shifts control to the fail continuation by invoking it.
> >
> > (define úil (λ (fcont) (fcont 'an-ignored-value)))
> >
> > ;A succeed means that it returns a function, which, when invoked, will
> > try again (by failing). The function it calls when it tries again is the
> > failure continuation that was passed in when this....success
> > ...occurred....OH WHAT THE
> > ;The "success" is indicated by the fact that this function exists and it
> > is not void. This function stores the continuation which, when invoked,
> > will resume computation after the point the success occurred.
> > ;Probably. Don't think falsum should go here but then what else could?
> >
> > (define =succeed (λ (fcont) (λ (an-ignored-value) (fcont falsum))))
> >
> > ;INVOKING FAIL ON FALSUM RETURNS FAIL VALUE
> > ;This means "we have failed and there is nowhere else to go"
> >
> > (test (úil falsum) fail-value)
> >
> > ;INVOKING SUCCEED GIVES A FUNCTION WHICH WILL THEN FAIL
> >
> > (test (procedure? (=succeed falsum)) #t)
> > (test ((=succeed falsum) falsum) fail-value)
> >
> > ;Use CPS to evaluate the lhs and rhs of an OR in sequence.
> > (define (=or2 expr1 expr2)
> > (λ (fcont) (expr1 (λ (an-ignored-value) (expr2 fcont))))
> > )
> >
> > -Logan