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


Groups > comp.lang.forth > #10823

Re: Locals

Newsgroups comp.lang.forth
From Albert van der Horst <albert@spenarnc.xs4all.nl>
Subject Re: Locals
Date 2012-04-03 17:54 +0000
Message-ID <m1x0fc.d2l@spenarnc.xs4all.nl> (permalink)
Organization Dutch Forth Workshop
References <4a5ba0bb-a657-46a7-97ae-33f55b142853@v2g2000vbx.googlegroups.com>

Show all headers | View raw


In article <4a5ba0bb-a657-46a7-97ae-33f55b142853@v2g2000vbx.googlegroups.com>,
Mark Wills  <markrobertwills@yahoo.co.uk> wrote:
>I was looking to see if I could extend my system by adding an optional
>loadable block(s) that will add local variables to each colon
>definition.
>
>I was planning to implement something very simple, where each colon
>definition would have three local variables, A, B & C that are
>accessed as normal via ! and @.
>
>I came up with
>
>variable var_top
>: a var_top @ ;
>: b var_top @ 1 cells + ;
>: c var_top @ 2 cells + ;
>
>: : here 3 cells allot : compile lit ,  compile var_top  compile ! ;
>
>That works - kind of.
>
>It modifies : such that reserves 3 cells, and adds code to the end
>colon-definition that sets var_top when the colon definition executes.
>It works. Each colon def has three unique locals, that I can set and
>read with ! and @.
>
>Trouble is, it doesn't nest. This is because var_top is set for each
>word on entry, but not re-set upon re-entry.
>
>Any ideas? Is this generally considered possible in high-level Forth?
>
>I'll check Forth dimensions, though I don't specifically remember
>anything.

If you have coroutines ( CO in ciforth, I thought ;: in colorforth)
you can do things up front and it kicks back at completion of
something. If your Forth has a real return stack, you can implement
CO easily.

Usage is like so:
        : HEX:    R> BASE @ >R  >R HEX   CO    R> BASE ! ;

Example of use:

 : (DH.) HEX: <# 1- 0 ?DO # I 4? LOOP # #> ;

The definition uses hex to format a number, then restores BASE.

or
"HEX: 789A,BCED" EVALUATE
or
HEX: in a file
HEX: in the first line of a block

Caution: if there is an exception (an error), the base is not
restored, but that would not be the case if done manually like:

...
HEX
...
\ Error occurs here.
..
DECIMAL
...

>
>Mark

Groetjes Albert

P.S. Forths that use refill may kick back at the end of
each line, or refill buffer.

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

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Locals Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-03 07:20 -0700
  Re: Locals Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-03 08:30 -0700
  Re: Locals Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-04-03 17:54 +0000
    Re: Locals Jason Damisch <jasondamisch@yahoo.com> - 2012-04-03 18:42 -0700
  Re: Locals "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-04-04 05:25 -0400
  Re: Locals BruceMcF <agila61@netscape.net> - 2012-04-03 20:32 -0700
  Re: Locals Michael L Gassanenko <m_l_g3@yahoo.com> - 2012-04-05 08:38 -0700
    Re: Locals Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-05 08:58 -0700
      Re: Locals Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-05 11:06 -0700

csiph-web