Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #51541
| From | Gerry Jackson <gerry@jackson9000.fsnet.co.uk> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Is {{ taken? |
| Date | 2016-10-02 12:04 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <nsqpis$giu$1@dont-email.me> (permalink) |
| References | <nspl78$fd4$1@cherry.spenarnc.xs4all.nl> |
On 02/10/2016 01:43, Albert van der Horst wrote:
> Lispkit is written in Pascal. To translate it to Forth,
> it would help if I had nested compilation with nested
> scoping.
> I was already experimenting with it, now I've a reason to
> add it to an upcoming release.
>
> :: and ;; ("colon-big" and "semi-big") are like : and ; but
> they allow nested definitions by defining them
> between {{ and }} . Forth is then in interpreter mode and any
> newly defined words there can be used in the remainder of the word.
>
> Like so:
>
> \-----------------------------------------------
> "DEFER" WANTED
> \ Sort the range FIRST to LAST (inclusive) of item compared
> \ by the xt COMPARING and exchanged by the xt EXHANGING.
> \ The xt's are filled in into *< and *<--> and must observe the
> \ interface. All indices must be compatible with these xt's.
> \ After the call we have that :
> \ ``For FIRST<=I<J<=LAST I J *< EXECUTE leaves TRUE.''
> :: QSORT
> {{
> \ Compare item N1 and N2. Return ``N1'' IS lower and not equal.
> DEFER *<
> \ Exchange item N1 and N2.
> DEFER *<-->
> \ Partition inclusive range LO HI leaving LO_1 HI_1 LO_2 HI_2.
> :: PARTITION
> {{
> VARIABLE low VARIABLE high VARIABLE median
> : order-lmh
> OVER low ! DUP high !
> low @ high @ + 1+ 2/ median !
> high @ low @ *< IF high @ low @ *<--> THEN
> high @ median @ *< IF high @ median @ *<--> THEN
> median @ low @ *< IF median @ low @ *<--> THEN
> ;
> : interchange
> low @ high @ *<-->
> \ Do we have a new position for our pivot?
> low @ median @ = IF high @ median ! ELSE
> high @ median @ = IF low @ median ! THEN
> THEN
> ;
> }}
> order-lmh
> BEGIN ( lo_1 hi_2 lo_2 hi_1)
> BEGIN 1 low +! low @ median @ *< NOT UNTIL
> BEGIN -1 high +! median @ high @ *< NOT UNTIL
> low @ high @ < WHILE
> interchange
> REPEAT
> \ Works also in case they are equal, then they point to a pivot.
> >R low @ 1- high @ 1+ R>
> ;;
> }}
> IS *<-->
> IS *<
> ( lo hi -- )
> \ Sort the range LOW to HIGH inclusive observing *<
> DEPTH 2 - >R
> BEGIN 2DUP < IF PARTITION ELSE 2DROP THEN DEPTH R@ = UNTIL
> RDROP
> ;;
> \-----------------------------------------------
>
>
> About :: and ;; I'm pretty sure. I would have used [[ ]] big
> brackets but these are taken IIRC.
> Are the double curly brackets still available for this purpose?
>
> And yes, this code actually works.
> And no, this facility doesn't take too much code. In fact it
> fits in one screen, commented and all.
> And indeed, it kind of disproves LOCAL's. If you can't use local
> variables in local colon definitions, what's their use?
>
My system compiles to an intermediate code before laying down executable
code so, as an experiment a few years ago, I implemented nested
definitions simply by suspending the current definition, compiling the
nested definition(s) then resuming the outer definition. That made
implementation of quotations trivial.
So I can write stuff like:
: x ... [ : y ... { a b c }
[ : z ... [ variable w ] ... ; ]
... ;
]
...
;
But I never got around to hiding y z and w from the outside world, but I
think that could easily be handled by wordlists. No need for words like
:: {{ etc.
--
Gerry
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is {{ taken? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-10-02 02:43 +0200
Re: Is {{ taken? Paul Rubin <no.email@nospam.invalid> - 2016-10-01 18:50 -0700
Re: Is {{ taken? Doug Hoffman <glidedog@gmail.com> - 2016-10-01 21:52 -0400
Re: Is {{ taken? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-10-02 10:37 +0200
Re: Is {{ taken? Doug Hoffman <glidedog@gmail.com> - 2016-10-02 04:46 -0400
Re: Is {{ taken? hughaguilar96@gmail.com - 2016-10-02 17:18 -0700
Re: Is {{ taken? Doug Hoffman <glidedog@gmail.com> - 2016-10-01 22:17 -0400
Re: Is {{ taken? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-10-02 11:17 +0200
Re: Is {{ taken? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-10-02 10:11 +0000
Re: Is {{ taken? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-10-02 13:46 +0200
Re: Is {{ taken? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-10-02 12:04 +0100
Re: Is {{ taken? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-10-02 13:55 +0200
csiph-web