Article View: net.lang.forth
Article #138Re: Speaking of Princeton
From: William L. Sebok
Date: Sat, 29 Sep 1984 00:59
Date: Sat, 29 Sep 1984 00:59
59 lines
2737 bytes
2737 bytes
Here are a few answers to a couple of recent questions. These words have
been tested on the Forth at astrovax.
> While the recent distribution of Princeton FORTH is still fresh
> on our computers, I've been evolving a list of "how do you do it"'s
> and was wondering if any of you out there have had similar problems/
> successes:
>
> 1. How do I implement the equivalent of ?TERMINAL ?
A definition for ?TERMINAL (called KEY? in Forth 83) in Princeton Forth under
either BSD 4.2 or 4.1 would be:
HEX
find 4.2BSD #if 4004667f #else 667F #then CONSTANT FIONREAD
DECIMAL
VARIABLE NBYTES
: ?TERMINAL NBYTES FIONREAD TYPER @ A1+ @ $IOCTL ?UERROR DROP
NBYTES @ ;
This returns the number of characters waiting to be input. Ordinarily it only
knows about full lines of characters. However when the terminal is in raw
mode (set by <KEY and KEY> ) it knows about individual characters. Beware
that both <KEY and KEY> flush input, i.e. forget all pending input characters.
This is known as living with what Unix provides. The next version of my vax
forth is likely to have ordinary input in CBREAK mode (to provide extra
interactive features) so it may not have those restrictions.
> 2. How can I implement my own control structures ( such as Charles Eaker's
> CASE statement ) without resorting to otherwise unknown assembly language?
A version of the CASE you requested would be:
VARIABLE CSP
: OF COMPILE OVER COMPILE = [COMPILE] IF COMPILE DROP ;
IMMEDIATE
: CASE 'S CSP ! ; IMMEDIATE
: ENDOF [COMPILE] ELSE ; IMMEDIATE
: ENDCASE COMPILE DROP
BEGIN 'S CSP @ <> WHILE [COMPILE] THEN REPEAT ; IMMEDIATE
Alternatively OF could be
: OF [COMPILE] CASE ; IMMEDIATE
using the old CASE, which does the same thing as OF should do.
This has no compile time testing. I should consider adding some of that to
this implementation. Right now this implementation shows its Forth Inc. forth
ancestry and little or no compile time checking.
--
Bill Sebok Princeton University, Astrophysics
{allegra,akgua,burl,cbosgd,decvax,ihnp4,noao,princeton,vax135}!astrovax!wls
Technical Details
Message-ID:
<456@astrovax.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxj!ihnp4!astrovax!wlsReferences:
<3033@utah-cs.UUCP> <128@cadovax.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/3/84 (WLS Mods); site astrovax.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxj!ihnp4!astrovax!wls From: wls@astrovax.UUCP (William L. Sebok) Newsgroups: net.lang.forth Subject: Re: Speaking of Princeton Message-ID: <456@astrovax.UUCP> Date: Fri, 28-Sep-84 20:59:33 EDT Article-I.D.: astrovax.456 Posted: Fri Sep 28 20:59:33 1984 Date-Received: Sat, 29-Sep-84 10:07:08 EDT References: <3033@utah-cs.UUCP> <128@cadovax.UUCP> Organization: Princeton Univ. Astrophysics Lines: 59