Main Page | Report this Page
 
   
Computers Forum Index  »  Computer Languages (Misc)  »  Minimum stack operations
Page 1 of 1    
Author Message
Wildhalcyon
Posted: Fri Jan 07, 2005 2:42 am
Guest
I've been looking at the various language specifications for Forth,
Joy, etc trying to figure out what the minimal operators are that can
be combined to form an entire set of operators (if desired).
I think, for Forth, a minimal list would be:
drop
depth
dup
roll
-roll

assuming that : swap 2 roll would correctly swap the top two stack
values. Im pretty sure that every other stack operation can be
performed from this set. Can anyone confirm this?
Arthur J. O'Dwyer
Posted: Fri Jan 07, 2005 5:38 pm
Guest
On Thu, 6 Jan 2005, Wildhalcyon wrote:
Quote:

I've been looking at the various language specifications for Forth,
Joy, etc trying to figure out what the minimal operators are that can
be combined to form an entire set of operators (if desired).
I think, for Forth, a minimal list would be:
drop [discard top of stack; $ in Befunge]
depth [height of stack before this operation]
dup [duplicate TOS; : in Befunge]
roll [move Nth item to TOS and rotate others down]
-roll [?? I assume "move TOS to Nth position and rotate others up"]

assuming that : swap 2 roll would correctly swap the top two stack
values. Im pretty sure that every other stack operation can be
performed from this set. Can anyone confirm this?

Well, first you'd have to define "every other stack operation."
In the usual convention, the only "stack operations" are PUSH and
POP --- these two operations define everything about a stack that
makes it "stack-like."

I infer from the Web that once you have PICK and ROLL, you can
basically treat the stack as an array. So if we suppose that
your definition of "every other stack operation" is "array indexing,"
then all we need to do is define PICK in terms of ROLL, -ROLL and DUP:

PICK <= 1+ DUP ROLL /* move item a[N] to TOS */
DUP 3 ROLL /* move N+1 to TOS, above two copies of a[N] */
-ROLL /* move a[N] back to Nth position */

(Also note that DROP can be implemented as DUP - 1+ ROLL, using the
fact that 1 ROLL is a no-op.)

If this doesn't answer your question, try again. :)

HTH,
-Arthur
Wildhalcyon
Posted: Fri Jan 07, 2005 6:43 pm
Guest
Actually, it probably should behave more like a list - be able to
randomly add or remove elements anywhere in the stack. A traditional
stack does just have push and pop, but sometimes more may be needed.
That's the reason, Im guessing, that most stack-implemented languages
include more than just push and pop.
The other option is having the double-stack arrangement such as Joy,
which allows you to move items from the primary stack to a secondary
"helper" stack.
Wildhalcyon
Posted: Fri Jan 07, 2005 10:43 pm
Guest
fantastic! That's exactly what I was looking for, although I would have
never known that that was the actual theory I wanted. Thanks!
sa
Posted: Sat Jan 08, 2005 2:53 am
Guest
see brent kerby's "the theory of concatenative combinators":

http://tunes.org/~iepos/joy.html


"Wildhalcyon" <wildhalcyon@hotmail.com> wrote in message news:1105122972.040575.221460@z14g2000cwz.googlegroups.com...
Quote:
Actually, it probably should behave more like a list - be able to
randomly add or remove elements anywhere in the stack. A traditional
stack does just have push and pop, but sometimes more may be needed.
That's the reason, Im guessing, that most stack-implemented languages
include more than just push and pop.
The other option is having the double-stack arrangement such as Joy,
which allows you to move items from the primary stack to a secondary
"helper" stack.
Arthur J. O'Dwyer
Posted: Sat Jan 08, 2005 2:59 am
Guest
On Fri, 7 Jan 2005, Wildhalcyon wrote:
Quote:

Actually, it probably should behave more like a list - be able to
randomly add or remove elements anywhere in the stack.

Easily emulable by an array --- list insertion is just shifting
the first K elements up one position (toward the top of the stack) and
then array-inserting into the "new" position. List deletion is just the
reverse: shifting everything down one position.
(And of course you can emulate array-element replacement with one
list-insertion and one list-deletion, too.)

Quote:
A traditional
stack does just have push and pop, but sometimes more may be needed.
That's the reason, Im guessing, that most stack-implemented languages
include more than just push and pop.

Yes. With PUSH and POP and a finite number of registers, you have
only a "push-down automaton." To get a decent programming language,
you really want to have a "Turing machine" or "two-stack machine" (the
terms are equivalent). So most stack-based languages "cheat" by
giving you enough extra operations to form a "basis" in the sense
used in Kerby's article. (Befunge-93 cheats merely by giving you a
great big honking number of registers.)

Quote:
The other option is having the double-stack arrangement such as Joy,
which allows you to move items from the primary stack to a secondary
"helper" stack.

Yes, two stacks make a tape, which makes a Turing machine.
(I'm sure you don't care much about this particular aspect of the
theory; just thought I'd mention it. :)

And also, "sa" wrote:
Quote:
see brent kerby's "the theory of concatenative combinators":
http://tunes.org/~iepos/joy.html

/Very/ interesting article, there! I wonder, though, whether the
OP was really asking about models with these "quoting" and "execution"
semantics (Kind of like stack-based Lisp!). I think the basic ideas
apply to the simpler Befunge-like model I was using, where you don't
have the concepts of "quoting" or "executing programs from the stack,"
but I'm not entirely sure.

-Arthur
Wildhalcyon
Posted: Sat Jan 08, 2005 3:42 am
Guest
The article is still interesting, but Arthur is right, combinators are
not quite what I was looking for, but after reading enough of it, I
think I'm able to prove what I want satisfactorily enough for myself.

Big aside:
I'm developing a filtered version of Befunge that removes some of the
extraneous details (I've always disliked the ? - random vector -
operator, it bugs the bejeebus out of me), and I wanted to develop some
other paradigms, add a couple more stack operators so that the language
wouldn't have to rely on programming-space-storage ('a great big
honking number of registers'). Im working on 2D lambda calculus... but
I'm not sure how well it will work with the rest of the language, so I
might just write another, toy language, to cover that. We'll see.
Arthur J. O'Dwyer
Posted: Sat Jan 08, 2005 7:12 pm
Guest
On Fri, 7 Jan 2005, Wildhalcyon wrote:
Quote:

Big aside:
I'm developing a filtered version of Befunge that removes some of the
extraneous details (I've always disliked the ? - random vector -
operator, it bugs the bejeebus out of me),

Then don't use it. Wink I think it's only supplied because otherwise
anyone who wanted a PRNG in Befunge would have to write one, and that
could be quite tedious. And PRNG-based programs are quite popular in
toy languages, I've noticed. ;-)

Quote:
and I wanted to develop some
other paradigms, add a couple more stack operators so that the language
wouldn't have to rely on programming-space-storage ('a great big
honking number of registers').

(You know that Funge-98 actually gives the programmer a countably
/infinite/ number of registers, because Funge-space is infinite, right?
And IMLE it's very easy to simply "reserve" row 0 for data storage
stretching off to infinity, and that gives you the tape of a Turing
machine, or the linear address space of a "normal" computer. So I'm
not sure what else you could want.)
(Unless it's explicit support for recursion somehow. That would be
interesting, I think, if it were done well. But I can't immediately
think of any way to do it well. ;)

-Arthur
Wildhalcyon
Posted: Sat Jan 08, 2005 10:47 pm
Guest
Quote:
Big aside:
I'm developing a filtered version of Befunge that removes some of
the
extraneous details (I've always disliked the ? - random vector -
operator, it bugs the bejeebus out of me),

Then don't use it. Wink I think it's only supplied because
otherwise
anyone who wanted a PRNG in Befunge would have to write one, and that
could be quite tedious. And PRNG-based programs are quite popular in
toy languages, I've noticed. Wink

The reason I dont like it (and don't trust it) is that it's not
supposed to be a psuedo-random direction, but a RANDOM direction
(according to the Funge-98 specification), which is impossible, but the
specification gives no clear rules as far as what the PRNG that would
actually implement it should do (a RNG which counts 1, 2, 3, 4... is
still an RNG, just a very bad one), plus there's no rules or control
for seeding. I think RNGs should be more thoroughly implemented, and
yes, "toy" languages often develop PRNGs. It's hard not to view Befunge
or any funge for that matter as anything BUT a toy language, although
any languuage that could be turing complete shouldn't be viewed as a
toy language. BF, in all its ridiculous simplicity, is a pretty
interesting language from a theoretical point of view. I even heard of
someone trying to implement lambda calculus or combinator theory for
it... something.

Quote:
and I wanted to develop some
other paradigms, add a couple more stack operators so that the
language
wouldn't have to rely on programming-space-storage ('a great big
honking number of registers').

(You know that Funge-98 actually gives the programmer a countably
/infinite/ number of registers, because Funge-space is infinite,
right?
And IMLE it's very easy to simply "reserve" row 0 for data storage
stretching off to infinity, and that gives you the tape of a Turing
machine, or the linear address space of a "normal" computer. So I'm
not sure what else you could want.)
(Unless it's explicit support for recursion somehow. That would
be
interesting, I think, if it were done well. But I can't immediately
think of any way to do it well. Wink

Again, the Funge-98 spec says that the addressing range in each
direction should be the limit of the numbers represented by a single
cell. In a 32-bit befunge representation, the cell area per program is
limited to:
21,267,647,912,751,613,342,506,514,584,526,913,536 cells or roughly
2.1267*10^37 (thanks to the GMP for that number)
While not technically countably infinite, it's many orders of magnitude
over a mole of cells. It's more than any computer in the next decade
should be able to work with.
The method I'm attempting to employ actually uses an arbitrarily-sized,
finite-but-unbounded plane. One could still use the programming-space
storage technique, and in some cases one ought to use it (function
static variables for instance), but now its not necessarily manditory.
This part of the language isn't terribly complete yet, so I could just
nix the stack operators and utilize the two-stack method, or just use
programming-space storage, since it's still an option.
Arthur J. O'Dwyer
Posted: Sat Jan 08, 2005 11:49 pm
Guest
On Sat, 8 Jan 2005, Wildhalcyon wrote:
Quote:

Big aside:
I'm developing a filtered version of Befunge that removes some
of the extraneous details (I've always disliked the ? - random
vector - operator, it bugs the bejeebus out of me),

Then don't use it. Wink I think it's only supplied because
otherwise anyone who wanted a PRNG in Befunge would have to write
one, and that could be quite tedious. And PRNG-based programs
are quite popular in toy languages, I've noticed. ;-)

The reason I dont like it (and don't trust it) is that it's not
supposed to be a psuedo-random direction, but a RANDOM direction
(according to the Funge-98 specification),

(I put that down to sloppy terminology.)

Quote:
which is impossible,

I claim "north" is a random direction. Prove to me it isn't. :)

Quote:
but the specification gives no clear rules as far as what the PRNG
that would actually implement it should do (a RNG which counts 1, 2,
3, 4... is still an RNG, just a very bad one), plus there's no rules
or control for seeding.

This is the same model followed by C and C++, except that they
provide a black-box routine for seeding the PRNG as well. IMNSHO,
this is actually a /good/ thing. Suppose you specify that your
language will mandate a Mersenne Twister PRNG. Murphy's Law states
that three months after your first gamma release, somebody will
discover a flaw in Mersenne Twisters and you'll have to scrap that
part of your standard. With the C "black-box" model, the language
remains unchanged --- you just tell everyone to watch out for obsolete
implementations, and get on with the more important things.

In fact, as it stands, there's nothing preventing a Funge
implementation from using *real* random numbers for '?', instead of
pseudo- ones. There are plenty of online sources of randomness,
plus /dev/urandom on *nix machines. No reason to rely on any
particular PRNG at all!

Quote:
I think RNGs should be more thoroughly implemented, and
yes, "toy" languages often develop PRNGs. It's hard not to view Befunge
or any funge for that matter as anything BUT a toy language, although
any languuage that could be turing complete shouldn't be viewed as a
toy language. BF, in all its ridiculous simplicity, is a pretty
interesting language from a theoretical point of view.

"Interesting" and "toy" are not incompatible designations, as any
child will tell you. ;)


Quote:
(You know that Funge-98 actually gives the programmer a countably
/infinite/ number of registers, because Funge-space is infinite,
right? And IMLE it's very easy to simply "reserve" row 0 for data
storage stretching off to infinity, and that gives you the tape of a
Turing machine, or the linear address space of a "normal" computer.
So I'm not sure what else you could want.)

Again, the Funge-98 spec says that the addressing range in each
direction should be the limit of the numbers represented by a single
cell.

But the Lahey-space model in the Appendix works with infinite volumes,
and the possibility of "infinity" bytes per cell [sic] is explicitly
mentioned in the text for the 'y' instruction. 'Sides, I think infinity
is more elegant.

"ruhtrA-">#,_@
Wildhalcyon
Posted: Sun Jan 09, 2005 1:44 am
Guest
Quote:
This is the same model followed by C and C++, except that they
provide a black-box routine for seeding the PRNG as well. IMNSHO,
this is actually a /good/ thing. Suppose you specify that your
language will mandate a Mersenne Twister PRNG. Murphy's Law states
that three months after your first gamma release, somebody will
discover a flaw in Mersenne Twisters and you'll have to scrap that
part of your standard. With the C "black-box" model, the language
remains unchanged --- you just tell everyone to watch out for
obsolete
implementations, and get on with the more important things.

In fact, as it stands, there's nothing preventing a Funge
implementation from using *real* random numbers for '?', instead of
pseudo- ones. There are plenty of online sources of randomness,
plus /dev/urandom on *nix machines. No reason to rely on any
particular PRNG at all!

Im not disadvocating the black-box model, I just think it's an
instruction that is poorly outlined and implemented. Black-boxes are
great, I love them, and use them when I can in the code that I write. I
just think that an instruction that can so explicitly be rewritten in
terms of other functions, combined with the fact that there are
numerous possible implementations of it, should be removed. Im not
saying it MUST be, that it's bad and evil, it's just something that
I've always disliked about Befunge, and probably always will dislike
about it, however much the rest of the language is amazing.

Quote:
I think RNGs should be more thoroughly implemented, and
yes, "toy" languages often develop PRNGs. It's hard not to view
Befunge
or any funge for that matter as anything BUT a toy language,
although
any languuage that could be turing complete shouldn't be viewed as
a
toy language. BF, in all its ridiculous simplicity, is a pretty
interesting language from a theoretical point of view.

"Interesting" and "toy" are not incompatible designations, as any
child will tell you. Wink

Good point, but by the same token, just about any programming language
can be used as a "toy", so what definition are you looking for?

Quote:
(You know that Funge-98 actually gives the programmer a
countably
/infinite/ number of registers, because Funge-space is infinite,
right? And IMLE it's very easy to simply "reserve" row 0 for data

storage stretching off to infinity, and that gives you the tape of
a
Turing machine, or the linear address space of a "normal"
computer.
So I'm not sure what else you could want.)

Again, the Funge-98 spec says that the addressing range in each
direction should be the limit of the numbers represented by a
single
cell.

But the Lahey-space model in the Appendix works with infinite
volumes,
and the possibility of "infinity" bytes per cell [sic] is explicitly
mentioned in the text for the 'y' instruction. 'Sides, I think
infinity
is more elegant.

Good point. Hadn't read that part closely enough I suppose. I knew
about the Lahey-space model, and it works fine with the implementation
that I've used as well. Either way works fine, I think, and the fact
that both could use a "reserve" row for data storage I think proves
that the language Im designing is turing complete, provided everything
else with it works.
sa
Posted: Sun Jan 09, 2005 12:41 pm
Guest
you might want to look at brent's reversible funge-like language,
Befreak:

http://tunes.org/~iepos/befreak.html

and here, for an implementation in k:

http://www.nsl.com/papers/befreak.htm


"Wildhalcyon" <wildhalcyon@hotmail.com> wrote in message news:1105135005.950381.90600@z14g2000cwz.googlegroups.com...
Quote:
fantastic! That's exactly what I was looking for, although I would have
never known that that was the actual theory I wanted. Thanks!
Wildhalcyon
Posted: Sun Jan 09, 2005 4:45 pm
Guest
Befreak is nice, I found that when I was looking for more information
on Pingpong (there does not appear to be any). Actually, aside from
Befunge, the two languages Ive worked closest to are Muriel and B.
 
Page 1 of 1       All times are GMT
The time now is Tue Jan 06, 2009 9:27 pm