Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #55741 > unrolled thread

When to use !name vs. name! ?

Started by"HAA" <someone@microsoft.com>
First post2017-03-14 11:15 +1100
Last post2017-04-12 08:13 +0200
Articles 14 on this page of 34 — 12 participants

Back to article view | Back to comp.lang.forth


Contents

  When to use  !name  vs.  name! ? "HAA" <someone@microsoft.com> - 2017-03-14 11:15 +1100
    Re: When to use  !name  vs.  name! ? hughaguilar96@gmail.com - 2017-03-13 18:27 -0700
      Re: When to use  !name  vs.  name! ? Mark Wills <markwills1970@gmail.com> - 2017-03-14 01:33 -0700
    Re: When to use  !name  vs.  name! ? Mark Wills <markwills1970@gmail.com> - 2017-03-14 01:30 -0700
    When to use  !name  vs.  name! ? NN <november.nihal@gmail.com> - 2017-03-14 02:56 -0700
      Re: When to use  !name  vs.  name! ? "HAA" <someone@microsoft.com> - 2017-03-16 08:59 +1100
        Re: When to use  !name  vs.  name! ? Mark Wills <markwills1970@gmail.com> - 2017-03-16 02:11 -0700
          Re: When to use  !name  vs.  name! ? "HAA" <someone@microsoft.com> - 2017-03-17 11:19 +1100
    Re: When to use !name vs. name! ? rickman <gnuarm@gmail.com> - 2017-03-16 20:46 -0400
      Re: When to use !name vs. name! ? "Elizabeth D. Rather" <erather@forth.com> - 2017-03-16 21:34 -1000
        Re: When to use !name vs. name! ? "HAA" <someone@microsoft.com> - 2017-03-18 09:49 +1100
          Re: When to use !name vs. name! ? "Elizabeth D. Rather" <erather@forth.com> - 2017-03-17 13:08 -1000
            Re: When to use !name vs. name! ? rickman <gnuarm@gmail.com> - 2017-03-17 19:35 -0400
              Re: When to use !name vs. name! ? Mark Wills <markwills1970@gmail.com> - 2017-03-18 00:51 -0700
              Re: When to use !name vs. name! ? "HAA" <someone@microsoft.com> - 2017-03-19 10:47 +1100
                Re: When to use !name vs. name! ? rickman <gnuarm@gmail.com> - 2017-03-18 22:18 -0400
                  Re: When to use !name vs. name! ? "Elizabeth D. Rather" <erather@forth.com> - 2017-03-18 16:36 -1000
                    Re: When to use !name vs. name! ? rickman <gnuarm@gmail.com> - 2017-03-18 23:53 -0400
                      Re: When to use !name vs. name! ? "Elizabeth D. Rather" <erather@forth.com> - 2017-03-18 22:22 -1000
                        Re: When to use !name vs. name! ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-19 16:03 +0000
                          Re: When to use !name vs. name! ? Alex <alex@rivadpm.com> - 2017-03-19 17:42 +0000
                            Re: When to use !name vs. name! ? "Elizabeth D. Rather" <erather@forth.com> - 2017-03-19 13:10 -1000
                    Re: When to use !name vs. name! ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-03-19 13:34 +0100
                      Re: When to use !name vs. name! ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-19 16:23 +0000
                        Re: When to use !name vs. name! ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-03-19 20:47 +0100
                          Re: When to use !name vs. name! ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-03-20 03:47 -0500
                  Re: When to use !name vs. name! ? "HAA" <someone@microsoft.com> - 2017-03-20 09:41 +1100
                    Re: When to use !name vs. name! ? Coos Haak <htrofhc@gmail.com> - 2017-03-20 01:24 +0100
                      Re: When to use !name vs. name! ? "HAA" <someone@microsoft.com> - 2017-03-21 12:10 +1100
                        Re: When to use !name vs. name! ? hughaguilar96@gmail.com - 2017-03-20 18:45 -0700
                        Re: When to use !name vs. name! ? Coos Haak <htrofhc@gmail.com> - 2017-03-21 14:58 +0100
                          Re: When to use !name vs. name! ? "HAA" <someone@microsoft.com> - 2017-03-22 19:49 +1100
            Re: When to use !name vs. name! ? hughaguilar96@gmail.com - 2017-03-17 16:46 -0700
    Re: When to use  !name  vs.  name! ? Lars Brinkhoff <lars.spam@nocrew.org> - 2017-04-12 08:13 +0200

Page 2 of 2 — ← Prev page 1 [2]


#55930 — Re: When to use !name vs. name! ?

FromAlex <alex@rivadpm.com>
Date2017-03-19 17:42 +0000
SubjectRe: When to use !name vs. name! ?
Message-ID<oamfnv$rrb$1@dont-email.me>
In reply to#55927
On 3/19/2017 16:03, Anton Ertl wrote:
> "Elizabeth D. Rather" <erather@forth.com> writes:

>
>> In most ITC Forths, the stack pointer is in a register, and an increment
>> or shift is one instruction (possibly indirect). There is no read or
>> write. I don't remember any instruction sets in which it is not possible
>> to increment or shift left the TOS in one instruction. A C
>> implementation, of course, may be much less efficient.
>
> Just to illustrate this, here's what you get in gforth-fast:
>
> : foo 1+ 2* ;  ok
> : bar 1 + 2 * ;  ok
> see-code foo
> $7F2CA4B88390 1+
> 7F2CA4AF6505:   add     rbx,$08   \ update ip (of threaded code)
> 7F2CA4AF6509:   add     r14,$01   \ tos = tos + 1
> $7F2CA4B88398 2*
> 7F2CA4AF650D:   add     rbx,$08   \ update ip (of threaded code)
> 7F2CA4AF6511:   add     r14,r14   \ tos = tos + tos
> $7F2CA4B883A0 ;s
> see-code bar
> $7F2CA4B883E0 lit
> $7F2CA4B883E8 <$1>
> $7F2CA4B883F0 <$0>                \ actually +, but combined with LIT
> 7F2CA4AF6529:   add     r14,[rbx] \ tos = tos + *ip
> 7F2CA4AF652C:   add     rbx,$18   \ update ip (of threaded code)
> $7F2CA4B883F8 noop                \ actually LIT, decompiler acting up
> $7F2CA4B88400 <$2>
> 7F2CA4AF6530:   mov     [r15],r14
> 7F2CA4AF6533:   sub     r15,$08
> 7F2CA4AF6537:   mov     rax,rbx
> 7F2CA4AF653A:   lea     rbx,$10[rbx]
> 7F2CA4AF653E:   mov     r14,[rax]
> $7F2CA4B88408 *
> 7F2CA4AF6541:   mov     rax,r15
> 7F2CA4AF6544:   lea     r15,$08[r15]
> 7F2CA4AF6548:   add     rbx,$08
> 7F2CA4AF654C:   imul    r14,$08[rax]
> $7F2CA4B88410 ;s ok
>
> In the BAR example you see that Gforth-fast has a static
> superinstruction for "lit <num> +", but none for "lit <num> *".  So
> for the "2 *" you see all the stack access overhead.  You don't see
> threaded-code overhead apart from the ip updates thanks to dynamic
> superinstructions.  And it looks like we are now using Intel assembler
> syntax in the disassembler.

STC Experimental 32bit: 0.06.08 Build: 781
: foo 1+ 2* ;  ok
: bar 1 + 2 * ;  ok
see foo
: foo ( ? -- ? )
\ foo is defined in (console)
\ call compiled
\ code=$41C550 len=5 type=130
( $0 )    add     eax $1                            \ 83C001
( $3 )    add     eax eax                           \ 03C0
( $5 )    ret                                       \ C3 ( end ) ok
see bar
: bar ( ? -- ? )
\ bar is defined in (console)
\ call compiled
\ code=$41C55B len=5 type=130
( $0 )    add     eax $1                            \ 83C001
( $3 )    add     eax eax                           \ 03C0
( $5 )    ret                                       \ C3 ( end ) ok

I'm still working on a full optimizer (using SSA) but this one is not 
hard to optimize.

-- 
Alex

[toc] | [prev] | [next] | [standalone]


#55950 — Re: When to use !name vs. name! ?

From"Elizabeth D. Rather" <erather@forth.com>
Date2017-03-19 13:10 -1000
SubjectRe: When to use !name vs. name! ?
Message-ID<kZ6dnVXpy6t0klLFnZ2dnUU7-VfNnZ2d@supernews.com>
In reply to#55930
On 3/19/17 7:42 AM, Alex wrote:
> On 3/19/2017 16:03, Anton Ertl wrote:
>> "Elizabeth D. Rather" <erather@forth.com> writes:
>
>>
>>> In most ITC Forths, the stack pointer is in a register, and an increment
>>> or shift is one instruction (possibly indirect). There is no read or
>>> write. I don't remember any instruction sets in which it is not possible
>>> to increment or shift left the TOS in one instruction. A C
>>> implementation, of course, may be much less efficient.
>>
>> Just to illustrate this, here's what you get in gforth-fast:
>>
>> : foo 1+ 2* ;  ok
>> : bar 1 + 2 * ;  ok
>> see-code foo
>> $7F2CA4B88390 1+
>> 7F2CA4AF6505:   add     rbx,$08   \ update ip (of threaded code)
>> 7F2CA4AF6509:   add     r14,$01   \ tos = tos + 1
>> $7F2CA4B88398 2*
>> 7F2CA4AF650D:   add     rbx,$08   \ update ip (of threaded code)
>> 7F2CA4AF6511:   add     r14,r14   \ tos = tos + tos
>> $7F2CA4B883A0 ;s
>> see-code bar
>> $7F2CA4B883E0 lit
>> $7F2CA4B883E8 <$1>
>> $7F2CA4B883F0 <$0>                \ actually +, but combined with LIT
>> 7F2CA4AF6529:   add     r14,[rbx] \ tos = tos + *ip
>> 7F2CA4AF652C:   add     rbx,$18   \ update ip (of threaded code)
>> $7F2CA4B883F8 noop                \ actually LIT, decompiler acting up
>> $7F2CA4B88400 <$2>
>> 7F2CA4AF6530:   mov     [r15],r14
>> 7F2CA4AF6533:   sub     r15,$08
>> 7F2CA4AF6537:   mov     rax,rbx
>> 7F2CA4AF653A:   lea     rbx,$10[rbx]
>> 7F2CA4AF653E:   mov     r14,[rax]
>> $7F2CA4B88408 *
>> 7F2CA4AF6541:   mov     rax,r15
>> 7F2CA4AF6544:   lea     r15,$08[r15]
>> 7F2CA4AF6548:   add     rbx,$08
>> 7F2CA4AF654C:   imul    r14,$08[rax]
>> $7F2CA4B88410 ;s ok
>>
>> In the BAR example you see that Gforth-fast has a static
>> superinstruction for "lit <num> +", but none for "lit <num> *".  So
>> for the "2 *" you see all the stack access overhead.  You don't see
>> threaded-code overhead apart from the ip updates thanks to dynamic
>> superinstructions.  And it looks like we are now using Intel assembler
>> syntax in the disassembler.
>
> STC Experimental 32bit: 0.06.08 Build: 781
> : foo 1+ 2* ;  ok
> : bar 1 + 2 * ;  ok
> see foo
> : foo ( ? -- ? )
> \ foo is defined in (console)
> \ call compiled
> \ code=$41C550 len=5 type=130
> ( $0 )    add     eax $1                            \ 83C001
> ( $3 )    add     eax eax                           \ 03C0
> ( $5 )    ret                                       \ C3 ( end ) ok
> see bar
> : bar ( ? -- ? )
> \ bar is defined in (console)
> \ call compiled
> \ code=$41C55B len=5 type=130
> ( $0 )    add     eax $1                            \ 83C001
> ( $3 )    add     eax eax                           \ 03C0
> ( $5 )    ret                                       \ C3 ( end ) ok
>
> I'm still working on a full optimizer (using SSA) but this one is not
> hard to optimize.

So, the evidence seems to be that for Gforth there's still good value in 
defining 1+ and 2*, but optimizing Forths not so much.

Cheers,
Elizabeth

-- 
Elizabeth R. Conklin
FORTH, Inc.
6080 Center Drive, Suite 600
Los Angeles, CA  90045
USA

[toc] | [prev] | [next] | [standalone]


#55922 — Re: When to use !name vs. name! ?

Fromalbert@cherry.spenarnc.xs4all.nl (Albert van der Horst)
Date2017-03-19 13:34 +0100
SubjectRe: When to use !name vs. name! ?
Message-ID<oaltt2$of8$1@cherry.spenarnc.xs4all.nl>
In reply to#55917
In article <bJmdndkW2_YCc1DFnZ2dnUU7-U_NnZ2d@supernews.com>,
Elizabeth D. Rather <erather@forth.com> wrote:
>On 3/18/17 4:18 PM, rickman wrote:
>> On 3/18/2017 7:47 PM, HAA wrote:
>>> rickman wrote:
>>>> On 3/17/2017 7:08 PM, Elizabeth D. Rather wrote:
>>>>> ...
>>>>> It depends on the word. Words that simply fetch a value from a variable
>>>>> aren't substantive enough to justify separates @/! definitions, so it
>>>>> really depends on what the rest of the action is. I can imagine an
>>>>> application that uses a thermocouple, for example. The name of the port
>>>>> that controls it is Thermo.  I would have words like !Thermo to
>>>>> write to
>>>>> it and @Thermo to read it and maybe perform a calibration. I would
>>>>> prefer to have the symbol first in these cases because it's the action
>>>>> that's important, not the thing being acted upon.
>>>>
>>>> So reverse the method used across Forth because the action is important?
>>>>   Is it really not important what it is acting on?  I think it is the
>>>> opposite.  The noun should be first since that is the important part.
>>>> The verb is last because it only has meaning in the context of what it
>>>> is acting on.
>>>> ...
>>>
>>> There are numerous cases where the action comes first and the object the
>>> qualification e.g. open/close-file  read/write-line  get/set-order,
>>> begin/end-xxx.
>>> In this context  @/!name  becomes shortform for get/set restore/save etc.
>>> Where the action is trivial e.g. peek/poke memory then the object takes
>>> precedence and reflects the stack order. e.g. name@/! .  Being a trivial
>>> operation however, there may be little need for defining a such a
>>> function.
>>
>> But the fetch and store operations have an operator @ and !.  Usage is
>> <name> @ or <name> !.  Combining these words into one operator the
>> convention would be name@ or name!.  I've seen this guideline explicitly
>> stated for cases like 1+ or 2* and many others.
>
>The trivial case, combining <name> @/! into one, is hardly worth doing.
>1+ and 2*, on the other hand, are worth defining in code on ITC
>implementations because they can resolve to a single machine
>instruction, which is why they're in CORE.

I can see that these words are worth having, especially 2/ that is
a bit manipulation despite the misleading name.
On two's complement machine it is the same then '' 2 / '' , but it is
mostly used instead of the much less terse '' 1 RSHIFT '' as long as
the 63-th bit is not involved.

I can't see why they are in the CORE wordset, instead of the
OBSOLETE_OPTIMISATIONS wordset, however.
Especially 1+ is a waste in the presence of an optimiser.
While '' 1 + '' optimises just fine, a code word for 1+ warrants
special attention in an optimiser.

>
>Cheers,
>Elizabeth

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#55928 — Re: When to use !name vs. name! ?

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2017-03-19 16:23 +0000
SubjectRe: When to use !name vs. name! ?
Message-ID<2017Mar19.172304@mips.complang.tuwien.ac.at>
In reply to#55922
albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) writes:
>I can see that these words are worth having, especially 2/ that is
>a bit manipulation despite the misleading name.
>On two's complement machine it is the same then '' 2 / ''

Only if / is floored:

SwiftForth i386-Linux 3.6.3 29-Jun-2016 
-1 2 / . 0  ok
-1 2/ . -1  ok

VFX Forth for Linux IA32 Version: 4.72 [build 0555]
-1 2 / . 0  ok
-1 2/ . -1  ok

Gforth 0.7.2, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
-1 2 / . -1  ok
-1 2/ . -1  ok

>While '' 1 + '' optimises just fine, a code word for 1+ warrants
>special attention in an optimiser.

Why would you write 1+ as a code word if your optimizer can handle "1 +"?

: 1+ 1 + ;

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2016: http://www.euroforth.org/ef16/

[toc] | [prev] | [next] | [standalone]


#55939 — Re: When to use !name vs. name! ?

Fromalbert@cherry.spenarnc.xs4all.nl (Albert van der Horst)
Date2017-03-19 20:47 +0100
SubjectRe: When to use !name vs. name! ?
Message-ID<oamn86$sdf$1@cherry.spenarnc.xs4all.nl>
In reply to#55928
In article <2017Mar19.172304@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) writes:
>>I can see that these words are worth having, especially 2/ that is
>>a bit manipulation despite the misleading name.
>>On two's complement machine it is the same then '' 2 / ''
>
>Only if / is floored:
>
>SwiftForth i386-Linux 3.6.3 29-Jun-2016
>-1 2 / . 0  ok
>-1 2/ . -1  ok
>
>VFX Forth for Linux IA32 Version: 4.72 [build 0555]
>-1 2 / . 0  ok
>-1 2/ . -1  ok

My bad, I only remembered never to use 2/ for division, because
under some circumstances it is not the same. Apparently more
circumstances than I thought. I once had 2/ as a loadable extension
using FM/MOD but now I just have a code word that uses SHR, .

>
>Gforth 0.7.2, Copyright (C) 1995-2008 Free Software Foundation, Inc.
>Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
>Type `bye' to exit
>-1 2 / . -1  ok
>-1 2/ . -1  ok
>
>>While '' 1 + '' optimises just fine, a code word for 1+ warrants
>>special attention in an optimiser.
>
>Why would you write 1+ as a code word if your optimizer can handle "1 +"?
>
>: 1+ 1 + ;

Exactly. Why write "1+" if your optimiser handles "1 +".

>
>- anton

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#55958 — Re: When to use !name vs. name! ?

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2017-03-20 03:47 -0500
SubjectRe: When to use !name vs. name! ?
Message-ID<7-KdndIK7-mmClLFnZ2dnUU7-e_NnZ2d@supernews.com>
In reply to#55939
Albert van der Horst <albert@cherry.spenarnc.xs4all.nl> wrote:
> In article <2017Mar19.172304@mips.complang.tuwien.ac.at>,
> Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>Why would you write 1+ as a code word if your optimizer can handle "1 +"?
>>
>>: 1+ 1 + ;
> 
> Exactly. Why write "1+" if your optimiser handles "1 +".

For me, it's a conceptual thing: "1+" is the successor function, which
I think of as more primitive than "+ n".  In the same way, 2/ is a
more primitive operation than division in general.  I believe that ths
is more to do with the way I learned Forth than anything more
fundamental: if I'd learned Forth on a system without "1+" I wouldn't
miss it.

Andrew.

[toc] | [prev] | [next] | [standalone]


#55948 — Re: When to use !name vs. name! ?

From"HAA" <someone@microsoft.com>
Date2017-03-20 09:41 +1100
SubjectRe: When to use !name vs. name! ?
Message-ID<oan19q$12u3$1@gioia.aioe.org>
In reply to#55916
rickman wrote:
> On 3/18/2017 7:47 PM, HAA wrote:
> > rickman wrote:
> >> On 3/17/2017 7:08 PM, Elizabeth D. Rather wrote:
> >>> ...
> >>> It depends on the word. Words that simply fetch a value from a variable
> >>> aren't substantive enough to justify separates @/! definitions, so it
> >>> really depends on what the rest of the action is. I can imagine an
> >>> application that uses a thermocouple, for example. The name of the port
> >>> that controls it is Thermo.  I would have words like !Thermo to write to
> >>> it and @Thermo to read it and maybe perform a calibration. I would
> >>> prefer to have the symbol first in these cases because it's the action
> >>> that's important, not the thing being acted upon.
> >>
> >> So reverse the method used across Forth because the action is important?
> >>   Is it really not important what it is acting on?  I think it is the
> >> opposite.  The noun should be first since that is the important part.
> >> The verb is last because it only has meaning in the context of what it
> >> is acting on.
> >> ...
> >
> > There are numerous cases where the action comes first and the object the
> > qualification e.g. open/close-file  read/write-line  get/set-order, begin/end-xxx.
> > In this context  @/!name  becomes shortform for get/set restore/save etc.
> > Where the action is trivial e.g. peek/poke memory then the object takes
> > precedence and reflects the stack order. e.g. name@/! .  Being a trivial
> > operation however, there may be little need for defining a such a function.
>
> But the fetch and store operations have an operator @ and !.  Usage is
> <name> @ or <name> !.  Combining these words into one operator the
> convention would be name@ or name!.  I've seen this guideline explicitly
> stated for cases like 1+ or 2* and many others.

If it is advantageous for trivial functions to have names indicative of the stack
effect - is it not also advantageous to differentiate functions that are not simple
or indicative?  Forth has GET-ORDER SET-ORDER not ORDER@ ORDER!
because ORDER is a concept, not a memory location.


[toc] | [prev] | [next] | [standalone]


#55954 — Re: When to use !name vs. name! ?

FromCoos Haak <htrofhc@gmail.com>
Date2017-03-20 01:24 +0100
SubjectRe: When to use !name vs. name! ?
Message-ID<170lq1srs0rqt$.p4ckv826gjru.dlg@40tude.net>
In reply to#55948
Op Mon, 20 Mar 2017 09:41:11 +1100 schreef HAA:

> rickman wrote:
>> On 3/18/2017 7:47 PM, HAA wrote:
>>> rickman wrote:
>>>> On 3/17/2017 7:08 PM, Elizabeth D. Rather wrote:
>>>>> ...
>>>>> It depends on the word. Words that simply fetch a value from a variable
>>>>> aren't substantive enough to justify separates @/! definitions, so it
>>>>> really depends on what the rest of the action is. I can imagine an
>>>>> application that uses a thermocouple, for example. The name of the port
>>>>> that controls it is Thermo.  I would have words like !Thermo to write to
>>>>> it and @Thermo to read it and maybe perform a calibration. I would
>>>>> prefer to have the symbol first in these cases because it's the action
>>>>> that's important, not the thing being acted upon.
>>>>
>>>> So reverse the method used across Forth because the action is important?
>>>>   Is it really not important what it is acting on?  I think it is the
>>>> opposite.  The noun should be first since that is the important part.
>>>> The verb is last because it only has meaning in the context of what it
>>>> is acting on.
>>>> ...
>>>
>>> There are numerous cases where the action comes first and the object the
>>> qualification e.g. open/close-file  read/write-line  get/set-order, begin/end-xxx.
>>> In this context  @/!name  becomes shortform for get/set restore/save etc.
>>> Where the action is trivial e.g. peek/poke memory then the object takes
>>> precedence and reflects the stack order. e.g. name@/! .  Being a trivial
>>> operation however, there may be little need for defining a such a function.
>>
>> But the fetch and store operations have an operator @ and !.  Usage is
>> <name> @ or <name> !.  Combining these words into one operator the
>> convention would be name@ or name!.  I've seen this guideline explicitly
>> stated for cases like 1+ or 2* and many others.
> 
> If it is advantageous for trivial functions to have names indicative of the stack
> effect - is it not also advantageous to differentiate functions that are not simple
> or indicative?  Forth has GET-ORDER SET-ORDER not ORDER@ ORDER!
> because ORDER is a concept, not a memory location.

Forths with the SEARCH WORDLIST have GET-ORDER and SET-ORDER
They deliver or store a structure consisting of wid's and a number.
I have seen implementations that had ORDER@ and ORDER!
Those were synonyms of (FigForth) CONTEXT @ and CONTEXT ! respectively.

Another example. I have a pointer that gives its value by saying
MYPTR and setting to another value by >MYPTR .
The first is used more often, so writing of MYPTR> is distracting.

groet Coos

[toc] | [prev] | [next] | [standalone]


#55985 — Re: When to use !name vs. name! ?

From"HAA" <someone@microsoft.com>
Date2017-03-21 12:10 +1100
SubjectRe: When to use !name vs. name! ?
Message-ID<oapudj$icj$1@gioia.aioe.org>
In reply to#55954
Coos Haak wrote:
> Op Mon, 20 Mar 2017 09:41:11 +1100 schreef HAA:
>
> > rickman wrote:
> >> On 3/18/2017 7:47 PM, HAA wrote:
> >>> rickman wrote:
> >>>> On 3/17/2017 7:08 PM, Elizabeth D. Rather wrote:
> >>>>> ...
> >>>>> It depends on the word. Words that simply fetch a value from a variable
> >>>>> aren't substantive enough to justify separates @/! definitions, so it
> >>>>> really depends on what the rest of the action is. I can imagine an
> >>>>> application that uses a thermocouple, for example. The name of the port
> >>>>> that controls it is Thermo.  I would have words like !Thermo to write to
> >>>>> it and @Thermo to read it and maybe perform a calibration. I would
> >>>>> prefer to have the symbol first in these cases because it's the action
> >>>>> that's important, not the thing being acted upon.
> >>>>
> >>>> So reverse the method used across Forth because the action is important?
> >>>>   Is it really not important what it is acting on?  I think it is the
> >>>> opposite.  The noun should be first since that is the important part.
> >>>> The verb is last because it only has meaning in the context of what it
> >>>> is acting on.
> >>>> ...
> >>>
> >>> There are numerous cases where the action comes first and the object the
> >>> qualification e.g. open/close-file  read/write-line  get/set-order, begin/end-xxx.
> >>> In this context  @/!name  becomes shortform for get/set restore/save etc.
> >>> Where the action is trivial e.g. peek/poke memory then the object takes
> >>> precedence and reflects the stack order. e.g. name@/! .  Being a trivial
> >>> operation however, there may be little need for defining a such a function.
> >>
> >> But the fetch and store operations have an operator @ and !.  Usage is
> >> <name> @ or <name> !.  Combining these words into one operator the
> >> convention would be name@ or name!.  I've seen this guideline explicitly
> >> stated for cases like 1+ or 2* and many others.
> >
> > If it is advantageous for trivial functions to have names indicative of the stack
> > effect - is it not also advantageous to differentiate functions that are not simple
> > or indicative?  Forth has GET-ORDER SET-ORDER not ORDER@ ORDER!
> > because ORDER is a concept, not a memory location.
>
> Forths with the SEARCH WORDLIST have GET-ORDER and SET-ORDER
> They deliver or store a structure consisting of wid's and a number.
> I have seen implementations that had ORDER@ and ORDER!
> Those were synonyms of (FigForth) CONTEXT @ and CONTEXT ! respectively.

CONTEXT was a simple variable where a trailing @/! operator was appropriate.
GET/SET-ORDER reflects a more complex function where the emphasis is on
the action, not the object.

> Another example. I have a pointer that gives its value by saying
> MYPTR and setting to another value by >MYPTR .
> The first is used more often, so writing of MYPTR> is distracting.
>
> groet Coos

The opposite of >MYPTR would typically be named <MYPTR.  Relevant here is
how the action (to/from) precedes the object.


[toc] | [prev] | [next] | [standalone]


#55987 — Re: When to use !name vs. name! ?

Fromhughaguilar96@gmail.com
Date2017-03-20 18:45 -0700
SubjectRe: When to use !name vs. name! ?
Message-ID<d72651c4-5f0f-4027-8290-dc7606e2b95b@googlegroups.com>
In reply to#55985
On Monday, March 20, 2017 at 6:08:08 PM UTC-7, HAA wrote:
> Coos Haak wrote:
> > Op Mon, 20 Mar 2017 09:41:11 +1100 schreef HAA:
> >
> > > rickman wrote:
> > >> On 3/18/2017 7:47 PM, HAA wrote:
> > >>> rickman wrote:
> > >>>> On 3/17/2017 7:08 PM, Elizabeth D. Rather wrote:
> > >>>>> ...
> > >>>>> It depends on the word. Words that simply fetch a value from a variable
> > >>>>> aren't substantive enough to justify separates @/! definitions, so it
> > >>>>> really depends on what the rest of the action is. I can imagine an
> > >>>>> application that uses a thermocouple, for example. The name of the port
> > >>>>> that controls it is Thermo.  I would have words like !Thermo to write to
> > >>>>> it and @Thermo to read it and maybe perform a calibration. I would
> > >>>>> prefer to have the symbol first in these cases because it's the action
> > >>>>> that's important, not the thing being acted upon.
> > >>>>
> > >>>> So reverse the method used across Forth because the action is important?
> > >>>>   Is it really not important what it is acting on?  I think it is the
> > >>>> opposite.  The noun should be first since that is the important part.
> > >>>> The verb is last because it only has meaning in the context of what it
> > >>>> is acting on.
> > >>>> ...
> > >>>
> > >>> There are numerous cases where the action comes first and the object the
> > >>> qualification e.g. open/close-file  read/write-line  get/set-order, begin/end-xxx.
> > >>> In this context  @/!name  becomes shortform for get/set restore/save etc.
> > >>> Where the action is trivial e.g. peek/poke memory then the object takes
> > >>> precedence and reflects the stack order. e.g. name@/! .  Being a trivial
> > >>> operation however, there may be little need for defining a such a function.
> > >>
> > >> But the fetch and store operations have an operator @ and !.  Usage is
> > >> <name> @ or <name> !.  Combining these words into one operator the
> > >> convention would be name@ or name!.  I've seen this guideline explicitly
> > >> stated for cases like 1+ or 2* and many others.
> > >
> > > If it is advantageous for trivial functions to have names indicative of the stack
> > > effect - is it not also advantageous to differentiate functions that are not simple
> > > or indicative?  Forth has GET-ORDER SET-ORDER not ORDER@ ORDER!
> > > because ORDER is a concept, not a memory location.
> >
> > Forths with the SEARCH WORDLIST have GET-ORDER and SET-ORDER
> > They deliver or store a structure consisting of wid's and a number.
> > I have seen implementations that had ORDER@ and ORDER!
> > Those were synonyms of (FigForth) CONTEXT @ and CONTEXT ! respectively.
> 
> CONTEXT was a simple variable where a trailing @/! operator was appropriate.
> GET/SET-ORDER reflects a more complex function where the emphasis is on
> the action, not the object.
> 
> > Another example. I have a pointer that gives its value by saying
> > MYPTR and setting to another value by >MYPTR .
> > The first is used more often, so writing of MYPTR> is distracting.
> >
> > groet Coos
> 
> The opposite of >MYPTR would typically be named <MYPTR.  Relevant here is
> how the action (to/from) precedes the object.

My naming convention is to use MYPTR! and MYPTR@ --- I wouldn't use >MYPTR and <MYPTR at all.

I use the > to indicate a conversion --- for example, I have STR>NUM in the novice-package --- also, Forth has always had S>D for single to double.

I use <XXX and XXX> as brackets --- although I sometimes use XXX and END-XXX instead. An example is <SWITCH and FAST-SWITCH> in the LIST.4TH package.

I also put the pointy brackets around low-level words. For example, I have this in the LIST.4TH package:

: <show-seq> ( node -- )
    .line @ count type  cr ;

: show-seq ( head -- )
    cr
    ['] <show-seq>  each ;

\ SHOW-SEQ uses EACH rather than EACH[...]EACH because <SHOW-SEQ> is useful in its own right.

[toc] | [prev] | [next] | [standalone]


#56004 — Re: When to use !name vs. name! ?

FromCoos Haak <htrofhc@gmail.com>
Date2017-03-21 14:58 +0100
SubjectRe: When to use !name vs. name! ?
Message-ID<ykyhp10ac44f$.1ov0maneuxnh$.dlg@40tude.net>
In reply to#55985
Op Tue, 21 Mar 2017 12:10:16 +1100 schreef HAA:

> Coos Haak wrote:
>> Op Mon, 20 Mar 2017 09:41:11 +1100 schreef HAA:
>>
>>> rickman wrote:
>>>> On 3/18/2017 7:47 PM, HAA wrote:
>>>>> rickman wrote:
>>>>>> On 3/17/2017 7:08 PM, Elizabeth D. Rather wrote:
>>>>>>> ...
>>>>>>> It depends on the word. Words that simply fetch a value from a variable
>>>>>>> aren't substantive enough to justify separates @/! definitions, so it
>>>>>>> really depends on what the rest of the action is. I can imagine an
>>>>>>> application that uses a thermocouple, for example. The name of the port
>>>>>>> that controls it is Thermo.  I would have words like !Thermo to write to
>>>>>>> it and @Thermo to read it and maybe perform a calibration. I would
>>>>>>> prefer to have the symbol first in these cases because it's the action
>>>>>>> that's important, not the thing being acted upon.
>>>>>>
>>>>>> So reverse the method used across Forth because the action is important?
>>>>>>   Is it really not important what it is acting on?  I think it is the
>>>>>> opposite.  The noun should be first since that is the important part.
>>>>>> The verb is last because it only has meaning in the context of what it
>>>>>> is acting on.
>>>>>> ...
>>>>>
>>>>> There are numerous cases where the action comes first and the object the
>>>>> qualification e.g. open/close-file  read/write-line  get/set-order, begin/end-xxx.
>>>>> In this context  @/!name  becomes shortform for get/set restore/save etc.
>>>>> Where the action is trivial e.g. peek/poke memory then the object takes
>>>>> precedence and reflects the stack order. e.g. name@/! .  Being a trivial
>>>>> operation however, there may be little need for defining a such a function.
>>>>
>>>> But the fetch and store operations have an operator @ and !.  Usage is
>>>> <name> @ or <name> !.  Combining these words into one operator the
>>>> convention would be name@ or name!.  I've seen this guideline explicitly
>>>> stated for cases like 1+ or 2* and many others.
>>>
>>> If it is advantageous for trivial functions to have names indicative of the stack
>>> effect - is it not also advantageous to differentiate functions that are not simple
>>> or indicative?  Forth has GET-ORDER SET-ORDER not ORDER@ ORDER!
>>> because ORDER is a concept, not a memory location.
>>
>> Forths with the SEARCH WORDLIST have GET-ORDER and SET-ORDER
>> They deliver or store a structure consisting of wid's and a number.
>> I have seen implementations that had ORDER@ and ORDER!
>> Those were synonyms of (FigForth) CONTEXT @ and CONTEXT ! respectively.
> 
> CONTEXT was a simple variable where a trailing @/! operator was appropriate.
> GET/SET-ORDER reflects a more complex function where the emphasis is on
> the action, not the object.
> 
>> Another example. I have a pointer that gives its value by saying
>> MYPTR and setting to another value by >MYPTR .
>> The first is used more often, so writing of MYPTR> is distracting.
>>
>> groet Coos
> 
> The opposite of >MYPTR would typically be named <MYPTR.  Relevant here is
> how the action (to/from) precedes the object.

The opposite of >R is R>. The action follows the object here.
I've seen very old Forth that had <R.

groet Coos

[toc] | [prev] | [next] | [standalone]


#56081 — Re: When to use !name vs. name! ?

From"HAA" <someone@microsoft.com>
Date2017-03-22 19:49 +1100
SubjectRe: When to use !name vs. name! ?
Message-ID<oatdmk$aqq$1@gioia.aioe.org>
In reply to#56004
Coos Haak wrote:
> Op Tue, 21 Mar 2017 12:10:16 +1100 schreef HAA:
>
> > Coos Haak wrote:
> >> Op Mon, 20 Mar 2017 09:41:11 +1100 schreef HAA:
> >>> ...
> >>> If it is advantageous for trivial functions to have names indicative of the stack
> >>> effect - is it not also advantageous to differentiate functions that are not simple
> >>> or indicative?  Forth has GET-ORDER SET-ORDER not ORDER@ ORDER!
> >>> because ORDER is a concept, not a memory location.
> >>
> >> Forths with the SEARCH WORDLIST have GET-ORDER and SET-ORDER
> >> They deliver or store a structure consisting of wid's and a number.
> >> I have seen implementations that had ORDER@ and ORDER!
> >> Those were synonyms of (FigForth) CONTEXT @ and CONTEXT ! respectively.
> >
> > CONTEXT was a simple variable where a trailing @/! operator was appropriate.
> > GET/SET-ORDER reflects a more complex function where the emphasis is on
> > the action, not the object.
> >
> >> Another example. I have a pointer that gives its value by saying
> >> MYPTR and setting to another value by >MYPTR .
> >> The first is used more often, so writing of MYPTR> is distracting.
> >>
> >> groet Coos
> >
> > The opposite of >MYPTR would typically be named <MYPTR.  Relevant here is
> > how the action (to/from) precedes the object.
>
> The opposite of >R is R>. The action follows the object here.
> I've seen very old Forth that had <R.
>
> groet Coos

You have described several conventions including examples where they
contradicted, your own among them.  What is your point?




[toc] | [prev] | [next] | [standalone]


#55882 — Re: When to use !name vs. name! ?

Fromhughaguilar96@gmail.com
Date2017-03-17 16:46 -0700
SubjectRe: When to use !name vs. name! ?
Message-ID<f4f86a19-dbd1-40a4-bfde-843521b0ea1c@googlegroups.com>
In reply to#55878
On Friday, March 17, 2017 at 4:08:32 PM UTC-7, Elizabeth D. Rather wrote:
> On 3/17/17 12:49 PM, HAA wrote:
> > Elizabeth D. Rather wrote:
> >> On 3/16/17 2:46 PM, rickman wrote:
> >>> I guess I'm showing my lack of experience, but when do fetch and store
> >>> words not use parameters on the stack?
> >>>
> >>> I thought there was already a convention that words which are
> >>> functionally equivalent to name @ and name ! would be name@ and name!
> >>> respectively.  No?
> >>>
> >>> What would you need @name for?
> >>
> >> That's a carryover from the very early days, when Forth names were
> >> stored in the dictionary as count+1st 3 chars. In the era of extreme
> >> memory conservation (mostly the 70's; at NRAO Chuck controlled the 36'
> >> radio telescope and its dome and managed 4 concurrent terminals with
> >> operators in a 32Kb computer) that was necessary. So, we put the operant
> >> symbol (@ or !) first.
> >
> > Never considered that.  Would you then regard it as an obsolete convention
> > best forgotten - or would it have some (new) use today?
> 
> It depends on the word. Words that simply fetch a value from a variable 
> aren't substantive enough to justify separates @/! definitions, so it 
> really depends on what the rest of the action is. I can imagine an 
> application that uses a thermocouple, for example. The name of the port 
> that controls it is Thermo.  I would have words like !Thermo to write to 
> it and @Thermo to read it and maybe perform a calibration. I would 
> prefer to have the symbol first in these cases because it's the action 
> that's important, not the thing being acted upon.

It is obsolete. She is now (in the year 2017) trying to justify a bad decision by inventing a fake reason for it.

Huffman compression can be implemented pretty easily and it works reasonably well. This would slow down compilation, but if it is written in assembly-language it shouldn't be too bad. It is still necessary to tell the users to keep their names' length down --- but the users don't have to arrange the chars in their names in any weird way to avoid clashes --- there are no clashes.

It has always been a convention that words functionally equivalent to NAME @ and NAME ! would be NAME@ and NAME! --- I had never considered that the reason why anybody would use @NAME and !NAME instead is to avoid a clash in the PolyForth dictionary storage scheme --- that does explain it though.

Huffman compression can be implemented pretty easily and it works reasonably well. This would slow down compilation, but if it is written in assembly-language it shouldn't be too bad. It is still necessary to tell the users to keep their names' length down --- but the users don't have to arrange the chars in their names in any weird way to avoid clashes --- there are no clashes.

Charles Moore is a genius, but some of his ideas were remarkably bad. That goofy dictionary storage scheme was one of them! A lot of bad programming that he did, I think, was just an expedient measure to get a program out under deadline --- he didn't expect it to last forever --- he got kicked out of Forth Inc. in 1982 and PolyForth continued to use his goofy dictionary storage scheme after MS-DOS came out and memory no longer was a problem.

If Charles Moore hadn't gotten kicked out of Forth Inc. in 1982, he would have likely fixed a lot of the problems in PolyForth. PolyForth could have become a viable Forth system --- instead, UR/Forth became the only professional Forth system (there were other Forth systems such as CMPforth that were pretty good, but weren't as popular) --- PolyForth continued to use 1970s technology and was obsoleted by QBASIC (PolyForth was better than GW-BASIC though).

[toc] | [prev] | [next] | [standalone]


#57109

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2017-04-12 08:13 +0200
Message-ID<86lgr6upad.fsf@molnjunk.nocrew.org>
In reply to#55741
> This has come up before but without resolution i.e. when to use the
> form !name @name vs.  name!  name@ ?

In ANS Forth, <name>! and <name>@ usually means "access an item of type
<name>", i.e. 2! 2@ C! C@ F! F@ etc.  I think the 2012 addition of
DEFER@ and DEFER! follows this usage.  A notable exception would be R@.

In the F18 instruction set, <name>! means "store into <name>", and
!<name> means "store into memory addressed by <name>".  This is in line
with the traditional words SP! SP@ RP! RP@.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.forth


csiph-web