Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.forth

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2012, 03:53 PM
Brad
Guest
 
Posts: n/a
Default Aliases

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
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 02-07-2012, 04:25 PM
BruceMcF
Guest
 
Posts: n/a
Default Re: Aliases

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?
Reply With Quote
  #3 (permalink)  
Old 02-07-2012, 05:05 PM
Brad
Guest
 
Posts: n/a
Default Re: Aliases

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 ;
Reply With Quote
  #4 (permalink)  
Old 02-08-2012, 09:31 AM
Mark Wills
Guest
 
Posts: n/a
Default Re: Aliases

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.

Reply With Quote
  #5 (permalink)  
Old 02-08-2012, 10:13 AM
Alex McDonald
Guest
 
Posts: n/a
Default Re: Aliases

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

Reply With Quote
  #6 (permalink)  
Old 02-08-2012, 04:11 PM
Elizabeth D. Rather
Guest
 
Posts: n/a
Default Re: Aliases

On 2/8/12 1:19 AM, Stephen Pelc wrote:
> On Wed, 8 Feb 2012 02:31:06 -0800 (PST), Mark Wills
> <markrobertwills@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."
==================================================
Reply With Quote
  #7 (permalink)  
Old 02-08-2012, 05:26 PM
Alex McDonald
Guest
 
Posts: n/a
Default Re: Aliases

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
>
> "Forth-based products and Services for real-time
> applications since 1973."
> ==================================================


Reply With Quote
  #8 (permalink)  
Old 02-08-2012, 05:30 PM
BruceMcF
Guest
 
Posts: n/a
Default Re: Aliases

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 ;
Reply With Quote
  #9 (permalink)  
Old 02-08-2012, 07:05 PM
Elizabeth D. Rather
Guest
 
Posts: n/a
Default Re: Aliases

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.

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."
==================================================
Reply With Quote
  #10 (permalink)  
Old 02-08-2012, 09:19 PM
Alex McDonald
Guest
 
Posts: n/a
Default Re: Aliases

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

>
> > > 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 ;


: 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 .
Reply With Quote
  #11 (permalink)  
Old 02-08-2012, 10:04 PM
BruceMcF
Guest
 
Posts: n/a
Default Re: Aliases

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.

Reply With Quote
  #12 (permalink)  
Old 02-08-2012, 10:05 PM
BruceMcF
Guest
 
Posts: n/a
Default Re: Aliases

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?

Reply With Quote
  #13 (permalink)  
Old 02-09-2012, 05:55 PM
Elizabeth D. Rather
Guest
 
Posts: n/a
Default Re: Aliases

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.

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."
==================================================
Reply With Quote
  #14 (permalink)  
Old 02-09-2012, 08:36 PM
Alex McDonald
Guest
 
Posts: n/a
Default Re: Aliases

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
>
> "Forth-based products and Services for real-time
> applications since 1973."
> ==================================================


Reply With Quote
  #15 (permalink)  
Old 02-10-2012, 12:44 AM
BruceMcF
Guest
 
Posts: n/a
Default Re: Aliases

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.
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 05:03 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.