Re: [stack] Code Transformation Problem (possibly monadic?)

"William Tanksley, Jr" <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
Christopher Diggins <[email protected]> wrote:
> Given the following sequence of instruction:
> a b m [c m d e] f g
> I want an automated transform (no matter how inefficient, it just has
> to be algorithmic) to rewrite the code so that each instruction
> applies to the stack below the top value, except for "m".

> The naive transformation would be:
> [a b m [c m d e] f g] dip
> However, we have a problem because the "m" instruction can't see the
> top of the stack.

Okay, I see what you want, kinda.

> The next obvious transformation (which doesn't work) would then be:
> [a] dip [b] dip m [[[c] dip m [d] dip [e] dip]] dip [f] dip [g] dip

The problem here -- or one of the problems here -- is that you're
diving into the quotation as though it were transparent. It's not;
it's a unit. So the "next obvious transformation" should actually be:

[a] dip [b] dip m [[c m d e]] dip [f] dip [g] dip

At this point, though, I have to stop and wonder what your problem
really means. When you say "each function applies to the stack below
the top value", do you mean what I just wrote, or do you mean that the
ENTIRE SEQUENCE ignores the value which was on the top just prior to
execution of the sequence, except for 'm', which for some reason sees
the value but doesn't destroy it (so that the next 'm' can also see
it)? That's a very complex semantics. Why do it?

However, here's a transform which appears to meet your request.

[a] dip [b] dip dup [m] dip [[c m d e]] dip [f] dip [g] dip

Note that each occurence of m is replaced by 'dup [m] dip', while all
the other words 'x' are replaced by '[x] dip'.

I still don't see why to do this, so I don't know if I'm violating
something by failing to break into the nested quotation.

> Christopher

-Wm
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.