Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > forth and RPN/RPL
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 4th April 07:03
alain mellan
External User
 
Posts: 1
Default forth and RPN/RPL



All,

Are there any known attempts at writing an RPN (HP41-like) or RPL
(HP48-like) systems in Forth?

Does it make sense? Are there any semantic incompabilities? (I'm no Forth
expert)

-- alain.
  Reply With Quote


  sponsored links


2 4th April 15:54
andrew haley
External User
 
Posts: 1
Default forth and RPN/RPL



Forth already uses RPN, and you can use it interactively like an HP
calculator.

The classic paper on RPL is [1]. Internally, RPL is like Forth but
each operand on the stack is tagged with its type, and dispatching
depends on that type. Effectively, the inner interpreter is that of
classical Forth plus one level of indirection. The other key
component is the garbage collector, because memory allocation and
reclamation in RPL is automatic. Given these two things, you'd then
have to extend the language to add vectors and arrays and matrices and
so on. It's a pretty big library, and I suspect writing all that code
would be a much bigger job than the language.

Andrew.

[1] Wickes, W. C. (1988). RPL: A mathematical control language. In
Proc. Rochester Forth Conf. on Programming Environments, Rochester,
NY, pp. 27-32. Institute of Applied Forth Research.
  Reply With Quote
3 4th April 20:15
alain mellan
External User
 
Posts: 1
Default forth and RPN/RPL


Great. Thanks. There are a few things though in RPL that are not purely postfix, like IF..THEN..ELSE.


Couldn't find the paper online. Anybody cares to email it to me?

-- alain.
  Reply With Quote
4 4th April 20:16
doug hoffman
External User
 
Posts: 1
Default forth and RPN/RPL


There is quite a bit in ANS Forth that is not postfix. Most notably
using TO for LOCALS and VALUEs. Not to mention most defining words
where the name (the input) precededes the operator.

I don't think that being "purely" postfix is a Forth requirement.

Regards,

-Doug
  Reply With Quote
5 4th April 20:16
doug hoffman
External User
 
Posts: 1
Default forth and RPN/RPL


There is quite a bit in ANS Forth that is not postfix. Most notably
using TO for LOCALS and VALUEs. Not to mention most defining words
where the name (the input) precedes the operator.

I don't think that being "purely" postfix is a Forth requirement.

Regards,

-Doug
  Reply With Quote
6 4th April 20:16
doug hoffman
External User
 
Posts: 1
Default forth and RPN/RPL


There is quite a bit in ANS Forth that is not postfix. Most notably
using TO for LOCALS and VALUEs. Not to mention most defining words
where the operator (the defining word) precedes the name (the input).
I don't think that being "purely" postfix is a Forth requirement.

Regards,

-Doug
  Reply With Quote
7 5th April 00:20
andrew haley
External User
 
Posts: 1
Default forth and RPN/RPL


That's true -- Forth has always used whatever form, prefix or postfix,
seemed easiest/most natural at the time. Forth isn't about purity.

Andrew.
  Reply With Quote
8 5th April 05:26
alain mellan
External User
 
Posts: 1
Default forth and RPN/RPL


Pardon my ignorance in forth, but I thought that user-defined words were
strictly postfix, while the language include things like ':', 'variable'
etc that are not, as you mentioned, postfix. Is it the case?

While we're at it: is it possible in forth to write something that would
be like a macro in Lisp/Scheme?

-- alain.
  Reply With Quote
9 5th April 05:26
doug hoffman
External User
 
Posts: 1
Default forth and RPN/RPL


No. User defined words ( or "language" words -- see below) can by
either infix or postfix. But I think it is a fair generalization to
say that the typical Forth program has a definite postfix flavor to it.
By the way, in Forth there is no difference between "language" words
and "user defined" words. That's part of the beauty and power of Forth.

I have no knowledge of Lisp/Scheme. Perhaps someone else can answer.

Regards,

-Doug
  Reply With Quote
10 5th April 09:40
elizabeth d rather
External User
 
Posts: 1
Default forth and RPN/RPL


As Doug says, there's no distinction in Forth between user-defined words and
"language" words. Conventionally, words expect numeric arguments on the
data stack, which implies a post-fix order, but text strings are parsed by
reading forward in the input stream. This means that all defining words (of
which : and VARIABLE are examples) are followed by the name of the word
being defined. Consider the defining word CONSTANT:

1000 CONSTANT BIG

The word CONSTANT expects a numeric argument on the stack, 1000 in this
case, and defines a word, named BIG in this case. When BIG is executed, it
will return the value 1000.

Users can add defining words, and they will follow a similar convention.

Well, I don't know anything about Lisp or Scheme, but one can make macros in
Forth. For example:

: DOUBLE ( -- ) POSTPONE DUP POSTPONE + ; IMMEDIATE

When DOUBLE is encountered (presumably inside a colon definition), it will
comjpile references to DUP and + . There's no particular advantage in doing
this, though, and it isn't done often. The major use of it is to make
custom flow-of-control words, and that's a need that crops up fairly rarely.
But you could, if you wished, define:

: -IF ( -- src ) POSTPONE 0= POSTPONE IF ; IMMEDIATE

Cheers,
Elizabeth

--
==================================================
Elizabeth D. Rather (US & Canada) 800-55-FORTH
FORTH Inc. +1 310-491-3356
5155 W. Rosecrans Ave. #1018 Fax: +1 310-978-9454
Hawthorne, CA 90250
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666