Re: counting nils in a list



On 14 Mar, 19:18, p...@xxxxxxxxxxxxxxxxx (Pascal J. Bourguignon)
wrote:
david <not...@xxxxxxxxx> writes:

i was inspired by this code from graham's acl:
[...]
to write a little program to generate forsythe edward notations.
i changed it a bit to make it work for my program.

now i try to write my own compress function to just
handle my particular case. thinking this will be easy
since i believe i understand the code above. and
also that will be simpler than a general compress
function. i also want to learn to design the recursive
function with car, cdr, and cons. so given a list like
'(nil nil B nil nil nil |k| nil)
i want it to return (2B3k1)
my usual approach of typing at the repl until something
works has failed me. i need a better design methodology.
all thoughts, comments, flames appreciated.
thanks, david

You can start from the result you want: <some result>
What is it?  How can you get it?

It is <some description>
We can get it using the function <some funcs>

DONE.

Yes, really!

I can see you don't believe me.  Check it:

<some test>

We just need now to compute value of the symbol <some result>
What is it?  How can you get it?

<snip>

So all we have to do now is code up Pascal's algorithm as a macro
and we'll never have to work again...


In conclusion: it's really quite simple, you only have say what result
you need, to define and describe it precisely, then to determine how
you can get it from some intermediary results and simple operation,
and to repeat until the intermediary results are actually the input
parameters.  During all the process, you can check the chunks of code
you have so far work, applying them on a few example of intermediary
results.

It is also possible to start from the input parameters, and step by
step try to produce the end results, but it is often easier to do the
reverse.

way cool!

.