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


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

A use for quotations

Started byGerry Jackson <gerry@jackson9000.fsnet.co.uk>
First post2016-08-14 19:51 +0100
Last post2016-08-18 07:35 +0000
Articles 9 on this page of 29 — 10 participants

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


Contents

  A use for quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-08-14 19:51 +0100
    Re: A use for quotations Bernd Paysan <bernd.paysan@gmx.de> - 2016-08-14 19:44 +0000
      Re: A use for quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-08-14 22:57 +0100
    Re: A use for quotations hughaguilar96@gmail.com - 2016-08-14 14:05 -0700
      Re: A use for quotations Cecil Bayona <cbayona@cbayona.com> - 2016-08-14 16:16 -0500
    Re: A use for quotations "HAA" <someone@microsoft.com> - 2016-08-17 11:29 +1000
      Re: A use for quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-08-17 10:06 +0100
        Re: A use for quotations "HAA" <someone@microsoft.com> - 2016-08-18 12:18 +1000
          Re: A use for quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-08-19 16:07 +0100
            Re: A use for quotations "Elizabeth D. Rather" <erather@forth.com> - 2016-08-19 09:35 -1000
              Re: A use for quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-08-19 23:03 +0100
            Re: A use for quotations "HAA" <someone@microsoft.com> - 2016-08-20 13:19 +1000
              Re: A use for quotations Coos Haak <htrofhc@gmail.com> - 2016-08-20 14:55 +0200
                Re: A use for quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-20 15:38 +0000
                Re: A use for quotations "HAA" <someone@microsoft.com> - 2016-08-22 14:58 +1000
                  Re: A use for quotations Julian Fondren <julian.fondren@gmail.com> - 2016-08-22 04:18 -0700
                  Re: A use for quotations Coos Haak <htrofhc@gmail.com> - 2016-08-22 15:13 +0200
                    Re: A use for quotations "HAA" <someone@microsoft.com> - 2016-08-24 22:20 +1000
                      Re: A use for quotations hughaguilar96@gmail.com - 2016-08-24 09:44 -0700
                      Re: A use for quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-08-25 10:09 +0100
                        Re: A use for quotations "HAA" <someone@microsoft.com> - 2016-08-27 12:24 +1000
    Re: A use for quotations humptydumpty <ouatubi@gmail.com> - 2016-08-17 00:55 -0700
      Re: A use for quotations hughaguilar96@gmail.com - 2016-08-17 02:19 -0700
        Re: A use for quotations humptydumpty <ouatubi@gmail.com> - 2016-08-17 07:49 -0700
          Re: A use for quotations humptydumpty <ouatubi@gmail.com> - 2016-08-17 08:18 -0700
      Re: A use for quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-08-17 10:30 +0100
        Re: A use for quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-08-17 10:34 +0100
          Re: A use for quotations humptydumpty <ouatubi@gmail.com> - 2016-08-17 07:43 -0700
        Re: A use for quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-18 07:35 +0000

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


#50502

From"HAA" <someone@microsoft.com>
Date2016-08-27 12:24 +1000
Message-ID<npqtl5$a3h$1@gioia.aioe.org>
In reply to#50465
Gerry Jackson wrote:
> On 24/08/2016 13:20, HAA wrote:
> > ...
> > I'm not complaining.  I'm pointing out the absurdity of namelessness.
>
> Whether it's absurd or not depends on the context, for example if using
> the original mini-oof and two classes inherit from a base class with a
> method called foo it is not absurd to give :NONAME definitions a name e.g.
>
> :noname ... ; class1 defines foo
> :noname ... ; class2 defines foo
>
> class1 new constant obj1
> class2 new constant obj2
>
> obj1 foo   \ executes the first :noname
> obj2 foo   \ executes the second :noname
>
> Just one example.
>
> > If I have to give something a temporary name, or put it into a temporary
> > named definition, or engage in any extra work to get around the fact that
> > something hasn't got a name, then perhaps it's trying to tell me something.
> >
>
> It's telling you that *you* yourself can't test unnamed definitions and
> I think you are in a small minority there. Have you actually tried or
> are you just prejudiced?

I stand by my statement *AS I SAID IT*.  I won't defend unnamed
definitions at any cost.  If that means being misrepresented and
accused of incompetence or prejudice, so be it.


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


#50179

Fromhumptydumpty <ouatubi@gmail.com>
Date2016-08-17 00:55 -0700
Message-ID<1c742f18-8f6a-49cd-96d3-6fe0be6fddfa@googlegroups.com>
In reply to#50093
On Sunday, August 14, 2016 at 9:51:36 PM UTC+3, Gerry wrote:
> In the RfD for quotations it states that quotations just provide 
> syntactic sugar for code that can be written using :NONAME. This has led 
> to some opposition with statements summarised by "why bother and 
> complicate Forth with an unnecessary feature". I think the example below 
> shows that having quotations provides an opportunity for design 
> approaches that wouldn't be taken were quotations not available, i.e. it 
> wouldn't be implemented that way using :NONAME because of the complexity.
> 
> The example is for pattern matching using regular expressions (RE) 
> where, given this usage:
> 
> s" <regular expression>" regex$ foo
> s" <text>" foo
> 
> REGEX$ ( caddr u -- ) compiles code representing the RE expression into 
> the word FOO.
> 
> FOO (caddr u -- caddr2 u2 f ) matches text against the RE.
> 
> The compiled code in FOO follows this pattern for each (sub)RE:
> 
> : foo ... [: 2dup <code implementing the (sub)RE> ;] CATCH ... ;
> 
> where the code after CATCH varies depending on whether the quotation was 
> generated by one of the RE operators ? | * +
> 
> Because the (sub)RE is arbitrarily complex the quotations will be nested 
> appropriately, for example given the RE:
>     a((bc(def*)g(h|j|k))+)?l
> quotations will be nested 4 deep.
> 
> The use of CATCH and THROW handles backtracking in the event of failure. 
> I had some qualms about (mis)using exceptions for this purpose but it is 
> so convenient that I did it anyway despite reduced efficiency.
> 
> I've implemented this, using LexGen and Grace to relieve the tedium of 
> parsing RE's, and it works well on both my system and GForth. It was 
> also easy to write the code generators once I had decided on the 
> approach to take. I suspect that if and when I develop this into a more 
> complete system, access to outer local variables could be useful - 
> although that needs more thought.
> 
> Incidentally I had a quick look at GForth's implementation regexp.fs 
> but, as I couldn't find any documentation or examples of use, recoiled 
> from trying to understand how it works or even trying to use it. Are 
> there any examples or even test files available for this?
> 
> -- 
> Gerry

Hi!

Another mechanism to go back to parents caller:

bo@linux-h5s7:~> gforth
Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
2variable backp  ok             
: backs> R@ RP@ cell+ backp 2! ;  ok
: back   backp 2@ RP! >R ;  ok               
: bottom   1- ?dup IF back THEN ;   ok       
: middle  ." pre-mid " bottom ." post.mid " ;  ok
: top     ." pre-top " middle ." post.top " ;  ok
: test  ( n -- ) ." init " backs> top cr .s ;  ok
clearstack cr 1 test 
init pre-top pre-mid post.mid post.top 
<0>  ok
clearstack cr 2 test 
init pre-top pre-mid pre-top pre-mid post.mid post.top 
<0>  ok
clearstack cr 3 test 
init pre-top pre-mid pre-top pre-mid pre-top pre-mid post.mid post.top 
<0>  ok


--
Have a nice day,
humptydumpty

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


#50181

Fromhughaguilar96@gmail.com
Date2016-08-17 02:19 -0700
Message-ID<bcfeac4b-2296-4021-a889-bcd0afd5621e@googlegroups.com>
In reply to#50179
On Wednesday, August 17, 2016 at 12:55:13 AM UTC-7, humptydumpty wrote:
> On Sunday, August 14, 2016 at 9:51:36 PM UTC+3, Gerry wrote:
> > In the RfD for quotations it states that quotations just provide 
> > syntactic sugar for code that can be written using :NONAME. This has led 
> > to some opposition with statements summarised by "why bother and 
> > complicate Forth with an unnecessary feature". I think the example below 
> > shows that having quotations provides an opportunity for design 
> > approaches that wouldn't be taken were quotations not available, i.e. it 
> > wouldn't be implemented that way using :NONAME because of the complexity.
> > 
> > The example is for pattern matching using regular expressions (RE) 
> > where, given this usage:
> > 
> > s" <regular expression>" regex$ foo
> > s" <text>" foo
> > 
> > REGEX$ ( caddr u -- ) compiles code representing the RE expression into 
> > the word FOO.
> > 
> > FOO (caddr u -- caddr2 u2 f ) matches text against the RE.
> > 
> > The compiled code in FOO follows this pattern for each (sub)RE:
> > 
> > : foo ... [: 2dup <code implementing the (sub)RE> ;] CATCH ... ;
> > 
> > where the code after CATCH varies depending on whether the quotation was 
> > generated by one of the RE operators ? | * +
> > 
> > Because the (sub)RE is arbitrarily complex the quotations will be nested 
> > appropriately, for example given the RE:
> >     a((bc(def*)g(h|j|k))+)?l
> > quotations will be nested 4 deep.
> > 
> > The use of CATCH and THROW handles backtracking in the event of failure. 
> > I had some qualms about (mis)using exceptions for this purpose but it is 
> > so convenient that I did it anyway despite reduced efficiency.
> > 
> > I've implemented this, using LexGen and Grace to relieve the tedium of 
> > parsing RE's, and it works well on both my system and GForth. It was 
> > also easy to write the code generators once I had decided on the 
> > approach to take. I suspect that if and when I develop this into a more 
> > complete system, access to outer local variables could be useful - 
> > although that needs more thought.
> > 
> > Incidentally I had a quick look at GForth's implementation regexp.fs 
> > but, as I couldn't find any documentation or examples of use, recoiled 
> > from trying to understand how it works or even trying to use it. Are 
> > there any examples or even test files available for this?
> > 
> > -- 
> > Gerry
> 
> Hi!
> 
> Another mechanism to go back to parents caller:
> 
> bo@linux-h5s7:~> gforth
> Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
> Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
> Type `bye' to exit
> 2variable backp  ok             
> : backs> R@ RP@ cell+ backp 2! ;  ok
> : back   backp 2@ RP! >R ;  ok               
> : bottom   1- ?dup IF back THEN ;   ok       
> : middle  ." pre-mid " bottom ." post.mid " ;  ok
> : top     ." pre-top " middle ." post.top " ;  ok
> : test  ( n -- ) ." init " backs> top cr .s ;  ok
> clearstack cr 1 test 
> init pre-top pre-mid post.mid post.top 
> <0>  ok
> clearstack cr 2 test 
> init pre-top pre-mid pre-top pre-mid post.mid post.top 
> <0>  ok
> clearstack cr 3 test 
> init pre-top pre-mid pre-top pre-mid pre-top pre-mid post.mid post.top 
> <0>  ok

I started to write RP! and RP@ in VFX assembly-language, but then I remembered what Stephen Pelc has told me repeatedly: "RTFM!" So I read the VFX manual, and found that they were already there --- that saved me some time --- RTFM can pay off occasionally!

Your code is easier to use than CATCH and THROW so I put it in the novice-package as VFX-specific code --- apparently it works under Gforth too, because that is what you tested under, and I don't know about SwiftForth --- I don't bother to support Gforth or SwiftForth anymore, so I don't care.

I wrote quite a lot of SwiftForth assembly-language in the novice-package (I doubled the speed of programs such as SLIDE-RULE.4TH that rely heavily on lists) --- I think that I will delete all of that in the next release of the novice-package --- it clutters up the source-code, and Elizabeth Rather said that my novice-package was "written by a novice," so I will just delete my SwiftForh assembly-language code and forget everything I knew about SwiftForth internal workings.

In MS-DOS days, to be a Forth programmer it was necessary to disassemble UR/Forth and know all of the internal workings (when I interviewed for the job at Testra that is the only thing they asked about) --- nowadays it is necessary to disassemble VFX and know all of the internal workings --- ANS-Forth has zero value; SwiftForth and Gforth have less.

Stephen Pelc only jumped onto the Forth-200x bandwagon for the purpose of dragging his feet --- he wants everybody to ignore ANS-Forth and Forth-200x --- he makes his money by selling VFX as the true standard, so he wants the Standard to be as crippled as possible in order for VFX to look good by comparison.

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


#50190

Fromhumptydumpty <ouatubi@gmail.com>
Date2016-08-17 07:49 -0700
Message-ID<25b6c2ea-7f2a-4927-aac0-5916a750076e@googlegroups.com>
In reply to#50181
On Wednesday, August 17, 2016 at 12:19:50 PM UTC+3, hughag...@gmail.com wrote:
> On Wednesday, August 17, 2016 at 12:55:13 AM UTC-7, humptydumpty wrote:
> > On Sunday, August 14, 2016 at 9:51:36 PM UTC+3, Gerry wrote:
> > > In the RfD for quotations it states that quotations just provide 
> > > syntactic sugar for code that can be written using :NONAME. This has led 
> > > to some opposition with statements summarised by "why bother and 
> > > complicate Forth with an unnecessary feature". I think the example below 
> > > shows that having quotations provides an opportunity for design 
> > > approaches that wouldn't be taken were quotations not available, i.e. it 
> > > wouldn't be implemented that way using :NONAME because of the complexity.
> > > 
> > > The example is for pattern matching using regular expressions (RE) 
> > > where, given this usage:
> > > 
> > > s" <regular expression>" regex$ foo
> > > s" <text>" foo
> > > 
> > > REGEX$ ( caddr u -- ) compiles code representing the RE expression into 
> > > the word FOO.
> > > 
> > > FOO (caddr u -- caddr2 u2 f ) matches text against the RE.
> > > 
> > > The compiled code in FOO follows this pattern for each (sub)RE:
> > > 
> > > : foo ... [: 2dup <code implementing the (sub)RE> ;] CATCH ... ;
> > > 
> > > where the code after CATCH varies depending on whether the quotation was 
> > > generated by one of the RE operators ? | * +
> > > 
> > > Because the (sub)RE is arbitrarily complex the quotations will be nested 
> > > appropriately, for example given the RE:
> > >     a((bc(def*)g(h|j|k))+)?l
> > > quotations will be nested 4 deep.
> > > 
> > > The use of CATCH and THROW handles backtracking in the event of failure. 
> > > I had some qualms about (mis)using exceptions for this purpose but it is 
> > > so convenient that I did it anyway despite reduced efficiency.
> > > 
> > > I've implemented this, using LexGen and Grace to relieve the tedium of 
> > > parsing RE's, and it works well on both my system and GForth. It was 
> > > also easy to write the code generators once I had decided on the 
> > > approach to take. I suspect that if and when I develop this into a more 
> > > complete system, access to outer local variables could be useful - 
> > > although that needs more thought.
> > > 
> > > Incidentally I had a quick look at GForth's implementation regexp.fs 
> > > but, as I couldn't find any documentation or examples of use, recoiled 
> > > from trying to understand how it works or even trying to use it. Are 
> > > there any examples or even test files available for this?
> > > 
> > > -- 
> > > Gerry
> > 
> > Hi!
> > 
> > Another mechanism to go back to parents caller:
> > 
> > bo@linux-h5s7:~> gforth
> > Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
> > Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
> > Type `bye' to exit
> > 2variable backp  ok             
> > : backs> R@ RP@ cell+ backp 2! ;  ok
> > : back   backp 2@ RP! >R ;  ok               
> > : bottom   1- ?dup IF back THEN ;   ok       
> > : middle  ." pre-mid " bottom ." post.mid " ;  ok
> > : top     ." pre-top " middle ." post.top " ;  ok
> > : test  ( n -- ) ." init " backs> top cr .s ;  ok
> > clearstack cr 1 test 
> > init pre-top pre-mid post.mid post.top 
> > <0>  ok
> > clearstack cr 2 test 
> > init pre-top pre-mid pre-top pre-mid post.mid post.top 
> > <0>  ok
> > clearstack cr 3 test 
> > init pre-top pre-mid pre-top pre-mid pre-top pre-mid post.mid post.top 
> > <0>  ok
> 
> I started to write RP! and RP@ in VFX assembly-language, but then I remembered what Stephen Pelc has told me repeatedly: "RTFM!" So I read the VFX manual, and found that they were already there --- that saved me some time --- RTFM can pay off occasionally!
> 
> Your code is easier to use than CATCH and THROW so I put it in the novice-package as VFX-specific code --- apparently it works under Gforth too, because that is what you tested under, and I don't know about SwiftForth --- I don't bother to support Gforth or SwiftForth anymore, so I don't care.
> 
> I wrote quite a lot of SwiftForth assembly-language in the novice-package (I doubled the speed of programs such as SLIDE-RULE.4TH that rely heavily on lists) --- I think that I will delete all of that in the next release of the novice-package --- it clutters up the source-code, and Elizabeth Rather said that my novice-package was "written by a novice," so I will just delete my SwiftForh assembly-language code and forget everything I knew about SwiftForth internal workings.
> 
> In MS-DOS days, to be a Forth programmer it was necessary to disassemble UR/Forth and know all of the internal workings (when I interviewed for the job at Testra that is the only thing they asked about) --- nowadays it is necessary to disassemble VFX and know all of the internal workings --- ANS-Forth has zero value; SwiftForth and Gforth have less.
> 
> Stephen Pelc only jumped onto the Forth-200x bandwagon for the purpose of dragging his feet --- he wants everybody to ignore ANS-Forth and Forth-200x --- he makes his money by selling VFX as the true standard, so he wants the Standard to be as crippled as possible in order for VFX to look good by comparison.

Hi!

I know that you were interested in locals implementations.
Here is another use of END ENDS> macro builders:

\ rlocals.fs

: ENDS> R> ;
: END   >R ; IMMEDIATE

	VARIABLE LEVELS
: ONE	1 DUP 1- LEVELS ! ; IMMEDIATE
: TWO	2 DUP 1- LEVELS ! ; IMMEDIATE
: THREE	3 DUP 1- LEVELS ! ; IMMEDIATE
: FOUR	4 DUP 1- LEVELS ! ; IMMEDIATE

	VARIABLE RC
: N>R
	R> RC !
	0 over = IF drop RC @ >R EXIT THEN
	1 over = IF drop >R RC @ >R EXIT THEN
	2 over = IF drop >R >R RC @ >R EXIT THEN
	3 over = IF drop >R >R >R RC @ >R EXIT THEN
	ABORT" N>R: TOO MUCH LOCALS!"
;
: NR>
	R> RC !
	0 over = IF drop RC @ >R EXIT THEN
	1 over = IF drop R> RC @ >R EXIT THEN
	2 over = IF drop R> R> RC @ >R EXIT THEN
	3 over = IF drop R> R> R> RC @ >R EXIT THEN
	ABORT" N>R: TOO MUCH LOCALS!"
;
: RLOCALS	( ctime: u -- ) ( rtime: -- alocals )
	1- ?DUP
	POSTPONE >R
	IF
		RECURSE
	ELSE
		POSTPONE RP@
		LEVELS @ NR> ENDS> LEVELS @ N>R
	THEN
	POSTPONE RDROP
; IMMEDIATE

1 [IF]
: .up-locals	( a -- )
	cr ." Test of visibilty of parents locals: "
	dup 0 th ?
	    1 th ?
;
: test		( n0 n1 -- )
	TWO RLOCALS
		dup 0 th ?
		dup 1 th ?
		    .up-locals
	END
;
[THEN]

And test:

bo@linux-h5s7:~/src> gforth rlocals.fs -e '9 10 TEST see TEST .s cr bye'
9 10 
Test of visibilty of parents locals: 9 10 
: test  
  >r >r rp@ dup 0 th ? dup 1 th ? .up-locals rdrop rdrop ;<0> 

--
Have a nice day,
humptydumpty

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


#50191

Fromhumptydumpty <ouatubi@gmail.com>
Date2016-08-17 08:18 -0700
Message-ID<b5d0c6e6-587c-4e16-9e48-8fd103e803b0@googlegroups.com>
In reply to#50190
On Wednesday, August 17, 2016 at 5:49:49 PM UTC+3, humptydumpty wrote:
> On Wednesday, August 17, 2016 at 12:19:50 PM UTC+3, hughag...@gmail.com wrote:
> > On Wednesday, August 17, 2016 at 12:55:13 AM UTC-7, humptydumpty wrote:
> > > On Sunday, August 14, 2016 at 9:51:36 PM UTC+3, Gerry wrote:
> > > > In the RfD for quotations it states that quotations just provide 
> > > > syntactic sugar for code that can be written using :NONAME. This has led 
> > > > to some opposition with statements summarised by "why bother and 
> > > > complicate Forth with an unnecessary feature". I think the example below 
> > > > shows that having quotations provides an opportunity for design 
> > > > approaches that wouldn't be taken were quotations not available, i.e. it 
> > > > wouldn't be implemented that way using :NONAME because of the complexity.
> > > > 
> > > > The example is for pattern matching using regular expressions (RE) 
> > > > where, given this usage:
> > > > 
> > > > s" <regular expression>" regex$ foo
> > > > s" <text>" foo
> > > > 
> > > > REGEX$ ( caddr u -- ) compiles code representing the RE expression into 
> > > > the word FOO.
> > > > 
> > > > FOO (caddr u -- caddr2 u2 f ) matches text against the RE.
> > > > 
> > > > The compiled code in FOO follows this pattern for each (sub)RE:
> > > > 
> > > > : foo ... [: 2dup <code implementing the (sub)RE> ;] CATCH ... ;
> > > > 
> > > > where the code after CATCH varies depending on whether the quotation was 
> > > > generated by one of the RE operators ? | * +
> > > > 
> > > > Because the (sub)RE is arbitrarily complex the quotations will be nested 
> > > > appropriately, for example given the RE:
> > > >     a((bc(def*)g(h|j|k))+)?l
> > > > quotations will be nested 4 deep.
> > > > 
> > > > The use of CATCH and THROW handles backtracking in the event of failure. 
> > > > I had some qualms about (mis)using exceptions for this purpose but it is 
> > > > so convenient that I did it anyway despite reduced efficiency.
> > > > 
> > > > I've implemented this, using LexGen and Grace to relieve the tedium of 
> > > > parsing RE's, and it works well on both my system and GForth. It was 
> > > > also easy to write the code generators once I had decided on the 
> > > > approach to take. I suspect that if and when I develop this into a more 
> > > > complete system, access to outer local variables could be useful - 
> > > > although that needs more thought.
> > > > 
> > > > Incidentally I had a quick look at GForth's implementation regexp.fs 
> > > > but, as I couldn't find any documentation or examples of use, recoiled 
> > > > from trying to understand how it works or even trying to use it. Are 
> > > > there any examples or even test files available for this?
> > > > 
> > > > -- 
> > > > Gerry
> > > 
> > > Hi!
> > > 
> > > Another mechanism to go back to parents caller:
> > > 
> > > bo@linux-h5s7:~> gforth
> > > Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
> > > Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
> > > Type `bye' to exit
> > > 2variable backp  ok             
> > > : backs> R@ RP@ cell+ backp 2! ;  ok
> > > : back   backp 2@ RP! >R ;  ok               
> > > : bottom   1- ?dup IF back THEN ;   ok       
> > > : middle  ." pre-mid " bottom ." post.mid " ;  ok
> > > : top     ." pre-top " middle ." post.top " ;  ok
> > > : test  ( n -- ) ." init " backs> top cr .s ;  ok
> > > clearstack cr 1 test 
> > > init pre-top pre-mid post.mid post.top 
> > > <0>  ok
> > > clearstack cr 2 test 
> > > init pre-top pre-mid pre-top pre-mid post.mid post.top 
> > > <0>  ok
> > > clearstack cr 3 test 
> > > init pre-top pre-mid pre-top pre-mid pre-top pre-mid post.mid post.top 
> > > <0>  ok
> > 
> > I started to write RP! and RP@ in VFX assembly-language, but then I remembered what Stephen Pelc has told me repeatedly: "RTFM!" So I read the VFX manual, and found that they were already there --- that saved me some time --- RTFM can pay off occasionally!
> > 
> > Your code is easier to use than CATCH and THROW so I put it in the novice-package as VFX-specific code --- apparently it works under Gforth too, because that is what you tested under, and I don't know about SwiftForth --- I don't bother to support Gforth or SwiftForth anymore, so I don't care.
> > 
> > I wrote quite a lot of SwiftForth assembly-language in the novice-package (I doubled the speed of programs such as SLIDE-RULE.4TH that rely heavily on lists) --- I think that I will delete all of that in the next release of the novice-package --- it clutters up the source-code, and Elizabeth Rather said that my novice-package was "written by a novice," so I will just delete my SwiftForh assembly-language code and forget everything I knew about SwiftForth internal workings.
> > 
> > In MS-DOS days, to be a Forth programmer it was necessary to disassemble UR/Forth and know all of the internal workings (when I interviewed for the job at Testra that is the only thing they asked about) --- nowadays it is necessary to disassemble VFX and know all of the internal workings --- ANS-Forth has zero value; SwiftForth and Gforth have less.
> > 
> > Stephen Pelc only jumped onto the Forth-200x bandwagon for the purpose of dragging his feet --- he wants everybody to ignore ANS-Forth and Forth-200x --- he makes his money by selling VFX as the true standard, so he wants the Standard to be as crippled as possible in order for VFX to look good by comparison.
> 
> Hi!
> 
> I know that you were interested in locals implementations.
> Here is another use of END ENDS> macro builders:
> 
> \ rlocals.fs
> 
> : ENDS> R> ;
> : END   >R ; IMMEDIATE
> 
> 	VARIABLE LEVELS
> : ONE	1 DUP 1- LEVELS ! ; IMMEDIATE
> : TWO	2 DUP 1- LEVELS ! ; IMMEDIATE
> : THREE	3 DUP 1- LEVELS ! ; IMMEDIATE
> : FOUR	4 DUP 1- LEVELS ! ; IMMEDIATE
> 
> 	VARIABLE RC
> : N>R
> 	R> RC !
> 	0 over = IF drop RC @ >R EXIT THEN
> 	1 over = IF drop >R RC @ >R EXIT THEN
> 	2 over = IF drop >R >R RC @ >R EXIT THEN
> 	3 over = IF drop >R >R >R RC @ >R EXIT THEN
> 	ABORT" N>R: TOO MUCH LOCALS!"
> ;
> : NR>
> 	R> RC !
> 	0 over = IF drop RC @ >R EXIT THEN
> 	1 over = IF drop R> RC @ >R EXIT THEN
> 	2 over = IF drop R> R> RC @ >R EXIT THEN
> 	3 over = IF drop R> R> R> RC @ >R EXIT THEN
> 	ABORT" N>R: TOO MUCH LOCALS!"
> ;
> : RLOCALS	( ctime: u -- ) ( rtime: -- alocals )
> 	1- ?DUP
> 	POSTPONE >R
> 	IF
> 		RECURSE
> 	ELSE
> 		POSTPONE RP@
> 		LEVELS @ NR> ENDS> LEVELS @ N>R
> 	THEN
> 	POSTPONE RDROP
> ; IMMEDIATE
> 
> 1 [IF]
> : .up-locals	( a -- )
> 	cr ." Test of visibilty of parents locals: "
> 	dup 0 th ?
> 	    1 th ?
> ;
> : test		( n0 n1 -- )
> 	TWO RLOCALS
> 		dup 0 th ?
> 		dup 1 th ?
> 		    .up-locals
> 	END
> ;
> [THEN]
> 
> And test:
> 
> bo@linux-h5s7:~/src> gforth rlocals.fs -e '9 10 TEST see TEST .s cr bye'
> 9 10 
> Test of visibilty of parents locals: 9 10 
> : test  
>   >r >r rp@ dup 0 th ? dup 1 th ? .up-locals rdrop rdrop ;<0> 
> 
> --
> Have a nice day,
> humptydumpty

Overcomplicated!

: ends> R> ;
: end   >R ; immediate

: rlocal postpone >r postpone rp@ ends> postpone rdrop ; immediate
: 2rlocals postpone >r postpone >r
           postpone rp@ ends>
           postpone rdrop postpone rdrop ; immediate
: 3rlocals postpone >r postpone >r postpone >r
           postpone rp@ ends>
           postpone rdrop postpone rdrop postpone rdrop ; immediate
: 4rlocals postpone >r postpone >r postpone >r postpone >r
           postpone rp@ ends>
           postpone rdrop postpone rdrop postpone rdrop postpone rdrop ; immediate

: test 2rlocals dup 0 th ? 1 th ? end ;

Testing:

99 100 cr test .s 
99 100 <0>  ok

--
humptydumpty

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


#50183

FromGerry Jackson <gerry@jackson9000.fsnet.co.uk>
Date2016-08-17 10:30 +0100
Message-ID<np1arh$7o6$1@dont-email.me>
In reply to#50179
On 17/08/2016 08:55, humptydumpty wrote:
> On Sunday, August 14, 2016 at 9:51:36 PM UTC+3, Gerry wrote:
>>
>> The use of CATCH and THROW handles backtracking in the event of failure.
>> I had some qualms about (mis)using exceptions for this purpose but it is
>> so convenient that I did it anyway despite reduced efficiency.
>>
> Hi!
>
> Another mechanism to go back to parents caller:
>
> bo@linux-h5s7:~> gforth
> Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
> Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
> Type `bye' to exit
> 2variable backp  ok
> : backs> R@ RP@ cell+ backp 2! ;  ok
> : back   backp 2@ RP! >R ;  ok
> : bottom   1- ?dup IF back THEN ;   ok
> : middle  ." pre-mid " bottom ." post.mid " ;  ok
> : top     ." pre-top " middle ." post.top " ;  ok
> : test  ( n -- ) ." init " backs> top cr .s ;  ok
> clearstack cr 1 test
> init pre-top pre-mid post.mid post.top
> <0>  ok
> clearstack cr 2 test
> init pre-top pre-mid pre-top pre-mid post.mid post.top
> <0>  ok
> clearstack cr 3 test
> init pre-top pre-mid pre-top pre-mid pre-top pre-mid post.mid post.top
> <0>  ok
>

Well that not standard ANS Forth/Forth 2012 code. At the risk of being 
accused of being a brown noser, I prefer to stick to complying with the 
standard. I have thought that if performance becomes an issue I would 
provide a lightweight mechanism such as you suggest. I haven't pursued 
that thought any further - is there a guaranteed non-crashing way of 
testing whether return stack manipulation works on an ANS Forth system? 
If so I could conditionally compile a lightweight version.

I did post some code providing a similar mechanism to yours here
https://groups.google.com/forum/?hl=en#!topic/comp.lang.forth/b0rpNOd8WF8%5B76-100%5D

-- 
Gerry

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


#50184

FromGerry Jackson <gerry@jackson9000.fsnet.co.uk>
Date2016-08-17 10:34 +0100
Message-ID<np1b38$7o6$2@dont-email.me>
In reply to#50183
On 17/08/2016 10:30, Gerry Jackson wrote:
> On 17/08/2016 08:55, humptydumpty wrote:
>> On Sunday, August 14, 2016 at 9:51:36 PM UTC+3, Gerry wrote:
>>>
>>> The use of CATCH and THROW handles backtracking in the event of failure.
>>> I had some qualms about (mis)using exceptions for this purpose but it is
>>> so convenient that I did it anyway despite reduced efficiency.
>>>
>> Hi!
>>
>> Another mechanism to go back to parents caller:
>>
>> bo@linux-h5s7:~> gforth
>> Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
>> Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
>> Type `bye' to exit
>> 2variable backp  ok
>> : backs> R@ RP@ cell+ backp 2! ;  ok
>> : back   backp 2@ RP! >R ;  ok
>> : bottom   1- ?dup IF back THEN ;   ok
>> : middle  ." pre-mid " bottom ." post.mid " ;  ok
>> : top     ." pre-top " middle ." post.top " ;  ok
>> : test  ( n -- ) ." init " backs> top cr .s ;  ok
>> clearstack cr 1 test
>> init pre-top pre-mid post.mid post.top
>> <0>  ok
>> clearstack cr 2 test
>> init pre-top pre-mid pre-top pre-mid post.mid post.top
>> <0>  ok
>> clearstack cr 3 test
>> init pre-top pre-mid pre-top pre-mid pre-top pre-mid post.mid post.top
>> <0>  ok
>>
>
> Well that not standard ANS Forth/Forth 2012 code. At the risk of being
> accused of being a brown noser, I prefer to stick to complying with the
> standard. I have thought that if performance becomes an issue I would
> provide a lightweight mechanism such as you suggest. I haven't pursued
> that thought any further - is there a guaranteed non-crashing way of
> testing whether return stack manipulation works on an ANS Forth system?
> If so I could conditionally compile a lightweight version.
>
> I did post some code providing a similar mechanism to yours here
> https://groups.google.com/forum/?hl=en#!topic/comp.lang.forth/b0rpNOd8WF8%5B76-100%5D
>
>
I hate Google Groups, that link nearly gets you there, you have to 
scroll down several messages to one dated 3/6/15 (American date format 
i.e. 6 March)

-- 
Gerry

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


#50189

Fromhumptydumpty <ouatubi@gmail.com>
Date2016-08-17 07:43 -0700
Message-ID<f339278f-c024-425a-a347-3e4084f39730@googlegroups.com>
In reply to#50184
On Wednesday, August 17, 2016 at 12:34:33 PM UTC+3, Gerry wrote:
> On 17/08/2016 10:30, Gerry Jackson wrote:
> > On 17/08/2016 08:55, humptydumpty wrote:
> >> On Sunday, August 14, 2016 at 9:51:36 PM UTC+3, Gerry wrote:
> >>>
> >>> The use of CATCH and THROW handles backtracking in the event of failure.
> >>> I had some qualms about (mis)using exceptions for this purpose but it is
> >>> so convenient that I did it anyway despite reduced efficiency.
> >>>
> >> Hi!
> >>
> >> Another mechanism to go back to parents caller:
> >>
> >> bo@linux-h5s7:~> gforth
> >> Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
> >> Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
> >> Type `bye' to exit
> >> 2variable backp  ok
> >> : backs> R@ RP@ cell+ backp 2! ;  ok
> >> : back   backp 2@ RP! >R ;  ok
> >> : bottom   1- ?dup IF back THEN ;   ok
> >> : middle  ." pre-mid " bottom ." post.mid " ;  ok
> >> : top     ." pre-top " middle ." post.top " ;  ok
> >> : test  ( n -- ) ." init " backs> top cr .s ;  ok
> >> clearstack cr 1 test
> >> init pre-top pre-mid post.mid post.top
> >> <0>  ok
> >> clearstack cr 2 test
> >> init pre-top pre-mid pre-top pre-mid post.mid post.top
> >> <0>  ok
> >> clearstack cr 3 test
> >> init pre-top pre-mid pre-top pre-mid pre-top pre-mid post.mid post.top
> >> <0>  ok
> >>
> >
> > Well that not standard ANS Forth/Forth 2012 code. At the risk of being
> > accused of being a brown noser, I prefer to stick to complying with the
> > standard. I have thought that if performance becomes an issue I would
> > provide a lightweight mechanism such as you suggest. I haven't pursued
> > that thought any further - is there a guaranteed non-crashing way of
> > testing whether return stack manipulation works on an ANS Forth system?
> > If so I could conditionally compile a lightweight version.
> >
> > I did post some code providing a similar mechanism to yours here
> > https://groups.google.com/forum/?hl=en#!topic/comp.lang.forth/b0rpNOd8WF8%5B76-100%5D
> >
> >
> I hate Google Groups, that link nearly gets you there, you have to 
> scroll down several messages to one dated 3/6/15 (American date format 
> i.e. 6 March)
> 
> -- 
> Gerry

Hi!

Interesting! I'm used to return stack continuations, but manipulations
of return stack pointer really should be used with care :)

I do not understand reluctance of using continuations...
If there are implementations that use 2 cells for a continuation,
why not propose a standard word RCELL that have the size of 
return stack continuation.

As for continuations, I'm very pleased with pair END ENDS>

--
Have a nice day,
humptydumpty

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


#50200

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2016-08-18 07:35 +0000
Message-ID<2016Aug18.093554@mips.complang.tuwien.ac.at>
In reply to#50183
Gerry Jackson <gerry@jackson9000.fsnet.co.uk> writes:
>Well that not standard ANS Forth/Forth 2012 code. At the risk of being 
>accused of being a brown noser, I prefer to stick to complying with the 
>standard. I have thought that if performance becomes an issue I would 
>provide a lightweight mechanism such as you suggest. I haven't pursued 
>that thought any further - is there a guaranteed non-crashing way of 
>testing whether return stack manipulation works on an ANS Forth system? 

No.  There is not even a crashing way.  Some programs that use
return-address manipulation may work as intended on a system, and some
other programs don't work as intended.  Typical issues in modern
systems are:

* The system uses tail-call elimination or inlining, i.e., the call
  does not push a return address.

* Locals work differently than in the system for which the program was
  developed.  This can be avoided by not using locals in any of the
  words that are involved in the return-address manipulation.

* The code for a word has a different size and representation than
  expected by the program.  This is relevant for programs that try to
  skip code by applying, e.g., CELL+ to a return address to skip code.

* Likewise, if the program tries to compile inline data by ","
  etc. after a return-address manipulating word, and then skipping
  that data by adding to the return address, this does not work if the
  code is somewhere else than ALLOTed data.

- 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] | [standalone]


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

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


csiph-web