Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Languages Misc > Re: RPN maps to...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 35 of 55 Topic 1073 of 1203
Post > Topic >>

Re: RPN maps to basic mathematic expressions nicely

by Elizabeth D Rather <eratherXXX@[EMAIL PROTECTED] > Nov 17, 2007 at 03:30 PM

cr88192 wrote:
> "Marcel Hendrix" <mhx@[EMAIL PROTECTED]
> wrote in message 
....
> <snip, big ugly example>
> 
> I meant, in general, not that one go and find some ugly monstrosity in
an 
> attempt to prove a point (absent citing any comprable example, say, in 
> forth).
> 
> so, here is the challenge:
> find some forth/postscript/... programs that can perform the same task,
and 
> demonstrates comprable or greater readability, with well-written code in

> both languages.

Of course, to have a fair comparison you must stipulate that the reader 
has equal familiarity and experience with all the languages in 
competition.  Since postfix languages are in the minority, it's awfully 
easy for someone whose experience is mostly or entirely with the other 
kind to say postfix is "unnatural" or "unreadable".  It's also entirely 
true (as John Passaniti often points out) that languages are designed 
for certain intended uses, and will be prettiest in apps within that
sphere.

Forth was originally designed for what we now call embedded systems. 
So, I'll submit the following simple embedded-type application (which is 
being presented at Forth Day right now, as it happens), to send SOS in 
Morse code on an LED.

\ Hardware interface: LED control
\ This version assumes memory-mapped I/O, as on a M52235EVB (Coldfire).
\    I/O registers SETTC, CLRTC, and DDRTC are pre-defined.
\ Glossary:
\ +LED ( -- )   Turn the LED on.
\ -LED ( -- )   Turn the LED off.
\ /LED ( -- )   Perform hardware initialization for LED output

: +LED ( -- )   1 SETTC C! ;
: -LED ( -- )   $FE CLRTC C! ;
: /LED ( -- )   DDRTC C@[EMAIL PROTECTED]
 1 OR DDRTC C! -LED ;

\ Application part I, timing functions:
\ The speed of Morse code transmission is typically specified
\ in words per minute (WPM), and the timing for a dah (dash)
\ is conventionally 3 times as long as a dit (dot). The spacing
\ between dits and dahs within a character is the length of one dit;
\ between letters in a word it is the length of a dah; and between
\ words it is 7 dits.

\ The time for one "dit" can be computed by the formula:
\    Tu = 1200 / WPM

\ Tu holds the current value of one "dit" time. The default value of 120 
\    sets the initial rate at 10 WPM.
\ WPM sets Tu based on the formula above.
\ DELAY pauses for n dit times.
\ DIT and DAH control the LED with appropriate timing.

CREATE Tu 120 ,
: WPM ( n -- )   1200 SWAP / Tu ! ;
: DELAY ( n -- )   Tu @[EMAIL PROTECTED]
 * MS ;
: DIT ( -- )   +LED 1 DELAY -LED 1 DELAY ;
: DAH ( -- )   +LED 3 DELAY -LED 1 DELAY ;

\ Application part II, messages:

\ Only the letters S and O are required here.  Other letters, numbers,
\ etc., may be added as needed.

: S ( -- )   DIT DIT DIT 2 DELAY ;
: O ( -- )   DAH DAH DAH 2 DELAY ;
: SOS ( -- )   S O S  4 DELAY ;

\ Note that the 4 DELAY at the end of SOS adds to the 2 after
\ the last S and the 1 at the end of the last DIT to give
\ the correct inter-word delay of 7 dit times.

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."
==================================================
 




 55 Posts in Topic:
RPN maps to basic mathematic expressions nicely
"metaperl.com"   2007-11-11 12:50:24 
Re: RPN maps to basic mathematic expressions nicely
"Paul E. Bennett&quo  2007-11-11 13:06:24 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-12 09:25:56 
Re: RPN maps to basic mathematic expressions nicely
Marco van de Voort <ma  2007-11-12 09:21:48 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-12 21:40:58 
Re: RPN maps to basic mathematic expressions nicely
Marco van de Voort <ma  2007-11-12 11:46:48 
Re: RPN maps to basic mathematic expressions nicely
Jerry Avins <jya@[EMAI  2007-11-12 13:51:05 
Re: RPN maps to basic mathematic expressions nicely
Andrew Haley <andrew29  2007-11-12 11:39:14 
Re: RPN maps to basic mathematic expressions nicely
Jerry Avins <jya@[EMAI  2007-11-12 13:54:50 
Re: RPN maps to basic mathematic expressions nicely
stephenXXX@[EMAIL PROTECT  2007-11-16 17:49:33 
Re: RPN maps to basic mathematic expressions nicely
Andrew Haley <andrew29  2007-11-16 18:26:39 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-17 19:22:07 
Re: RPN maps to basic mathematic expressions nicely
mhx@[EMAIL PROTECTED] (M  2007-11-17 12:34:02 
Re: RPN maps to basic mathematic expressions nicely
Albert van der Horst <  2007-11-17 16:01:42 
Re: RPN maps to basic mathematic expressions nicely
Jerry Avins <jya@[EMAI  2007-11-17 13:37:04 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-18 08:39:07 
Re: RPN maps to basic mathematic expressions nicely
Richard Owlett <rowlet  2007-11-17 17:16:33 
Re: RPN maps to basic mathematic expressions nicely
mhx@[EMAIL PROTECTED] (M  2007-11-18 00:21:13 
Re: RPN maps to basic mathematic expressions nicely
mhx@[EMAIL PROTECTED] (M  2007-11-18 00:54:13 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-18 11:17:04 
Re: RPN maps to basic mathematic expressions nicely
Andrew Haley <andrew29  2007-11-18 17:50:04 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-19 07:48:22 
Re: RPN maps to basic mathematic expressions nicely
Andrew Haley <andrew29  2007-11-19 10:03:11 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-20 06:22:12 
Re: RPN maps to basic mathematic expressions nicely
Jerry Avins <jya@[EMAI  2007-11-19 15:39:14 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-20 08:33:48 
Re: RPN maps to basic mathematic expressions nicely
Jerry Avins <jya@[EMAI  2007-11-19 17:57:09 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-20 16:56:28 
Re: RPN maps to basic mathematic expressions nicely
Jerry Avins <jya@[EMAI  2007-11-20 11:58:40 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-21 07:13:13 
Re: RPN maps to basic mathematic expressions nicely
Jerry Avins <jya@[EMAI  2007-11-20 17:55:00 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-21 12:03:34 
Re: RPN maps to basic mathematic expressions nicely
Jerry Avins <jya@[EMAI  2007-11-20 21:34:26 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-21 14:24:44 
Re: RPN maps to basic mathematic expressions nicely
Elizabeth D Rather <er  2007-11-17 15:30:04 
Re: RPN maps to basic mathematic expressions nicely
anton@[EMAIL PROTECTED]   2007-11-18 09:48:12 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-21 09:43:55 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-22 13:52:20 
Re: RPN maps to basic mathematic expressions nicely
Elizabeth D Rather <er  2007-11-21 22:48:50 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-24 12:00:16 
Re: RPN maps to basic mathematic expressions nicely
stephenXXX@[EMAIL PROTECT  2007-11-24 14:31:22 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-25 08:20:06 
Re: RPN maps to basic mathematic expressions nicely
stephenXXX@[EMAIL PROTECT  2007-11-24 14:31:22 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-25 08:20:06 
Re: RPN maps to basic mathematic expressions nicely
"slava@[EMAIL PROTEC  2007-11-11 16:14:02 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-12 11:21:04 
Re: RPN maps to basic mathematic expressions nicely
Bernd Paysan <bernd.pa  2007-11-23 11:10:48 
Re: RPN maps to basic mathematic expressions nicely
Andrew Haley <andrew29  2007-11-23 15:49:07 
Re: RPN maps to basic mathematic expressions nicely
Bernd Paysan <bernd.pa  2007-11-23 17:24:16 
Re: RPN maps to basic mathematic expressions nicely
"Rod Pemberton"  2007-11-12 01:16:25 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-12 16:44:53 
Re: RPN maps to basic mathematic expressions nicely
Marco van de Voort <ma  2007-11-12 17:15:35 
Re: RPN maps to basic mathematic expressions nicely
Jerry Avins <jya@[EMAI  2007-11-12 14:17:04 
Re: RPN maps to basic mathematic expressions nicely
Gary Coulbourne <bear@  2007-11-19 11:22:53 
Re: RPN maps to basic mathematic expressions nicely
John Doty <jpd@[EMAIL   2007-11-19 15:11:44 
Re: RPN maps to basic mathematic expressions nicely
"cr88192" <c  2007-11-20 16:59:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 18 23:09:35 CDT 2008.