[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Mar 10 21:23:05 1994 
Subject:Re: Another Pop-11 style question: nexstates 
From:jlc (Jonathan Cunningham) 
Volume-ID:940310.06 

> > To generate the next-states, what is wrong with using
> >     for choice in available do
> >         delete(choice, available) -> remainder;
> >         ....
> > etc.?
>
> I forgot to say in my original that I had considered this, but felt
> it was confusing in relation to lists with repeated elements. You
> have to use delete(choice, available, 1) and then explain that it
> doesn't matter that with repeated items only the first occurrence would
> be deleted. This can be made non-visible by using a sorted list in the
> first place (perhaps you were assuming it was sorted), but people might
> be building up options in an order for some reason.

I was aware of this. The definition of -mydelete- does delete only one
element. Using the matcher, I don't know (or care) which one. I wasn't
assuming it was sorted. But for some reason, I thought it wasn't worth
mentioning because there wouldn't be any repeated elements .... don't
know why I was thinking that. The code would still work correctly even
with repeated elements using mydelete (unless the order mattered - but
using the matcher for these kinds of things feels too declarative for
the order to be important, if you know what I mean).

Rather than correcting the code to
    delete( choice, available, 1 )
I would prefer to correct it to
    delete( choice, available, nonop == )
This would also solve all your worries about the order in which
solutions were generated, and which element gets deleted with repeated
elements. Unfortunately, this won't work with simple integers. You would
have to make a new class, and define addition and (non strict) equality
for the class. In some ways that would be much better from the point of
view of teaching good programming style, but probably much worse from
the point of view of teaching anything about search.

You could always use one-element lists -
   [[3] [5] [5] [6]]
they look a bit like blocks too :-).

--jonathan