Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Aliases

54 views
Skip to first unread message

Brad

unread,
Feb 7, 2012, 11:53:41 AM2/7/12
to
Hi All,

I want to copy existing words into a new wordlist.

My first thought was to use:

: & ( <w> -- ) >IN @ ' SWAP >IN ! CREATE , DOES> @ EXECUTE ;

However, this doesn't work for copying IMMEDIATE words. I can use
EVALUATE, but it's very wordy:

: & ( <w> -- )
S" : " PAD PLACE BL WORD DUP >R COUNT 2DUP PAD APPEND
S" " PAD APPEND
R> FIND NIP DUP IF 1 =
IF S" POSTPONE " PAD APPEND PAD APPEND
S" ; IMMEDIATE" PAD APPEND \ : FOO POSTPONE FOO ;
IMMEDIATE
ELSE PAD APPEND S" ;" PAD APPEND \ : FOO FOO ;
THEN
PAD COUNT EVALUATE
ELSE 3DROP THEN \ Not found, don't make an
alias
;

Is there a simpler (but portable) way? Does 200x propose ALIAS?

-Brad

BruceMcF

unread,
Feb 7, 2012, 12:25:03 PM2/7/12
to
On Feb 7, 11:53 am, Brad <hwfw...@gmail.com> wrote:
> Hi All,
>
> I want to copy existing words into a new wordlist.
>
> My first thought was to use:
>
> : &  ( <w> -- )  >IN @ ' SWAP >IN !  CREATE ,  DOES> @ EXECUTE ;
>
> However, this doesn't work for copying IMMEDIATE words. I can use
> EVALUATE, but it's very wordy:

I see why you switch from ' to FIND to get the IMMEDIATE status, but I
don't see why you switch to EVALUATE at the same time.

Wouldn't something along the lines of ...

: does-@EXECUTE ( -- ) DOES> @ EXECUTE ;
: & ( "word" -- )
>IN @ BL WORD FIND ?DUP IF
ROT >IN ! CREATE SWAP , does-@EXECUTE
1 = IF IMMEDIATE THEN
ELSE CR ." Cannot find: " COUNT TYPE DROP
THEN ;

... do it?

Stephen Pelc

unread,
Feb 7, 2012, 12:59:33 PM2/7/12
to
On Tue, 7 Feb 2012 08:53:41 -0800 (PST), Brad <hwf...@gmail.com>
wrote:

>I want to copy existing words into a new wordlist.
>
>My first thought was to use:
>
>: & ( <w> -- ) >IN @ ' SWAP >IN ! CREATE , DOES> @ EXECUTE ;

...

>Is there a simpler (but portable) way? Does 200x propose ALIAS?

SYNONYM <newname> <oldname>

Stephen


--
Stephen Pelc, steph...@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads

Brad

unread,
Feb 7, 2012, 1:05:13 PM2/7/12
to
On Feb 7, 10:59 am, stephen...@mpeforth.com (Stephen Pelc) wrote:
> SYNONYM <newname> <oldname>
>
Okay. But for brevity (and since the names are identical):

: & ( <name> -- )
>IN @ BL WORD FIND DUP 0= THROW ROT >IN !
CREATE SWAP , 1 = IF IMMEDIATE THEN
DOES> @ EXECUTE ;

Mark Wills

unread,
Feb 8, 2012, 5:31:06 AM2/8/12
to
On Feb 7, 5:59 pm, stephen...@mpeforth.com (Stephen Pelc) wrote:
> On Tue, 7 Feb 2012 08:53:41 -0800 (PST), Brad <hwfw...@gmail.com>
> wrote:
>
> >I want to copy existing words into a new wordlist.
>
> >My first thought was to use:
>
> >: &  ( <w> -- )  >IN @ ' SWAP >IN !  CREATE ,  DOES> @ EXECUTE ;
>
> ...
>
> >Is there a simpler (but portable) way? Does 200x propose ALIAS?
>
> SYNONYM <newname> <oldname>
>
> Stephen
>
> --
> Stephen Pelc, stephen...@mpeforth.com
> MicroProcessor Engineering Ltd - More Real, Less Time
> 133 Hill Lane, Southampton SO15 5AF, England
> tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
> web:http://www.mpeforth.com- free VFX Forth downloads

I thought Synonym would only create a synonym. It doesn't copy the
original code into a new word.

The OP wants to duplicate a word from one wordlist into another. Not
quite the same as SYNONYM.

Nevertheless, that raises an interesting point in itself; One might
consider, rather than just blindly copying the executable code into
the new word, compiling a call to the original word instead. It saves
space on constrained systems.

Stephen Pelc

unread,
Feb 8, 2012, 6:19:54 AM2/8/12
to
On Wed, 8 Feb 2012 02:31:06 -0800 (PST), Mark Wills
<markrob...@yahoo.co.uk> wrote:

>> >Is there a simpler (but portable) way? Does 200x propose ALIAS?
>>
>> SYNONYM <newname> <oldname>
>
>I thought Synonym would only create a synonym. It doesn't copy the
>original code into a new word.
>
>The OP wants to duplicate a word from one wordlist into another. Not
>quite the same as SYNONYM.

What Brad's code does is to generate a new word of the form
: foo foo ;
which is not the same as copying the binary. Copying the binary is
actually quite hard to do on some implementations and CPUs.

Stephen

--
Stephen Pelc, steph...@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691

Alex McDonald

unread,
Feb 8, 2012, 6:13:05 AM2/8/12
to
On Feb 8, 10:31 am, Mark Wills <markrobertwi...@yahoo.co.uk> wrote:
> On Feb 7, 5:59 pm, stephen...@mpeforth.com (Stephen Pelc) wrote:
>
>
>
>
>
>
>
>
>
> > On Tue, 7 Feb 2012 08:53:41 -0800 (PST), Brad <hwfw...@gmail.com>
> > wrote:
>
> > >I want to copy existing words into a new wordlist.
>
> > >My first thought was to use:
>
> > >: &  ( <w> -- )  >IN @ ' SWAP >IN !  CREATE ,  DOES> @ EXECUTE ;
>
> > ...
>
> > >Is there a simpler (but portable) way? Does 200x propose ALIAS?
>
> > SYNONYM <newname> <oldname>
>
> > Stephen
>
> > --
> > Stephen Pelc, stephen...@mpeforth.com
> > MicroProcessor Engineering Ltd - More Real, Less Time
> > 133 Hill Lane, Southampton SO15 5AF, England
> > tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
> > web:http://www.mpeforth.com-free VFX Forth downloads
>
> I thought Synonym would only create a synonym. It doesn't copy the
> original code into a new word.
>
> The OP wants to duplicate a word from one wordlist into another. Not
> quite the same as SYNONYM.
>
> Nevertheless, that raises an interesting point in itself; One might
> consider, rather than just blindly copying the executable code into
> the new word, compiling a call to the original word instead. It saves
> space on constrained systems.

Then (assuming you have VOCABULARY, and this can obviously be extended
to wordlists);

: OLDNAME .... ;

VOCABULARY NEWVOC
ALSO NEWVOC DEFINITIONS

SYNONYM NEWNAME OLDNAME

PREVIOUS DEFINITIONS

Elizabeth D. Rather

unread,
Feb 8, 2012, 12:11:34 PM2/8/12
to
On 2/8/12 1:19 AM, Stephen Pelc wrote:
> On Wed, 8 Feb 2012 02:31:06 -0800 (PST), Mark Wills
> <markrob...@yahoo.co.uk> wrote:
>
>>>> Is there a simpler (but portable) way? Does 200x propose ALIAS?
>>>
>>> SYNONYM<newname> <oldname>
>>
>> I thought Synonym would only create a synonym. It doesn't copy the
>> original code into a new word.
>>
>> The OP wants to duplicate a word from one wordlist into another. Not
>> quite the same as SYNONYM.
>
> What Brad's code does is to generate a new word of the form
> : foo foo ;
> which is not the same as copying the binary. Copying the binary is
> actually quite hard to do on some implementations and CPUs.

And why would one actually want to do that?

Cheers,
Elizabeth

--
==================================================
Elizabeth D. Rather (US & Canada) 800-55-FORTH
FORTH Inc. +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

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

BruceMcF

unread,
Feb 8, 2012, 1:30:46 PM2/8/12
to
On Feb 8, 6:13 am, Alex McDonald <b...@rivadpm.com> wrote:
> On Feb 8, 10:31 am, Mark Wills <markrobertwi...@yahoo.co.uk> wrote:
>
>
>
>
>
>
>
>
>
> > On Feb 7, 5:59 pm, stephen...@mpeforth.com (Stephen Pelc) wrote:
>
> > > On Tue, 7 Feb 2012 08:53:41 -0800 (PST), Brad <hwfw...@gmail.com>
> > > wrote:
>
> > > >I want to copy existing words into a new wordlist.
>
> > > >My first thought was to use:
>
> > > >: &  ( <w> -- )  >IN @ ' SWAP >IN !  CREATE ,  DOES> @ EXECUTE ;
>
> > > ...
>
> > > >Is there a simpler (but portable) way? Does 200x propose ALIAS?
>
> > > SYNONYM <newname> <oldname>
>
> > > Stephen
>
> > > --
> > > Stephen Pelc, stephen...@mpeforth.com
> > > MicroProcessor Engineering Ltd - More Real, Less Time
> > > 133 Hill Lane, Southampton SO15 5AF, England
> > > tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
> > > web:http://www.mpeforth.com-freeVFX Forth downloads
>
> > I thought Synonym would only create a synonym. It doesn't copy the
> > original code into a new word.
>
> > The OP wants to duplicate a word from one wordlist into another. Not
> > quite the same as SYNONYM.
>
> > Nevertheless, that raises an interesting point in itself; One might
> > consider, rather than just blindly copying the executable code into
> > the new word, compiling a call to the original word instead. It saves
> > space on constrained systems.
>
> Then (assuming you have VOCABULARY, and this can obviously be extended
> to wordlists);
>
> : OLDNAME .... ;
>
> VOCABULARY NEWVOC
> ALSO NEWVOC DEFINITIONS
>
> SYNONYM NEWNAME OLDNAME
>
> PREVIOUS DEFINITIONS

That does not, however, import the word under the same name as "&" is
trying to do. DEFER and IS would do so, I think, by reusing the word
in the input buffer. But if the extra semantics of DEFER and IS are
not required, the does-@EXECUTE approach would be about as compact:

: does-@EXECUTE DOES> @ EXECUTE ;
: & ( "name" -- )
>IN @ BL WORD FIND ?DUP IF
ROT >IN ! SWAP CREATE , does-@EXECUTE
1 = IF IMMEDIATE THEN
ELSE CR COUNT TYPE SPACE ." ???" THEN ;

: & ( "name" -- )
>IN @ BL WORD FIND ?DUP IF
ROT DUP >IN ! DEFER
>IN ! SWAP ['] IS EXECUTE
1 = IF IMMEDIATE THEN
ELSE CR COUNT TYPE SPACE ." ???" THEN ;

Alex McDonald

unread,
Feb 8, 2012, 1:26:13 PM2/8/12
to
On Feb 8, 5:11 pm, "Elizabeth D. Rather" <erat...@forth.com> wrote:
> On 2/8/12 1:19 AM, Stephen Pelc wrote:
>
>
>
>
>
>
>
>
>
> > On Wed, 8 Feb 2012 02:31:06 -0800 (PST), Mark Wills
> > <markrobertwi...@yahoo.co.uk>  wrote:
>
> >>>> Is there a simpler (but portable) way? Does 200x propose ALIAS?
>
> >>> SYNONYM<newname>  <oldname>
>
> >> I thought Synonym would only create a synonym. It doesn't copy the
> >> original code into a new word.
>
> >> The OP wants to duplicate a word from one wordlist into another. Not
> >> quite the same as SYNONYM.
>
> > What Brad's code does is to generate a new word of the form
> >    : foo  foo  ;
> > which is not the same as copying the binary. Copying the binary is
> > actually quite hard to do on some implementations and CPUs.
>
> And why would one actually want to do that?

Inlining, dynamic loading (particularly of libraries), "sandpit"
debugging, virtualisation, compilation out of line or off-processor,
and so on. The usual technique is to either keep a static set of
relocations that are applied when the code is loaded or moved; or
dynamically generate them by disassembling the code. It's usually
required for processors that utilise position dependent code.

Many of these may not apply to Forth, although inlining is an
exception.

>
> Cheers,
> Elizabeth
>
> --
> ==================================================
> Elizabeth D. Rather   (US & Canada)   800-55-FORTH
> FORTH Inc.                         +1 310.999.6784
> 5959 West Century Blvd. Suite 700
> Los Angeles, CA 90045http://www.forth.com

Stephen Pelc

unread,
Feb 8, 2012, 1:51:48 PM2/8/12
to
On Wed, 08 Feb 2012 07:11:34 -1000, "Elizabeth D. Rather"
<era...@forth.com> wrote:

>> What Brad's code does is to generate a new word of the form
>> : foo foo ;
>> which is not the same as copying the binary. Copying the binary is
>> actually quite hard to do on some implementations and CPUs.
>
>And why would one actually want to do that?

1) : foo foo ;
That's sometimes useful to expose words. Clients do it.
2) Binary copy
Some code generators (e.g. SwiftForth) do/did this.

Elizabeth D. Rather

unread,
Feb 8, 2012, 3:05:37 PM2/8/12
to
On 2/8/12 8:26 AM, Alex McDonald wrote:
> On Feb 8, 5:11 pm, "Elizabeth D. Rather"<erat...@forth.com> wrote:
>> On 2/8/12 1:19 AM, Stephen Pelc wrote:
...
>>> What Brad's code does is to generate a new word of the form
>>> : foo foo ;
>>> which is not the same as copying the binary. Copying the binary is
>>> actually quite hard to do on some implementations and CPUs.
>>
>> And why would one actually want to do that?
>
> Inlining, dynamic loading (particularly of libraries), "sandpit"
> debugging, virtualisation, compilation out of line or off-processor,
> and so on. The usual technique is to either keep a static set of
> relocations that are applied when the code is loaded or moved; or
> dynamically generate them by disassembling the code. It's usually
> required for processors that utilise position dependent code.
>
> Many of these may not apply to Forth, although inlining is an
> exception.

Ok, but my understanding of the OP was that he wanted to access the word
from a different wordlist. Stephen's SYNONYM does that nicely. Inlining
is a compiler strategy in itself, not particularly related to getting
something visible in a different wordlist. If wordlist visibility is the
issue, I don't see why copying the code itself is relevant.

Alex McDonald

unread,
Feb 8, 2012, 5:19:09 PM2/8/12
to
On Feb 8, 6:30 pm, BruceMcF <agil...@netscape.net> wrote:
> On Feb 8, 6:13 am, Alex McDonald <b...@rivadpm.com> wrote:
>
>
>
>
>
>
>
>
>
> > On Feb 8, 10:31 am, Mark Wills <markrobertwi...@yahoo.co.uk> wrote:
>
> > > On Feb 7, 5:59 pm, stephen...@mpeforth.com (Stephen Pelc) wrote:
>
> > > > On Tue, 7 Feb 2012 08:53:41 -0800 (PST), Brad <hwfw...@gmail.com>
> > > > wrote:
>
> > > > >I want to copy existing words into a new wordlist.
>
> > > > >My first thought was to use:
>
> > > > >: &  ( <w> -- )  >IN @ ' SWAP >IN !  CREATE ,  DOES> @ EXECUTE ;
>
> > > > ...
>
> > > > >Is there a simpler (but portable) way? Does 200x propose ALIAS?
>
> > > > SYNONYM <newname> <oldname>
>
> > > > Stephen
>
> > > > --
> > > > Stephen Pelc, stephen...@mpeforth.com
> > > > MicroProcessor Engineering Ltd - More Real, Less Time
> > > > 133 Hill Lane, Southampton SO15 5AF, England
> > > > tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
> > > > web:http://www.mpeforth.com-freeVFXForth downloads
: THISNAME .... ;
VOCABULARY NEWVOC
ALSO NEWVOC DEFINITIONS
SYNONYM THISNAME THISNAME
PREVIOUS DEFINITIONS

SYNONYM allows both names to be the same. Any system that declares and
finds the new THISNAME as its own alias is in error.

15.6.2. SYNONYM TOOLS EXT
For both strings skip leading space delimiters. Parse newname and
oldname delimited by a space. Create a definition for newname with the
semantics defined below. Newname may be the same as oldname; when
looking up oldname, newname shall not be found .

BruceMcF

unread,
Feb 8, 2012, 6:04:11 PM2/8/12
to
On Feb 8, 5:19 pm, Alex McDonald <b...@rivadpm.com> wrote:
> SYNONYM allows both names to be the same.

Yes, but the specified behavior was for the name to appear once.

> Any system that declares and
> finds the new THISNAME as its own alias is in error.

Yes, that's why the original name was searched for and its xt found
first, before executing DEFER and the interpreter semantics of IS.

BruceMcF

unread,
Feb 8, 2012, 6:05:22 PM2/8/12
to
On Feb 8, 5:19 pm, Alex McDonald <b...@rivadpm.com> wrote:
> SYNONYM allows both names to be the same. Any system that declares and
> finds the new THISNAME as its own alias is in error.

Is the SYNONYM of an immediate word defined to be immediate?

Elizabeth D. Rather

unread,
Feb 9, 2012, 1:55:40 PM2/9/12
to
I think not automatically. You would have to mark your synonym as
immediate. It can conceivably be useful to define a non-immediate
synonym of an immediate word.

Alex McDonald

unread,
Feb 9, 2012, 4:36:58 PM2/9/12
to
On Feb 9, 6:55 pm, "Elizabeth D. Rather" <erat...@forth.com> wrote:
> On 2/8/12 1:05 PM, BruceMcF wrote:
>
> > On Feb 8, 5:19 pm, Alex McDonald<b...@rivadpm.com>  wrote:
> >> SYNONYM allows both names to be the same. Any system that declares and
> >> finds the new THISNAME as its own alias is in error.
>
> > Is the SYNONYM of an immediate word defined to be immediate?
>
> I think not automatically.  You would have to mark your synonym as
> immediate. It can conceivably be useful to define a non-immediate
> synonym of an immediate word.

According to the spec it's not portable. In the case of my Forth, the
word can be marked immediate because the old word's definition is
copied to newname. I can envisage dictionaries where the
implementation has names and pointers to header structures; in which
case, a shared header structure would result in also marking oldname
as immediate.

15.6.2. SYNONYM TOOLS EXT
( “<spaces>newname” “<spaces>oldname” -- ) X:synonym
For both strings skip leading space delimiters. Parse newname and
oldname delimited by a space. Create a definition for newname with the
semantics defined below. Newname may be the same as oldname; when
looking up oldname, newname shall not be found.

An ambiguous conditions exists if oldname can not be found or
IMMEDIATE is applied to newname.


>
> Cheers,
> Elizabeth
>
> --
> ==================================================
> Elizabeth D. Rather   (US & Canada)   800-55-FORTH
> FORTH Inc.                         +1 310.999.6784
> 5959 West Century Blvd. Suite 700
> Los Angeles, CA 90045http://www.forth.com

BruceMcF

unread,
Feb 9, 2012, 8:44:49 PM2/9/12
to
On Feb 9, 1:55 pm, "Elizabeth D. Rather" <erat...@forth.com> wrote:
> > Is the SYNONYM of an immediate word defined to be immediate?

> I think not automatically.  You would have to mark your synonym as
> immediate. It can conceivably be useful to define a non-immediate
> synonym of an immediate word.

Then for the target application, where the desire is for the immediacy
or not to be inherited, it wouldn't seem like much less trouble than
the BL WORD FIND approach.

Gerry Jackson

unread,
Feb 10, 2012, 4:32:53 AM2/10/12
to
On 09/02/2012 21:36, Alex McDonald wrote:
> On Feb 9, 6:55 pm, "Elizabeth D. Rather"<erat...@forth.com> wrote:
>> On 2/8/12 1:05 PM, BruceMcF wrote:
>>
>>> On Feb 8, 5:19 pm, Alex McDonald<b...@rivadpm.com> wrote:
>>>> SYNONYM allows both names to be the same. Any system that declares and
>>>> finds the new THISNAME as its own alias is in error.
>>
>>> Is the SYNONYM of an immediate word defined to be immediate?

I think so, see below.

>>
>> I think not automatically. You would have to mark your synonym as
>> immediate. It can conceivably be useful to define a non-immediate
>> synonym of an immediate word.
>
> According to the spec it's not portable. In the case of my Forth, the
> word can be marked immediate because the old word's definition is
> copied to newname. I can envisage dictionaries where the
> implementation has names and pointers to header structures; in which
> case, a shared header structure would result in also marking oldname
> as immediate.
>
> 15.6.2. SYNONYM TOOLS EXT
> ( “<spaces>newname” “<spaces>oldname” -- ) X:synonym
> For both strings skip leading space delimiters. Parse newname and
> oldname delimited by a space. Create a definition for newname with the
> semantics defined below. Newname may be the same as oldname; when
> looking up oldname, newname shall not be found.
>
> An ambiguous conditions exists if oldname can not be found or
> IMMEDIATE is applied to newname.
>

You omitted the next bit of the specification that the above refers to
for semantics and which says (from
www.forth200x.org/documents/forth11-1.pdf):

<quote>
newname interpretation: ( i*x -- j*x )
Perform the interpretation semantics of oldname.
newname compilation: ( i*x -- j*x )
Perform the compilation semantics of oldname.
</quote>

If oldname is immediate and an implementation doesn't make newname
immediate then their compilation semantics are different which violates
the second statement above.

Therefore ISTM that immediacy must be inherited and the answer to
Bruce's original question is yes.

--
Gerry

Alex McDonald

unread,
Feb 10, 2012, 6:21:58 AM2/10/12
to
On Feb 10, 9:32 am, Gerry Jackson <ge...@jackson9000.fsnet.co.uk>
wrote:
Elizabeth was suggesting immediacy can be set on newname when oldname
is not immediate, which is ambiguous;

: foo ;
synonym bar foo immediate

This is ok;

: foo ; immediate
synonym bar foo

Anton Ertl

unread,
Feb 10, 2012, 6:32:51 AM2/10/12
to

Gerry Jackson

unread,
Feb 10, 2012, 8:04:13 AM2/10/12
to
Not the way I read it, she was referring to an immediate oldname and
attempting to make newname match it by use of immediate ...

> which is ambiguous;

Correct

>
> : foo ;
> synonym bar foo immediate
>
> This is ok;
>
> : foo ; immediate
> synonym bar foo
>

Yes and bar is automatically immediate (or should be).

--
Gerry

Alex McDonald

unread,
Feb 10, 2012, 8:07:55 AM2/10/12
to
On Feb 10, 1:04 pm, Gerry Jackson <ge...@jackson9000.fsnet.co.uk>
OK, we're in violent agreement :-)

JennyB

unread,
Feb 10, 2012, 9:57:53 AM2/10/12
to
On Friday, 10 February 2012 09:32:53 UTC, Gerry wrote:

> You omitted the next bit of the specification that the above refers to
> for semantics and which says (from
> www.forth200x.org/documents/forth11-1.pdf):
>
> <quote>
> newname interpretation: ( i*x -- j*x )
> Perform the interpretation semantics of oldname.
> newname compilation: ( i*x -- j*x )
> Perform the compilation semantics of oldname.
> </quote>
>
> If oldname is immediate and an implementation doesn't make newname
> immediate then their compilation semantics are different which violates
> the second statement above.
>
Further, if a system has words with non-default and non-immediate semantics, shouldn't ' newname ( and ['] newname at runtime) return the interpretation semantics of oldname, and POSTPONE newname compile the compilation semantics of oldname, regardless of later STATE?

I'm beginning to see a way to Standardise such words, and still keep an interpreter that uses FIND:

: CLONE ( xt xtc ++ )
CREATE 2, IMMEDIATE
DOES> 2@ STATE @ 0= IF DROP THEN EXECUTE ;

CLONE? ( xt -- f ) system dependent. I /think/ you can always non-portably
recognize a DOES> word from its xt


: 'COMP ( ++ xt xtc ) FIND ?DUP 0= IF
COUNT TYPE [CHAR] ? EMIT ABORT THEN
-1 = IF
['] COMPILE ELSE
DUP CLONE? IF
>BODY 2@ ELSE
['] EXECUTE THEN ;

: ' 'COMP DROP ;
: ['] ' POSTPONE LITERAL ; IMMEDIATE

: POSTPONE 'COMP DUP ['] EXECUTE = IF
DROP ELSE
SWAP POSTPONE LITERAL THEN
COMPILE, ; IMMEDIATE

: & >IN @ >R 'COMP
R> >IN ! CLONE ;

: SYNONYM >IN @ >R BL WORD DROP \ skip new name for now
'COMP
>IN @ R> SWAP >R >IN ! CLONE
R> >IN ! ;

\ Gforth Style Combined Words

: ct>xtc ( ct -- xtc ) >R :NONAME POSTPONE DROP R> COMPILE, POSTPONE ; ;

: INTERPRET/COMPILE: ct>xtc CLONE ;

In general, whenever you want to decorate the behaviour of an already-defined word, clone it.




BruceMcF

unread,
Feb 10, 2012, 12:05:18 PM2/10/12
to
On Feb 10, 4:32 am, Gerry Jackson <ge...@jackson9000.fsnet.co.uk>
wrote:
>>>> Is the SYNONYM of an immediate word defined to be immediate?

> I think so, see below.
...
> You omitted the next bit of the specification that
> the above refers to for semantics and which says
> (fromwww.forth200x.org/documents/forth11-1.pdf):

> <quote>
> newname interpretation: ( i*x -- j*x )
>          Perform the interpretation semantics of oldname.

> newname compilation: ( i*x -- j*x )
>          Perform the compilation semantics of oldname.

> </quote>

OK, thanks.

Then:

CREATE &BUFFER S" SYNONYM" S, 64 CHARS ALLOT
... and something to paste two copies of the "name" into that buffer
just saving the original count and doing a BL> and S> twice would load
up the word, then restore the original count and its ready for the
next use ... would support a "&" that took one copy of the name, and
then evaluate the buffer ... without the complication of handling the
immediacy itself, and also working for words that have more than just
EXECUTE and COMPILE, as compilation semantics.

Ed

unread,
Feb 10, 2012, 8:10:31 PM2/10/12
to
Elizabeth D. Rather wrote:
> On 2/8/12 1:05 PM, BruceMcF wrote:
> > On Feb 8, 5:19 pm, Alex McDonald<b...@rivadpm.com> wrote:
> >> SYNONYM allows both names to be the same. Any system that declares and
> >> finds the new THISNAME as its own alias is in error.
> >
> > Is the SYNONYM of an immediate word defined to be immediate?
> >
>
> I think not automatically. You would have to mark your synonym as
> immediate. It can conceivably be useful to define a non-immediate
> synonym of an immediate word.

That's what AKA in Swiftforth necessitates. The negatives are:

1) aliases of immediate words won't truly be so until IMMEDIATE is applied
2) it demands the user know the immediacy of the word before it's aliased

Is there a need to make an immediate word non-immediate? Other
than as a work-around for a bad choice made earlier, none that I know.

Usually one has a good reason for making a word IMMEDIATE. I don't
recall ever seeing an application where, after making a word immediate,
it then needed unmaking. If this is the case for regular words then it
must also hold true for aliases.

My AKA automatically handles immediacy. SwiftForth's could also,
with little or no incompatibility to existing apps.



BruceMcF

unread,
Feb 11, 2012, 2:53:57 PM2/11/12
to
On Feb 10, 8:10 pm, "Ed" <nos...@invalid.com> wrote:
> Is there a need to make an immediate word non-immediate?

What's the matter with:

: do-/ ( "...<ret>" -- ) POSTPONE / ;

Ed

unread,
Feb 13, 2012, 1:15:31 AM2/13/12
to
It went over my head.



0 new messages