Looking for a short SYNONYM 
Author Message
 Looking for a short SYNONYM

I want to define a word DITTO that creates synonyms.  For example,
DITTO DUP would create a word DUP in the definitions list whose
action is that of DUP.  Is there an ANS or near-ANS way to do this?

-- Brad Eckert



Mon, 22 Nov 1999 03:00:00 GMT  
 Looking for a short SYNONYM

Quote:

> I want to define a word DITTO that creates synonyms.  For example,
> DITTO DUP would create a word DUP in the definitions list whose
> action is that of DUP.  Is there an ANS or near-ANS way to do this?

This is a version I have used for years. I believe it was first done by
Victor Ynge (sp?) and appeared in an early Forth Dimensions. It works
with both immediate and non-immediate words. Basically you create a new
word that tries to behave like the old word, either executing or
compiling the old word depending on STATE. There is no run-time penalty
when used in a colon definition (the old word is compiled).

This definition used to be in Win32Forth, but the definition has been
changed to be like F-PC's ALIAS word, which patches the xt pointer in
the header, and so it is not ANS.

: SYNONYM   ( -- )
        CREATE  IMMEDIATE
                BL WORD FIND  DUP 0= ABORT" ?"  , ,


                IF  COMPILE,  ELSE  EXECUTE  THEN ;

SYNONYM <newmame> <oldname>

SYNONYM DUPE DUP
SYNONYM ENDIF THEN

----------------------------------------------------------------------

Finnigan Corporation            
2215 Grand Avenue Parkway        Tel: (512) 251-1574
Austin, TX  78728-3812           Fax: (512) 251-1547



Tue, 23 Nov 1999 03:00:00 GMT  
 Looking for a short SYNONYM

: I want to define a word DITTO that creates synonyms.  For example,
: DITTO DUP would create a word DUP in the definitions list whose
: action is that of DUP.  Is there an ANS or near-ANS way to do this?

\ Here is a Standard definition using Core words only.

( An old friend from F83. )
: PLACE               ( caddr1 u caddr2 -- )
    2DUP >R >R  CHAR+ SWAP  CHARS MOVE  R> R> C!
;

: SYNONYM             ( "name1<spaces>name2" -- )
    CREATE IMMEDIATE
    WORD COUNT  HERE  OVER 1+ ALLOT  PLACE
    DOES> COUNT EVALUATE
;

--
Procedamus in pace.   Wil Baden   Costa Mesa, California



Tue, 23 Nov 1999 03:00:00 GMT  
 Looking for a short SYNONYM

Quote:

> \ Here is a Standard definition using Core words only.
> ( An old friend from F83. )
> : PLACE               ( caddr1 u caddr2 -- )

    > 2DUP >R >R  CHAR+ SWAP  CHARS MOVE  R> R> C!

Quote:
> ;
> : SYNONYM             ( "name1<spaces>name2" -- )
> CREATE IMMEDIATE
> WORD COUNT  HERE  OVER 1+ ALLOT  PLACE
> DOES> COUNT EVALUATE
> ;

But why stop there?  (`PARSE` is from the Core Extension word set
but can be defined with Core words.)

: MACRO              ( "name<spaces><char>ccc<char> -- )
    CREATE IMMEDIATE
    CHAR PARSE  HERE  OVER 1+ ALLOT  PLACE
    DOES> COUNT EVALUATE
;

MACRO ITERATE " FALSE REPEAT DROP "
MACRO AGAIN   " 0 UNTIL "
MACRO UNLESS  " 0 IF "



Tue, 23 Nov 1999 03:00:00 GMT  
 Looking for a short SYNONYM

Quote:


> > I want to define a word DITTO that creates synonyms.  For example,
> > DITTO DUP would create a word DUP in the definitions list whose
> > action is that of DUP.  Is there an ANS or near-ANS way to do this?

> This is a version I have used for years. I believe it was first done by
> Victor Ynge (sp?) and appeared in an early Forth Dimensions. It works
> with both immediate and non-immediate words. Basically you create a new
> word that tries to behave like the old word, either executing or
> compiling the old word depending on STATE. There is no run-time penalty
> when used in a colon definition (the old word is compiled).

> This definition used to be in Win32Forth, but the definition has been
> changed to be like F-PC's ALIAS word, which patches the xt pointer in
> the header, and so it is not ANS.

> : SYNONYM   ( -- )
>         CREATE  IMMEDIATE
>                 BL WORD FIND  DUP 0= ABORT" ?"  , ,


>                 IF  COMPILE,  ELSE  EXECUTE  THEN ;

> SYNONYM <newmame> <oldname>

> SYNONYM DUPE DUP
> SYNONYM ENDIF THEN

Very nice.  What I had in mind was a version of this in which <oldname> is the
same as <newname> so the syntax would be DITTO <newname>.  I suppose one could
back up the input pointer so as to parse <newname> twice.

-- Brad Eckert



Tue, 23 Nov 1999 03:00:00 GMT  
 Looking for a short SYNONYM


Quote:


> > : SYNONYM   ( -- )
> >         CREATE  IMMEDIATE
> >                 BL WORD FIND  DUP 0= ABORT" ?"  , ,


> >                 IF  COMPILE,  ELSE  EXECUTE  THEN ;

> > SYNONYM <newmame> <oldname>

> > SYNONYM DUPE DUP
> > SYNONYM ENDIF THEN

> Very nice.  What I had in mind was a version of this in which <oldname> is the
> same as <newname> so the syntax would be DITTO <newname>.  I suppose one
could
> back up the input pointer so as to parse <newname> twice.

Yes, but you would need to do the "BL WORD FIND" first, because CREATE builds
a header that is findable, and it WOULD be found by a following "BL WORD
FIND" as
was used above.

Tom Zimmer

--
Tom Zimmer



Wed, 24 Nov 1999 03:00:00 GMT  
 Looking for a short SYNONYM

  >> : PLACE               ( caddr1 u caddr2 -- )
  >>   2DUP >R >R  CHAR+ SWAP  CHARS MOVE  R> R> C! ;

Just a note about this ultra complicated definition of PLACE that
someone posted. :-)  Here's a ANS but simpler/more efficient than
the above:

: place ( c-addr u dest -- )
   2dup c! char+ swap chars move ;




Thu, 25 Nov 1999 03:00:00 GMT  
 Looking for a short SYNONYM

:   >> : PLACE               ( caddr1 u caddr2 -- )
:   >>   2DUP >R >R  CHAR+ SWAP  CHARS MOVE  R> R> C! ;

: Just a note about this ultra complicated definition of PLACE that
: someone posted. :-)  Here's a ANS but simpler/more efficient than
: the above:

: : place ( c-addr u dest -- )
:    2dup c! char+ swap chars move ;

Nice flame.

Yes, that's how I wrote it before I knew better.

Your ignorant definition will usually work.

The ultra complicated part of my definition is to make it _always_ work.

`PAD 80 PAD PLACE`

`PAD 10 CHARS + 20 PAD PLACE`

`PAD 20 PAD 10 CHARS + PLACE`
--
Procedamus in pace.     Wil Baden   Costa Mesa, California



Thu, 25 Nov 1999 03:00:00 GMT  
 Looking for a short SYNONYM

Quote:


> :   >> : PLACE               ( caddr1 u caddr2 -- )
> :   >>   2DUP >R >R  CHAR+ SWAP  CHARS MOVE  R> R> C! ;

> : Just a note about this ultra complicated definition of PLACE that
> : someone posted. :-)  Here's a ANS but simpler/more efficient than
> : the above:

> : : place ( c-addr u dest -- )
> :    2dup c! char+ swap chars move ;

> Nice flame.

> Yes, that's how I wrote it before I knew better.

> Your ignorant definition will usually work.

> The ultra complicated part of my definition is to make it _always_ work.

> `PAD 80 PAD PLACE`

> `PAD 10 CHARS + 20 PAD PLACE`

> `PAD 20 PAD 10 CHARS + PLACE`
> --
> Procedamus in pace.     Wil Baden   Costa Mesa, California

Not to mention a multi-tasking environment, where you want the
count of characters to change only after the text has been put
in place.

--
Tom Zimmer



Thu, 25 Nov 1999 03:00:00 GMT  
 Looking for a short SYNONYM

   >: : place ( c-addr u dest -- )
   >:    2dup c! char+ swap chars move ;
   >Nice flame.
   >Yes, that's how I wrote it before I knew better.
   >Your ignorant definition will usually work.
   >The ultra complicated part of my definition is to make it _always_
   >work.    `PAD 80 PAD PLACE`

Sorry, no intention to make it a flame, just a "I thought I knew better
than you" message. Obviously this was not the case and I eat my words. :)
You have a very good point, I just wasn't thinking of overlapping addrs
when I wrote the definition.

Thank you kindly...




Fri, 26 Nov 1999 03:00:00 GMT  
 Looking for a short SYNONYM


Quote:


>:   >> : PLACE               ( caddr1 u caddr2 -- )
>:   >>   2DUP >R >R  CHAR+ SWAP  CHARS MOVE  R> R> C! ;

>: Just a note about this ultra complicated definition of PLACE that
>: someone posted. :-)  Here's a ANS but simpler/more efficient than
>: the above:

>: : place ( c-addr u dest -- )
>:    2dup c! char+ swap chars move ;

>Nice flame.

>Yes, that's how I wrote it before I knew better.

>Your ignorant definition will usually work.

>The ultra complicated part of my definition is to make it _always_ work.

>`PAD 80 PAD PLACE`

>`PAD 10 CHARS + 20 PAD PLACE`

>`PAD 20 PAD 10 CHARS + PLACE`
>--
>Procedamus in pace.         Wil Baden   Costa Mesa, California

Youth must learn by experience that experience is valuable. :-)

--
//---------------------------
// Bruce Hoyt

//---------------------------



Sat, 27 Nov 1999 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. long = short*short ; (short,short) = long/short

2. Consultant looking for short term Smalltalk contract - NY/NJ

3. Looking for short, intensive, ST course in UK

4. Looking For VHDL (Short ) Course

5. Kalman filter short course - looking for suggestions/leads

6. regexp, look for shortest string

7. Looking for a shorter for SmallTalk ?

8. common type synonyms (haskell)

9. type synonyms

10. X86 opcode synonyms

11. english synonyms

12. Synonyms

 

 
Powered by phpBB® Forum Software