Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #40544 > unrolled thread
| Started by | Tessa Bonting <tessa.bonting@gmail.com> |
|---|---|
| First post | 2015-07-12 06:48 -0700 |
| Last post | 2015-08-06 21:19 +0200 |
| Articles | 20 on this page of 126 — 22 participants |
Back to article view | Back to comp.lang.forth
How do quotation work, I can not foound them in 20xx Tessa Bonting <tessa.bonting@gmail.com> - 2015-07-12 06:48 -0700
Re: How do quotation work, I can not foound them in 20xx anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-07-12 15:10 +0000
Re: How do quotation work, I can not foound them in 20xx Tessa Bonting <tessa.bonting@gmail.com> - 2015-07-12 08:47 -0700
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-13 01:15 -0700
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-13 01:20 -0700
Re: How do quotation work, I can not foound them in 20xx Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-07-13 01:30 -0700
Re: How do quotation work, I can not foound them in 20xx Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-07-13 01:33 -0700
Re: How do quotation work, I can not foound them in 20xx Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-07-13 01:28 -0700
Re: How do quotation work, I can not foound them in 20xx Julian Fondren <julian.fondren@gmail.com> - 2015-07-12 08:23 -0700
Re: How do quotation work, I can not foound them in 20xx Coos Haak <chforth@hccnet.nl> - 2015-07-12 18:56 +0200
Re: How do quotation work, I can not foound them in 20xx Julian Fondren <julian.fondren@gmail.com> - 2015-07-13 20:24 -0700
Re: How do quotation work, I can not foound them in 20xx Coos Haak <chforth@hccnet.nl> - 2015-07-14 09:43 +0200
Re: How do quotation work, I can not foound them in 20xx "HAA" <someone@microsoft.com> - 2015-07-18 14:18 +1000
Re: How do quotation work, I can not foound them in 20xx "HAA" <someone@microsoft.com> - 2015-08-01 12:46 +1000
Re: How do quotation work, I can not foound them in 20xx mhx@iae.nl - 2015-08-01 00:52 -0700
Re: How do quotation work, I can not foound them in 20xx "HAA" <someone@microsoft.com> - 2015-08-02 18:16 +1000
Re: How do quotation work, I can not foound them in 20xx mhx@iae.nl - 2015-08-02 02:18 -0700
Re: How do quotation work, I can not foound them in 20xx "HAA" <someone@microsoft.com> - 2015-08-05 13:35 +1000
Re: How do quotation work, I can not foound them in 20xx Bernd Paysan <bernd.paysan@gmx.de> - 2015-08-01 21:37 +0200
Re: How do quotation work, I can not foound them in 20xx JennyB <jennybrien@googlemail.com> - 2015-08-05 06:00 -0700
Re: How do quotation work, I can not foound them in 20xx anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-05 13:16 +0000
Re: How do quotation work, I can not foound them in 20xx JennyB <jennybrien@googlemail.com> - 2015-08-05 09:40 -0700
Re: How do quotation work, I can not foound them in 20xx anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-06 14:34 +0000
Re: How do quotation work, I can not foound them in 20xx JennyB <jennybrien@googlemail.com> - 2015-08-07 00:33 -0700
Re: How do quotation work, I can not foound them in 20xx "HAA" <someone@microsoft.com> - 2015-08-15 12:37 +1000
Re: How do quotation work, I can not foound them in 20xx Bernd Paysan <bernd.paysan@gmx.de> - 2015-08-15 13:53 +0200
Re: How do quotation work, I can not foound them in 20xx "HAA" <someone@microsoft.com> - 2015-08-16 12:53 +1000
Re: How do quotation work, I can not foound them in 20xx "HAA" <someone@microsoft.com> - 2015-08-08 13:06 +1000
Re: How do quotation work, I can not foound them in 20xx "WJ" <w_a_x_man@yahoo.com> - 2015-09-15 03:23 +0000
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-12 14:55 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-13 12:53 +0100
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-13 06:13 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-13 16:00 +0100
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-13 09:12 -0700
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-13 09:26 -0700
Re: How do quotation work, I can not foound them in 20xx Coos Haak <chforth@hccnet.nl> - 2015-07-13 17:00 +0200
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-13 16:58 +0100
Re: How do quotation work, I can not foound them in 20xx Coos Haak <chforth@hccnet.nl> - 2015-07-13 20:53 +0200
Re: How do quotation work, I can not foound them in 20xx bettilyona@gmail.com - 2015-07-13 09:13 -0700
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-13 09:15 -0700
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-13 13:10 -0700
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-13 14:24 -0700
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-13 18:51 -0700
Re: How do quotation work, I can not foound them in 20xx Julian Fondren <julian.fondren@gmail.com> - 2015-07-13 20:19 -0700
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-13 20:49 -0700
Re: How do quotation work, I can not foound them in 20xx Julian Fondren <julian.fondren@gmail.com> - 2015-07-13 21:48 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-14 09:38 +0100
Re: How do quotation work, I can not foound them in 20xx Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-07-13 21:44 -0700
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-13 21:53 -0700
Re: How do quotation work, I can not foound them in 20xx Julian Fondren <julian.fondren@gmail.com> - 2015-07-13 22:04 -0700
Re: How do quotation work, I can not foound them in 20xx humptydumpty <ouatubi@gmail.com> - 2015-07-14 01:22 -0700
Re: How do quotation work, I can not foound them in 20xx humptydumpty <ouatubi@gmail.com> - 2015-07-14 01:47 -0700
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-14 09:56 -0700
Re: How do quotation work, I can not foound them in 20xx Julian Fondren <julian.fondren@gmail.com> - 2015-07-14 10:45 -0700
Re: How do quotation work, I can not foound them in 20xx humptydumpty <ouatubi@gmail.com> - 2015-07-14 11:10 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-14 09:35 +0100
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-14 02:17 -0700
Re: How do quotation work, I can not foound them in 20xx humptydumpty <ouatubi@gmail.com> - 2015-07-14 02:24 -0700
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-14 02:25 -0700
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-14 09:32 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-14 17:50 +0100
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-14 10:48 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-14 18:59 +0100
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-14 20:49 +0100
Re: How do quotation work, I can not foound them in 20xx "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-15 00:52 -0400
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-15 12:09 +0100
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-15 04:19 -0700
Re: How do quotation work, I can not foound them in 20xx "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-15 22:10 -0400
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-16 00:42 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-16 14:29 +0100
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-16 12:52 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-16 09:59 +0100
Re: How do quotation work, I can not foound them in 20xx Mike Mellen <mmellen@intellikey.com> - 2015-07-15 07:56 -0400
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-15 16:27 +0100
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-15 10:47 -0700
Re: How do quotation work, I can not foound them in 20xx "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-15 21:50 -0400
Re: How do quotation work, I can not foound them in 20xx stephen@mpeforth.com (Stephen Pelc) - 2015-07-15 19:38 +0000
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-15 12:58 -0700
Re: How do quotation work, I can not foound them in 20xx "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-15 22:20 -0400
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-14 09:53 -0700
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-14 10:12 -0700
Re: How do quotation work, I can not foound them in 20xx Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-07-14 10:53 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-14 20:06 +0100
Re: How do quotation work, I can not foound them in 20xx Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-07-14 12:18 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-14 20:52 +0100
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-14 13:39 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-14 22:20 +0100
Re: How do quotation work, I can not foound them in 20xx Raimond Dragomir <raimond.dragomir@gmail.com> - 2015-07-14 21:10 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-15 12:03 +0100
Re: How do quotation work, I can not foound them in 20xx Coos Haak <chforth@hccnet.nl> - 2015-07-15 14:16 +0200
Re: How do quotation work, I can not foound them in 20xx Coos Haak <chforth@hccnet.nl> - 2015-07-15 14:04 +0200
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-15 15:44 +0100
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-15 15:47 +0100
Re: How do quotation work, I can not foound them in 20xx anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-07-15 15:26 +0000
Re: How do quotation work, I can not foound them in 20xx JennyB <jennybrien@googlemail.com> - 2015-07-16 05:41 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-16 14:13 +0100
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-14 14:18 -0700
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-15 02:42 -0700
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-15 01:26 -0700
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-15 10:44 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-15 19:31 +0100
Re: How do quotation work, I can not foound them in 20xx Paul Rubin <no.email@nospam.invalid> - 2015-07-15 11:48 -0700
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-15 12:13 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-15 20:18 +0100
Re: How do quotation work, I can not foound them in 20xx "WJ" <w_a_x_man@yahoo.com> - 2015-07-22 11:11 +0000
Re: How do quotation work, I can not foound them in 20xx Håkan Thörngren <hth313@gmail.com> - 2015-07-14 11:38 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-14 19:58 +0100
Re: How do quotation work, I can not foound them in 20xx anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-07-15 05:55 +0000
Re: How do quotation work, I can not foound them in 20xx Håkan Thörngren <hth313@gmail.com> - 2015-07-15 00:03 -0700
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-15 01:41 -0700
Re: How do quotation work, I can not foound them in 20xx Paul Rubin <no.email@nospam.invalid> - 2015-07-13 22:05 -0700
Re: How do quotation work, I can not foound them in 20xx Mark Wills <markwills1970@gmail.com> - 2015-07-13 14:24 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-13 23:13 +0100
Re: How do quotation work, I can not foound them in 20xx "Elizabeth D. Rather" <erather@forth.com> - 2015-07-13 13:03 -1000
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-14 09:31 +0100
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-15 13:24 -0700
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-15 22:04 +0100
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-13 22:52 +0100
Re: How do quotation work, I can not foound them in 20xx hughaguilar96@gmail.com - 2015-07-13 13:12 -0700
Re: How do lambdas work, I cannot find them in 20xx "WJ" <w_a_x_man@yahoo.com> - 2016-07-11 23:02 +0000
Re: How do lambdas work, I cannot find them in 20xx "WJ" <w_a_x_man@yahoo.com> - 2016-07-12 02:56 +0000
Re: How do quotation work, I can not foound them in 20xx stephen@mpeforth.com (Stephen Pelc) - 2015-07-13 13:16 +0000
Re: How do quotation work, I can not foound them in 20xx anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-07-13 16:00 +0000
Re: How do quotation work, I can not foound them in 20xx "Alex McDonald" <blog@rivadpm.com> - 2015-07-13 17:58 +0100
Re: How do quotation work, I can not foound them in 20xx Steve Graham <solitary.wanderer52@gmail.com> - 2015-08-06 09:54 -0700
Re: How do quotation work, I can not foound them in 20xx Coos Haak <chforth@hccnet.nl> - 2015-08-06 21:19 +0200
Page 5 of 7 — ← Prev page 1 2 3 4 [5] 6 7 Next page →
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2015-07-14 10:12 -0700 |
| Message-ID | <37dc90c4-ed23-46dc-8a70-d0b5e72441ee@googlegroups.com> |
| In reply to | #40621 |
On Tuesday, July 14, 2015 at 9:53:59 AM UTC-7, Mark Wills wrote:
> Yes. I understand that. What I don't understand is what is fake about my implementation. Perhaps you were being tongue-in-cheek. It seems a valid implementation to me.
I'm never tongue-in-cheek.
On Monday, July 13, 2015 at 9:26:47 AM UTC-7, Mark Wills wrote:
> They get access to locals 'for free' (as in, no code required):
> : test
> locals{ fred }
> 99 set fred \ load fred with 99
> [: fred 1+ ;] execute .
> ;
> test
> 100 ok:0
You did your EXECUTE inside of the parent function --- the idea is to pass the quotation's xt into another function (the higher-order function) and do the EXECUTE there --- by that time the local-frame on the return-stack is buried under the return-address of the CALL and also under the local-frame of the higher-order function, so it is no longer accessible when the quotation executes.
The only way that this is going to work is if you are holding your local variables in registers rather than in a local-frame on the return-stack, and those registers have never been over-written by the time that your quotation executes.
Try having TEST call another function and pass the quotation xt into that function, then that function executes the xt --- it is meaningless to execute the xt inside of the TEST function!
[toc] | [prev] | [next] | [standalone]
| From | Raimond Dragomir <raimond.dragomir@gmail.com> |
|---|---|
| Date | 2015-07-14 10:53 -0700 |
| Message-ID | <20815e21-3a08-4371-9336-a1e5fad36ef2@googlegroups.com> |
| In reply to | #40623 |
marți, 14 iulie 2015, 20:12:14 UTC+3, hughag...@gmail.com a scris:
> On Tuesday, July 14, 2015 at 9:53:59 AM UTC-7, Mark Wills wrote:
> > Yes. I understand that. What I don't understand is what is fake about my implementation. Perhaps you were being tongue-in-cheek. It seems a valid implementation to me.
>
> I'm never tongue-in-cheek.
>
> On Monday, July 13, 2015 at 9:26:47 AM UTC-7, Mark Wills wrote:
> > They get access to locals 'for free' (as in, no code required):
> > : test
> > locals{ fred }
> > 99 set fred \ load fred with 99
> > [: fred 1+ ;] execute .
> > ;
> > test
> > 100 ok:0
>
> You did your EXECUTE inside of the parent function --- the idea is to pass the quotation's xt into another function (the higher-order function) and do the EXECUTE there --- by that time the local-frame on the return-stack is buried under the return-address of the CALL and also under the local-frame of the higher-order function, so it is no longer accessible when the quotation executes.
>
> The only way that this is going to work is if you are holding your local variables in registers rather than in a local-frame on the return-stack, and those registers have never been over-written by the time that your quotation executes.
>
> Try having TEST call another function and pass the quotation xt into that function, then that function executes the xt --- it is meaningless to execute the xt inside of the TEST function!
Here is an example.
First, your example:
def test { | fred } 99 fred ! [ fred @ 1+ ] execute . ;
ok
test
100 ok
Hugh is right, you don't write a quotation just to execute it immediately
by execute. This is just as you write the code directly, no need for a
quotation.
A quotation is usefull if it can be passed as an argument for a higher
order function. Here, we execute the quotation 10 times:
def test { | fred } 99 fred ! 10 [ 1 fred +! ] times fred @ . ;
test reDef
ok
test
109 ok
See how the quotation incremented the parent local every time.
times is a higher order function. If you wonder how it's written, here it is:
def times >r for r> r@ execute >r next r> drop ;
Note the execute inside a loop.
[toc] | [prev] | [next] | [standalone]
| From | "Alex McDonald" <blog@rivadpm.com> |
|---|---|
| Date | 2015-07-14 20:06 +0100 |
| Message-ID | <mo3mgj$77f$1@dont-email.me> |
| In reply to | #40626 |
on 14/07/2015 18:53:25, Raimond Dragomir wrote:
> mar?i, 14 iulie 2015, 20:12:14 UTC+3, hughag...@gmail.com a scris:
>> On Tuesday, July 14, 2015 at 9:53:59 AM UTC-7, Mark Wills wrote:
>> > Yes. I understand that. What I don't understand is what is fake about m
> y implementation. Perhaps you were being tongue-in-cheek. It seems a
> valid implementation to me.
>>
>> I'm never tongue-in-cheek.
>>
>> On Monday, July 13, 2015 at 9:26:47 AM UTC-7, Mark Wills wrote:
>> > They get access to locals 'for free' (as in, no code required):
>> > : test
>> > locals{ fred }
>> > 99 set fred \ load fred with 99
>> > [: fred 1+ ;] execute .
>> > ;
>> > test
>> > 100 ok:0
>>
>> You did your EXECUTE inside of the parent function --- the idea is to pas
> s the quotation's xt into another function (the higher-order function)
> and do the EXECUTE there --- by that time the local-frame on the
> return-stack is buried under the return-address of the CALL and also
> under the local-fra me of the higher-order function, so it is no
> longer accessible when the quo tation executes.
>>
>> The only way that this is going to work is if you are holding your local
> variables in registers rather than in a local-frame on the
> return-stack, an d those registers have never been over-written by the
> time that your quotat ion executes.
>>
>> Try having TEST call another function and pass the quotation xt into that
> function, then that function executes the xt --- it is meaningless to
> exec ute the xt inside of the TEST function!
>
> Here is an example.
> First, your example:
>
> def test { | fred } 99 fred ! [ fred @ 1+ ] execute . ;
> ok
> test
> 100 ok
>
> Hugh is right, you don't write a quotation just to execute it
> immediately by execute. This is just as you write the code directly,
> no need for a quotation.
>
> A quotation is usefull if it can be passed as an argument for a higher
> order function. Here, we execute the quotation 10 times:
>
> def test { | fred } 99 fred ! 10 [ 1 fred +! ] times fred @ . ;
> test reDef
> ok
> test
> 109 ok
>
> See how the quotation incremented the parent local every time.
> times is a higher order function. If you wonder how it's written, here
> it i s:
>
> def times >r for r> r@ execute >r next r> drop ;
>
> Note the execute inside a loop.
>
>
Try this.
def atimes >r for r> r@ execute >r next r> drop ;
def btimes atimes ;
def ctimes btimes ;
def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
What result do you get? I'm betting a return stack to a quotation it's
not 109.
[toc] | [prev] | [next] | [standalone]
| From | Raimond Dragomir <raimond.dragomir@gmail.com> |
|---|---|
| Date | 2015-07-14 12:18 -0700 |
| Message-ID | <8f73baac-2e77-4fb4-88ea-399d3f1bc144@googlegroups.com> |
| In reply to | #40632 |
>
> Try this.
>
> def atimes >r for r> r@ execute >r next r> drop ;
> def btimes atimes ;
> def ctimes btimes ;
> def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
>
> What result do you get? I'm betting a return stack to a quotation it's
> not 109.
ok
def atimes >r for r> r@ execute >r next r> drop ;
ok
def btimes atimes ;
ok
def ctimes btimes ;
ok
def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
ok
test
109 ok
[toc] | [prev] | [next] | [standalone]
| From | "Alex McDonald" <blog@rivadpm.com> |
|---|---|
| Date | 2015-07-14 20:52 +0100 |
| Message-ID | <mo3p6t$i44$1@dont-email.me> |
| In reply to | #40633 |
on 14/07/2015 20:18:31, Raimond Dragomir wrote:
>>
>> Try this.
>>
>> def atimes >r for r> r@ execute >r next r> drop ;
>> def btimes atimes ;
>> def ctimes btimes ;
>> def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
>>
>> What result do you get? I'm betting a return stack to a quotation it's
>> not 109.
>
> ok
> def atimes >r for r> r@ execute >r next r> drop ;
> ok
> def btimes atimes ;
> ok
> def ctimes btimes ;
> ok
> def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
> ok
> test
> 109 ok
>
Let me guess; locals are not on the return stack. Either in registers or
a separate area?
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2015-07-14 13:39 -0700 |
| Message-ID | <c232cc55-8202-4932-bbf3-0738b44b73ec@googlegroups.com> |
| In reply to | #40635 |
On Tuesday, July 14, 2015 at 12:52:22 PM UTC-7, Alex McDonald wrote:
> on 14/07/2015 20:18:31, Raimond Dragomir wrote:
> >>
> >> Try this.
> >>
> >> def atimes >r for r> r@ execute >r next r> drop ;
> >> def btimes atimes ;
> >> def ctimes btimes ;
> >> def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
> >>
> >> What result do you get? I'm betting a return stack to a quotation it's
> >> not 109.
> >
> > ok
> > def atimes >r for r> r@ execute >r next r> drop ;
> > ok
> > def btimes atimes ;
> > ok
> > def ctimes btimes ;
> > ok
> > def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
> > ok
> > test
> > 109 ok
> Let me guess; locals are not on the return stack. Either in registers or
> a separate area?
He's not going to tell you how his compiler works, because you have no purpose except to attack people. So go ahead and guess --- then present your guess as fact --- do what you always do.
The problem I see here is not really Alex McDonald, because trolls have always existed and always will. The problem is a failure of leadership in the Forth community. I think that the Forth-200x committee believe that trolls like Alex are useful so long as they attack people such as Raimond and myself and don't attack ANS-Forth and/or Forth-200x. They believe that they can stand aloof and dodge blame for all of this nastiness because they aren't posting the nastiness themselves, and have effectively kept their hands clean by using a proxy --- they aren't fooling anybody! --- everybody knows that Alex McDonald and John Passaniti are tools of the Forth-200x committee, and that the Forth-200x committee is the engine of corruption on comp.lang.forth.
I actually know how Raimond's compiler works, because he told me. He has some good ideas! There is no forum available to present ideas about Forth though. This is a big part of why Forth languishes unused --- over the years people who have had good ideas have been attacked and have withdrawn (it is like wrestling a pig; even if you win you end up covered in mud, and the pig enjoys it) --- as time goes by, only the bad ideas persist (ANS-Forth is the standard), and Forth gets a reputation for being a haven for people who don't know anything about programming but who still want to be programmers (or, like Elizabeth Rather, pretend to be programmers but never actually write any programs).
[toc] | [prev] | [next] | [standalone]
| From | "Alex McDonald" <blog@rivadpm.com> |
|---|---|
| Date | 2015-07-14 22:20 +0100 |
| Message-ID | <mo3uc6$5qf$1@dont-email.me> |
| In reply to | #40636 |
on 14/07/2015 21:39:53, wrote:
> On Tuesday, July 14, 2015 at 12:52:22 PM UTC-7, Alex McDonald wrote:
>> on 14/07/2015 20:18:31, Raimond Dragomir wrote:
>> >>
>> >> Try this.
>> >>
>> >> def atimes >r for r> r@ execute >r next r> drop ;
>> >> def btimes atimes ;
>> >> def ctimes btimes ;
>> >> def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
>> >>
>> >> What result do you get? I'm betting a return stack to a quotation it's
>> >> not 109.
>> >
>> > ok
>> > def atimes >r for r> r@ execute >r next r> drop ;
>> > ok
>> > def btimes atimes ;
>> > ok
>> > def ctimes btimes ;
>> > ok
>> > def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
>> > ok
>> > test
>> > 109 ok
>
>> Let me guess; locals are not on the return stack. Either in registers or
>> a separate area?
>
> He's not going to tell you how his compiler works, because you have no
> purp ose except to attack people. So go ahead and guess --- then
> present your gu ess as fact --- do what you always do.
>
> The problem I see here is not really Alex McDonald, because trolls
> have alw ays existed and always will. The problem is a failure of
> leadership in the Forth community. I think that the Forth-200x
> committee believe that trolls like Alex are useful so long as they
> attack people such as Raimond and myse lf and don't attack ANS-Forth
> and/or Forth-200x. They believe that they can stand aloof and dodge
> blame for all of this nastiness because they aren't posting the
> nastiness themselves, and have effectively kept their hands cle an by
> using a proxy --- they aren't fooling anybody! --- everybody knows th
> at Alex McDonald and John Passaniti are tools of the Forth-200x
> committee, and that the Forth-200x committee is the engine of
> corruption on comp.lang. forth.
>
> I actually know how Raimond's compiler works, because he told me. He
> has so me good ideas! There is no forum available to present ideas
> about Forth tho ugh. This is a big part of why Forth languishes unused
> --- over the years p eople who have had good ideas have been attacked
> and have withdrawn (it is like wrestling a pig; even if you win you
> end up covered in mud, and the pi g enjoys it) --- as time goes by,
> only the bad ideas persist (ANS-Forth is the standard), and Forth gets
> a reputation for being a haven for people who don't know anything
> about programming but who still want to be programmers (or, like
> Elizabeth Rather, pretend to be programmers but never actually w rite
> any programs).
>
And? Where does this agenda get you? Or is this the start of Act 3?
[toc] | [prev] | [next] | [standalone]
| From | Raimond Dragomir <raimond.dragomir@gmail.com> |
|---|---|
| Date | 2015-07-14 21:10 -0700 |
| Message-ID | <1080bafe-a7a1-40a7-a673-8205c5e2fac1@googlegroups.com> |
| In reply to | #40635 |
marți, 14 iulie 2015, 22:52:22 UTC+3, Alex McDonald a scris:
> on 14/07/2015 20:18:31, Raimond Dragomir wrote:
> >>
> >> Try this.
> >>
> >> def atimes >r for r> r@ execute >r next r> drop ;
> >> def btimes atimes ;
> >> def ctimes btimes ;
> >> def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
> >>
> >> What result do you get? I'm betting a return stack to a quotation it's
> >> not 109.
> >
> > ok
> > def atimes >r for r> r@ execute >r next r> drop ;
> > ok
> > def btimes atimes ;
> > ok
> > def ctimes btimes ;
> > ok
> > def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
> > ok
> > test
> > 109 ok
> >
>
> Let me guess; locals are not on the return stack. Either in registers or
> a separate area?
Wrong again. They are on the return stack. I don't have any separate area or
stack. My system has only data stack and return stack for the runtime. The
third stack is the control stack, only for compiler.
I have though a frame pointer for the locals. It is exactly what the C compiler
uses for its locals. Very simple.
[toc] | [prev] | [next] | [standalone]
| From | "Alex McDonald" <blog@rivadpm.com> |
|---|---|
| Date | 2015-07-15 12:03 +0100 |
| Message-ID | <mo5eio$ek9$1@dont-email.me> |
| In reply to | #40639 |
on 15/07/2015 05:10:10, Raimond Dragomir wrote:
> mar?i, 14 iulie 2015, 22:52:22 UTC+3, Alex McDonald a scris:
>> on 14/07/2015 20:18:31, Raimond Dragomir wrote:
>> >>
>> >> Try this.
>> >>
>> >> def atimes >r for r> r@ execute >r next r> drop ;
>> >> def btimes atimes ;
>> >> def ctimes btimes ;
>> >> def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
>> >>
>> >> What result do you get? I'm betting a return stack to a quotation it's
>> >> not 109.
>> >
>> > ok
>> > def atimes >r for r> r@ execute >r next r> drop ;
>> > ok
>> > def btimes atimes ;
>> > ok
>> > def ctimes btimes ;
>> > ok
>> > def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
>> > ok
>> > test
>> > 109 ok
>> >
>>
>> Let me guess; locals are not on the return stack. Either in registers or
>> a separate area?
>
> Wrong again. They are on the return stack. I don't have any separate
> area o r
> stack. My system has only data stack and return stack for the runtime.
> The third stack is the control stack, only for compiler.
>
> I have though a frame pointer for the locals. It is exactly what the C
> comp iler
> uses for its locals. Very simple.
>
OK, I see. So that leads to a number of other questions.
I'm interested in how atimes seeing the XT for [ 1 fred +! ] knows which
activation record contains fred, since there are activation records for
btimes and ctimes on the stack that the frame pointer will be addressing.
Is this possible?
def dtimes { barney rubble } for barney rubble execute next ;
def test { | fred } 99 fred ! 10 [ 1 fred +! ] dtimes fred @ . ;
[toc] | [prev] | [next] | [standalone]
| From | Coos Haak <chforth@hccnet.nl> |
|---|---|
| Date | 2015-07-15 14:16 +0200 |
| Message-ID | <1ejzyvjym8t2k.1xzg5yndpjy8z.dlg@40tude.net> |
| In reply to | #40646 |
Op Wed, 15 Jul 2015 14:04:37 +0200 schreef Coos Haak: <snip> > Note: instead of 'for barney' write 'barney for'. > > In test, fred is at certain offset from the locals pointer. > In dtimes, barney is at the same offset, rubble one cell further. > So in dtimes, barney is incremented, not fred, result is 99. > And of course, the offsets are the same, but the locals pointer is grown and isn't the same in dtimes as in test. groet Coos
[toc] | [prev] | [next] | [standalone]
| From | Coos Haak <chforth@hccnet.nl> |
|---|---|
| Date | 2015-07-15 14:04 +0200 |
| Message-ID | <6tkckker9q7w.fs5ui81cypnc.dlg@40tude.net> |
| In reply to | #40646 |
Op Wed, 15 Jul 2015 12:03:12 +0100 schreef Alex McDonald:
> on 15/07/2015 05:10:10, Raimond Dragomir wrote:
>> mar?i, 14 iulie 2015, 22:52:22 UTC+3, Alex McDonald a scris:
>>> on 14/07/2015 20:18:31, Raimond Dragomir wrote:
>>> >>
>>> >> Try this.
>>> >>
>>> >> def atimes >r for r> r@ execute >r next r> drop ;
>>> >> def btimes atimes ;
>>> >> def ctimes btimes ;
>>> >> def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
>>> >>
>>> >> What result do you get? I'm betting a return stack to a quotation it's
>>> >> not 109.
>>> >
>>> > ok
>>> > def atimes >r for r> r@ execute >r next r> drop ;
>>> > ok
>>> > def btimes atimes ;
>>> > ok
>>> > def ctimes btimes ;
>>> > ok
>>> > def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
>>> > ok
>>> > test
>>> > 109 ok
>>> >
>>>
>>> Let me guess; locals are not on the return stack. Either in registers or
>>> a separate area?
>>
>> Wrong again. They are on the return stack. I don't have any separate
>> area o r
>> stack. My system has only data stack and return stack for the runtime.
>> The third stack is the control stack, only for compiler.
>>
>> I have though a frame pointer for the locals. It is exactly what the C
>> comp iler
>> uses for its locals. Very simple.
>>
>
> OK, I see. So that leads to a number of other questions.
>
> I'm interested in how atimes seeing the XT for [ 1 fred +! ] knows which
> activation record contains fred, since there are activation records for
> btimes and ctimes on the stack that the frame pointer will be addressing.
> Is this possible?
>
> def dtimes { barney rubble } for barney rubble execute next ;
> def test { | fred } 99 fred ! 10 [ 1 fred +! ] dtimes fred @ . ;
Note: instead of 'for barney' write 'barney for'.
In test, fred is at certain offset from the locals pointer.
In dtimes, barney is at the same offset, rubble one cell further.
So in dtimes, barney is incremented, not fred, result is 99.
My implementation, ISO locals are value-types, not variables.
: dtimes
{: barney rubble :}
barney for rubble execute next ;
: test
99 {: fred :}
10 [: 1 +to fred ;]
dtimes fred . ;
>>test 99 ok
groet Coos
[toc] | [prev] | [next] | [standalone]
| From | "Alex McDonald" <blog@rivadpm.com> |
|---|---|
| Date | 2015-07-15 15:44 +0100 |
| Message-ID | <mo5rht$sso$1@dont-email.me> |
| In reply to | #40653 |
on 15/07/2015 13:04:39, Coos Haak wrote:
> Op Wed, 15 Jul 2015 12:03:12 +0100 schreef Alex McDonald:
>
>> on 15/07/2015 05:10:10, Raimond Dragomir wrote:
>>> mar?i, 14 iulie 2015, 22:52:22 UTC+3, Alex McDonald a scris:
>>>> on 14/07/2015 20:18:31, Raimond Dragomir wrote:
>>>> >>
>>>> >> Try this.
>>>> >>
>>>> >> def atimes >r for r> r@ execute >r next r> drop ;
>>>> >> def btimes atimes ;
>>>> >> def ctimes btimes ;
>>>> >> def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
>>>> >>
>>>> >> What result do you get? I'm betting a return stack to a quotation it's
>>>> >> not 109.
>>>> >
>>>> > ok
>>>> > def atimes >r for r> r@ execute >r next r> drop ;
>>>> > ok
>>>> > def btimes atimes ;
>>>> > ok
>>>> > def ctimes btimes ;
>>>> > ok
>>>> > def test { | fred } 99 fred ! 10 [ 1 fred +! ] ctimes fred @ . ;
>>>> > ok
>>>> > test
>>>> > 109 ok
>>>> >
>>>>
>>>> Let me guess; locals are not on the return stack. Either in registers or
>>>> a separate area?
>>>
>>> Wrong again. They are on the return stack. I don't have any separate
>>> area o r
>>> stack. My system has only data stack and return stack for the runtime.
>>> The third stack is the control stack, only for compiler.
>>>
>>> I have though a frame pointer for the locals. It is exactly what the C
>>> comp iler
>>> uses for its locals. Very simple.
>>>
>>
>> OK, I see. So that leads to a number of other questions.
>>
>> I'm interested in how atimes seeing the XT for [ 1 fred +! ] knows which
>> activation record contains fred, since there are activation records for
>> btimes and ctimes on the stack that the frame pointer will be addressing.
>> Is this possible?
>>
>> def dtimes { barney rubble } for barney rubble execute next ;
>> def test { | fred } 99 fred ! 10 [ 1 fred +! ] dtimes fred @ . ;
>
> Note: instead of 'for barney' write 'barney for'.
>
> In test, fred is at certain offset from the locals pointer.
> In dtimes, barney is at the same offset, rubble one cell further.
> So in dtimes, barney is incremented, not fred, result is 99.
>
> My implementation, ISO locals are value-types, not variables.
>: dtimes
> {: barney rubble :}
> barney for rubble execute next ;
>
>: test
> 99 {: fred :}
> 10 [: 1 +to fred ;]
> dtimes fred . ;
>
>>>test 99 ok
>
> groet Coos
>
Here's an ANS/ISO Forth version;
STC Experimental 32bit: 0.06.08 Build: 316
: dtimes {: barney rubble :} barney 0 ?do rubble execute loop ; ok
: test 99 {: fred :} 10 [: 1 +to fred ;] dtimes fred . ; ok
test 99 ok
Same effect, as the same mechanism is used to determine the locals offet
on the stack. Now, with an activation record we could fix that for
DTIMES; but if : DTIMES ETIMES ; and ETIMES does the work, then that's
quite a trick in aliasing BARNEY to FRED, since ETIMES points to DTIMES
activation record, not TEST. It could be done by using display pointers
or a very smart compile (and even then : DTIMES ['] ETIMES EXECUTE ;
would probably blow it). The overhead of all this is quite large just to
allow parent locals in the payload of a quotation. We'd be better off
with full blown scoping, closures and GC by that point.
I'm gravitating towards a quotation with the following characteristics;
1. It can't refer to the enclosing word's locals, but it can have locals
of its own 2. The XT of the quotation can persist outside of the
enclosing execution 3. Quotations can be nested
[: has stack effects ( C: -- quot-sys ) no execution semantics (for that
use :NONAME) ;] has stack effects ( C: quot-sys -- ) no execution
semantics [: ... ;] when executed stack effect is ( -- xt ),
xt when executed is ( i*x -- j*x ) depending on the effects of enclosed
..
[toc] | [prev] | [next] | [standalone]
| From | "Alex McDonald" <blog@rivadpm.com> |
|---|---|
| Date | 2015-07-15 15:47 +0100 |
| Message-ID | <mo5ro8$tkp$1@dont-email.me> |
| In reply to | #40654 |
on 15/07/2015 15:44:38, "Alex McDonald" wrote:
>>
>
> Here's an ANS/ISO Forth version;
>
> STC Experimental 32bit: 0.06.08 Build: 316
>: dtimes {: barney rubble :} barney 0 ?do rubble execute loop ; ok
>: test 99 {: fred :} 10 [: 1 +to fred ;] dtimes fred . ; ok
> test 99 ok
It isn't ANS, I've just realised, since "anything already on the return
stack becomes unavailable until the loop control parameters are
discarded". But you get the drift.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2015-07-15 15:26 +0000 |
| Message-ID | <2015Jul15.172637@mips.complang.tuwien.ac.at> |
| In reply to | #40654 |
"Alex McDonald" <blog@rivadpm.com> writes:
>STC Experimental 32bit: 0.06.08 Build: 316
>: dtimes {: barney rubble :} barney 0 ?do rubble execute loop ; ok
>: test 99 {: fred :} 10 [: 1 +to fred ;] dtimes fred . ; ok
>test 99 ok
>
>Same effect, as the same mechanism is used to determine the locals offet
>on the stack. Now, with an activation record we could fix that for
>DTIMES; but if : DTIMES ETIMES ; and ETIMES does the work, then that's
>quite a trick in aliasing BARNEY to FRED, since ETIMES points to DTIMES
>activation record, not TEST.
One classical approach is to represent the static scoping with static
links. But that means that you have to represent the closure with two
cells: one represents the code (what is classically the xt), and one
contains the static link. If we want to represent that in a single
cell, we need an additional structure (on the return or locals stack)
that contains this info, and EXECUTE and the other xts have to be
adapted so that EXECUTE works both on normal xts and on pointers to
these structures.
> It could be done by using display pointers
Yes, using a display is also an option, but I don't think it gets rid
of the problem discussed above.
> The overhead of all this is quite large just to
>allow parent locals in the payload of a quotation. We'd be better off
>with full blown scoping, closures and GC by that point.
I think that GC would be quite beyond the usual scope of Forth. Maybe
something with more explicit memory management could be workable.
>I'm gravitating towards a quotation with the following characteristics;
>
>1. It can't refer to the enclosing word's locals, but it can have locals
>of its own 2. The XT of the quotation can persist outside of the
>enclosing execution 3. Quotations can be nested
That's what we have implemented in Gforth (development version).
- 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 2015: http://www.mpeforth.com/euroforth2015/euroforth2015.htm
[toc] | [prev] | [next] | [standalone]
| From | JennyB <jennybrien@googlemail.com> |
|---|---|
| Date | 2015-07-16 05:41 -0700 |
| Message-ID | <ff6c7584-e668-4609-bcf4-8f21b9de4c9a@googlegroups.com> |
| In reply to | #40657 |
On Wednesday, 15 July 2015 16:38:27 UTC+1, Anton Ertl wrote:
> "Alex McDonald" <blog@rivadpm.com> writes:
> >STC Experimental 32bit: 0.06.08 Build: 316
> >: dtimes {: barney rubble :} barney 0 ?do rubble execute loop ; ok
> >: test 99 {: fred :} 10 [: 1 +to fred ;] dtimes fred . ; ok
> >test 99 ok
> >
> >Same effect, as the same mechanism is used to determine the locals offet
> >on the stack. Now, with an activation record we could fix that for
> >DTIMES; but if : DTIMES ETIMES ; and ETIMES does the work, then that's
> >quite a trick in aliasing BARNEY to FRED, since ETIMES points to DTIMES
> >activation record, not TEST.
>
> One classical approach is to represent the static scoping with static
> links. But that means that you have to represent the closure with two
> cells: one represents the code (what is classically the xt), and one
> contains the static link. If we want to represent that in a single
> cell, we need an additional structure (on the return or locals stack)
> that contains this info, and EXECUTE and the other xts have to be
> adapted so that EXECUTE works both on normal xts and on pointers to
> these structures.
>
Well, since you don't know how the definition that the quotation is passed to uses either locals or the return stack, you need some other way of passing parameters. The natural thing is to use the data stack. If the quotation is EXECUTED a number of times by EACH or TIMES, then it must leave the data stack balanced, though of course it can mutate the values on it.
Where that is not enough, allowing the quotation its own local values is a good solution.
Back in the early days of local values' I had my own 'fake' version that I called 'Social Values' because they were shared among a number of definitions. The syntax went something like this.
4 Socials Fred Barney Wilma Betty
These are (now) global available.
: Pebbles ... Fred ... Wilma ... ;
: Bam-Bam ... Barney ... Betty ... ;
Then the high-level words:
: Flintstones >SOCIALS \ push a scratch sack with values for Fred, etc.
...
SOCIALS< \ restore the scratch stack
;
I could have had an END-SOCIALS to remove the social definitions from the search order, but I don't think I ever bothered.
So
1 Socials fred
: test 99 >socials 10 [: 1 +to fred ;] dtimes fred socials< . ;
Would work no matter how dtimes is defined, unless of course it also uses socials :-/ Of course, that holds no matter what simple mechanism you devise.
BTW, to whom it may concern, last time I checked, I was sane, but not American.
[toc] | [prev] | [next] | [standalone]
| From | "Alex McDonald" <blog@rivadpm.com> |
|---|---|
| Date | 2015-07-16 14:13 +0100 |
| Message-ID | <mo8ajs$qsh$1@dont-email.me> |
| In reply to | #40683 |
on 16/07/2015 13:41:05, JennyB wrote:
> On Wednesday, 15 July 2015 16:38:27 UTC+1, Anton Ertl wrote:
>> "Alex McDonald" <blog@rivadpm.com> writes:
>> >STC Experimental 32bit: 0.06.08 Build: 316
>> >: dtimes {: barney rubble :} barney 0 ?do rubble execute loop ; ok
>> >: test 99 {: fred :} 10 [: 1 +to fred ;] dtimes fred . ; ok
>> >test 99 ok
>> >
>> >Same effect, as the same mechanism is used to determine the locals offet
>> >on the stack. Now, with an activation record we could fix that for
>> >DTIMES; but if : DTIMES ETIMES ; and ETIMES does the work, then that's
>> >quite a trick in aliasing BARNEY to FRED, since ETIMES points to DTIMES
>> >activation record, not TEST.
>>
>> One classical approach is to represent the static scoping with static
>> links. But that means that you have to represent the closure with two
>> cells: one represents the code (what is classically the xt), and one
>> contains the static link. If we want to represent that in a single
>> cell, we need an additional structure (on the return or locals stack)
>> that contains this info, and EXECUTE and the other xts have to be
>> adapted so that EXECUTE works both on normal xts and on pointers to
>> these structures.
>>
>
> Well, since you don't know how the definition that the quotation is
> passed to uses either locals or the return stack, you need some other
> way of passi ng parameters. The natural thing is to use the data
> stack.
Yes. Closures, frame pointers, scoping, GC and so on can wait for another
day.
> If the quotati on is EXECUTED a number of times by EACH or
> TIMES, then it must leave the d ata stack balanced, though of course
> it can mutate the values on it.
Which is how the word called iteratively by TRAVERSE-WORDLIST was
designed.
>
> Where that is not enough, allowing the quotation its own local values
> is a good solution.
+1. The implementation here of quotations uses 95% of :NONAME (which also
supports locals) with a surrounding AHEAD THEN. There seems to be a
consensus developing; an RfD would seem to be called for.
> BTW, to whom it may concern, last time I checked, I was sane, but not American.
A fine combination.
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markwills1970@gmail.com> |
|---|---|
| Date | 2015-07-14 14:18 -0700 |
| Message-ID | <f861c85c-d619-4f8f-a37d-df0215c4a00d@googlegroups.com> |
| In reply to | #40626 |
Thanks this is useful.
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markwills1970@gmail.com> |
|---|---|
| Date | 2015-07-15 02:42 -0700 |
| Message-ID | <5d6ce922-1c69-4605-9562-4789e61e836d@googlegroups.com> |
| In reply to | #40626 |
On Tuesday, 14 July 2015 18:53:29 UTC+1, Raimond Dragomir wrote:
> marți, 14 iulie 2015, 20:12:14 UTC+3, hughag...@gmail.com a scris:
> > On Tuesday, July 14, 2015 at 9:53:59 AM UTC-7, Mark Wills wrote:
> > > Yes. I understand that. What I don't understand is what is fake about my implementation. Perhaps you were being tongue-in-cheek. It seems a valid implementation to me.
> >
> > I'm never tongue-in-cheek.
> >
> > On Monday, July 13, 2015 at 9:26:47 AM UTC-7, Mark Wills wrote:
> > > They get access to locals 'for free' (as in, no code required):
> > > : test
> > > locals{ fred }
> > > 99 set fred \ load fred with 99
> > > [: fred 1+ ;] execute .
> > > ;
> > > test
> > > 100 ok:0
> >
> > You did your EXECUTE inside of the parent function --- the idea is to pass the quotation's xt into another function (the higher-order function) and do the EXECUTE there --- by that time the local-frame on the return-stack is buried under the return-address of the CALL and also under the local-frame of the higher-order function, so it is no longer accessible when the quotation executes.
> >
> > The only way that this is going to work is if you are holding your local variables in registers rather than in a local-frame on the return-stack, and those registers have never been over-written by the time that your quotation executes.
> >
> > Try having TEST call another function and pass the quotation xt into that function, then that function executes the xt --- it is meaningless to execute the xt inside of the TEST function!
>
> Here is an example.
> First, your example:
>
> def test { | fred } 99 fred ! [ fred @ 1+ ] execute . ;
> ok
> test
> 100 ok
>
> Hugh is right, you don't write a quotation just to execute it immediately
> by execute. This is just as you write the code directly, no need for a
> quotation.
>
> A quotation is usefull if it can be passed as an argument for a higher
> order function. Here, we execute the quotation 10 times:
>
> def test { | fred } 99 fred ! 10 [ 1 fred +! ] times fred @ . ;
> test reDef
> ok
> test
> 109 ok
>
> See how the quotation incremented the parent local every time.
> times is a higher order function. If you wonder how it's written, here it is:
>
> def times >r for r> r@ execute >r next r> drop ;
>
> Note the execute inside a loop.
Super example, thank you.
I can "sort of" do the same thing, as long as the definition that
*executes* the quotation doesn't use locals itself, or, if it does,
defines them after it executes the quotation.
So, converting your code, I get:
: times ( xt n -- )
0 do dup execute loop drop
;
: foo ( -- )
locals{ fred }
99 set fred
[: 1 +set fred ;] 10 times
fred .
;
But times, as written above isn't very useful. The xt should
really be stored somewhere other than the stack, to allow the
stack to be used (perhaps the quotation stores results on the
stack). The obvious place to put the xt would be in a local:
: times ( xt #repeats -- )
locals{ xt }
swap set xt
0 do xt execute loop
;
That would be very neat and tidy. But I can't do that in my
implementation. I can put it in a variable, but that would not
allow nesting of calls to times.
I'll have to fake it! (Sorry, Hugh!): I'll have to the xt on
the return stack, and that's a pain, because the return stack
is in use by DO...LOOP.
Deep breath... (holds nose, types with one hand...)
: times ( xt #repeats -- )
swap >r \ stash xt
0 do
rp@ 3 cells + @ execute
loop
r> drop
;
: foo ( -- )
locals{ fred }
99 set fred
[: 1 +set fred ;] 10 times
fred .
;
foo
109 ok:0
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markwills1970@gmail.com> |
|---|---|
| Date | 2015-07-15 01:26 -0700 |
| Message-ID | <283f1106-aef4-4bfc-85c7-ec9343116153@googlegroups.com> |
| In reply to | #40623 |
On Tuesday, 14 July 2015 18:12:14 UTC+1, hughag...@gmail.com wrote:
> On Tuesday, July 14, 2015 at 9:53:59 AM UTC-7, Mark Wills wrote:
> > Yes. I understand that. What I don't understand is what is fake about my implementation. Perhaps you were being tongue-in-cheek. It seems a valid implementation to me.
>
> I'm never tongue-in-cheek.
>
> On Monday, July 13, 2015 at 9:26:47 AM UTC-7, Mark Wills wrote:
> > They get access to locals 'for free' (as in, no code required):
> > : test
> > locals{ fred }
> > 99 set fred \ load fred with 99
> > [: fred 1+ ;] execute .
> > ;
> > test
> > 100 ok:0
>
> You did your EXECUTE inside of the parent function --- the idea is to pass the quotation's xt into another function (the higher-order function) and do the EXECUTE there --- by that time the local-frame on the return-stack is buried under the return-address of the CALL and also under the local-frame of the higher-order function, so it is no longer accessible when the quotation executes.
>
> The only way that this is going to work is if you are holding your local variables in registers rather than in a local-frame on the return-stack, and those registers have never been over-written by the time that your quotation executes.
>
> Try having TEST call another function and pass the quotation xt into that function, then that function executes the xt --- it is meaningless to execute the xt inside of the TEST function!
Okay, this works on my system:
: foo ( xt -- )
execute . ;
: test ( -- )
locals{ fred }
99 set fred \ load fred with 99
[: fred 1+ ;] ( -- xt ) foo ;
test
100 ok:0
But if foo contains its own locals, you're screwed:
: foo ( xt -- )
locals{ mary }
150 set mary
execute . ;
: test ( -- )
locals{ fred }
99 set fred \ load fred with 99
[: fred 1+ ;] ( -- xt ) foo ;
test
151 ok:0
So I guess it's fake! :-/
If you declare the locals in foo *after* you execute the
quotation, then you can get away with it:
: foo ( xt -- )
execute .
locals{ mary }
150 set mary
mary .
;
: test ( -- )
locals{ fred }
99 set fred \ load fred with 99
[: fred 1+ ;] ( -- xt ) foo ;
test
100 150 ok:0
My system has it's own private locals stack (not on the return
stack, it's totally private), so I'm sure you can see what's
going on.
Thanks for the clarification.
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2015-07-15 10:44 -0700 |
| Message-ID | <b49fe10b-ef58-460f-a1d6-2c1edace699f@googlegroups.com> |
| In reply to | #40643 |
On Wednesday, July 15, 2015 at 1:26:43 AM UTC-7, Mark Wills wrote:
> Okay, this works on my system:
>
> : foo ( xt -- )
> execute . ;
>
> : test ( -- )
> locals{ fred }
> 99 set fred \ load fred with 99
> [: fred 1+ ;] ( -- xt ) foo ;
>
> test
> 100 ok:0
>
> But if foo contains its own locals, you're screwed:
FOO is the higher-order function --- this is the term.
Yes, if you don't use local in the higher-order function, then your frame-pointer will still be valid when the quotation executes.
The solution I discussed with Raimond already for his system, and which will work in your system also, is to use a different frame-pointer in higher-order functions. You would define higher-order functions with H: rather than : but otherwise they are the same as regular colon words. The difference is that regular colon words use the FP register as a frame-pointer and the higher-order functions use the HFP register as a frame-pointer. So, you need another register dedicated (HFP) beyond what you would normally have.
If you have a register shortage, then you can use RP (the return-stack pointer) as your frame-pointer in higher-order functions. If you do this though, then you can't use >R etc. in higher-order functions. Raimond calls this technique "frameless locals" (a somewhat confusing term; it means that we don't have a dedicated frame-pointer, but are using RP as the frame-pointer).
Note that ANS-Forth (13.3.3) says this:
- Locals shall not be declared until values previously placed on the return stack within the definition have been removed;
- After a definition's locals have been declared, a program may place data on the return stack. However, if this is done, locals shall not be accessed until those values have been removed from the return stack;
So, the ANS-Forth document actually requires that all ANS-Forth systems use frameless-locals, meaning that >R etc. can't be used in conjunction with locals. As a practical matter, every ANS-Forth system ignores this limitation and uses a frame-pointer.
If you have a register shortage you could use frameless-locals for higher-order functions. I would recommend instead that you have a separate frame-pointer (HFP) for higher-order functions, this way they work the same as regular colon words (can use locals and >R in the same function). This is much easier to explain to users, as there are no special rules. In either case however, you do need a different way to define higher-order functions --- use H: rather than : to define them --- this way the different method of accessing locals can be compiled internally. The point of having a different method of accessing locals in the higher-order function is to preserve the frame-pointer (FP) of the parent function so that it is still valid when the quotation executes.
If you do this, then I'll stop saying that you are faking quotations --- you will have real quotations (woo hoo!).
[toc] | [prev] | [next] | [standalone]
Page 5 of 7 — ← Prev page 1 2 3 4 [5] 6 7 Next page →
Back to top | Article view | comp.lang.forth
csiph-web