Re: [stack] Re: Concatenative macros?

"William Tanksley, Jr" <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
[email protected] <[email protected]> wrote:
> [email protected] wrote on 02/09/2007 10:25:56 AM:
> > I wrote a Python interpreter, although I didn't even try to run it, so
> > it's probably severely broken. (My purpose was to explain this to a

> yes, by all means.

Included at the end of this post.

> as i mentioned to you privately a few days ago, i wrote the interpreter
> as a preliminary step to experimenting with a genetic algorithm (to find
> programs.)  as you pointed out at the beginning of this discussion,
> programs constructed in a flat, two-element language seem tailor-made
> for recombination operations.

Indeed.

Although I'm also interested in genetic systems, my main interest is
in understanding languages for use by humans. I'm not certain
(although I can sometimes hope) that perfectly flat languages will
ever be usable by humans (we and the people who write in Unlambda are
NOT humans, sorry), but I'm certain that I'm increasing my
understanding of languages :-).

> 01.k contains inner and outer interpreters.  the inner interpreter
> evaluates and produces binary sequences.  the outer interpreter takes
> strings using a vocabulary (e.g. zap, i, unit, &c.), deconstructs them
> into binary sequences, invokes the inner interpreter, then constructs
> strings in the vocabulary from the result.

Of course, the "outer interpreter" could also be implemented as a
"compiler" and "decompiler". I think this is a useful result of
flatness: any string always means the same thing, regardless of
context. (Of course, this also means that decompilations are not
unique.)

-Billy

-------- the "ok" 01 interpreter (untested):

def q(stack):
  a = stack.pop()
  b = stack.pop()
  stack.push( [[b]] )
  stack.push( [a, b] )
  return stack

def one(stack): # K combinator
  a = stack.pop()
  b = stack.pop() # throw away
  return Execute(a, stack)

def zero(stack):
  stack.push( list() )
  stack.push( list(q) )
  stack.push( list(one) )

# It's impossible to Execute anything that's not a list.
def Execute(fn, stack):
 for elem in fn:
    if elem instanceof list: stack.push(elem)
    else elem(stack)

# The heart of the system:
bits = raw_input("Input a string of 0s and 1s: ")
stack = []
for bit in bits:
  if bit == '0': zero(stack)
  else: one(stack)
print stack
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.