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


Groups > comp.lang.forth > #19817

Re: Locals with a broader scope

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Locals with a broader scope
Date 2013-02-19 11:25 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2013Feb19.122532@mips.complang.tuwien.ac.at> (permalink)
References (1 earlier) <0fb56fee-bbe8-4ed4-8b28-3e59d2520cf4@googlegroups.com> <__idnTtoCNkWRLzMnZ2dnUVZ_gSdnZ2d@supernews.com> <2013Feb18.153900@mips.complang.tuwien.ac.at> <46b42aa3-97a2-4b53-9f80-8617f5335596@googlegroups.com> <6f1f0e77-54a1-49b7-8f6e-91dd7a914492@googlegroups.com>

Show all headers | View raw


Percy <percival.andrews@gmail.com> writes:
>>>> I think the not-quite-locals should be treated as variables, accessed by @ and ! instead of TO. You can use classic variables, or you can put a line of code at the top declaring them temporary variables. 
>
>Can someone comment on why locals are VALUES rather than VARIABLES anyway?

One reason is that a VALUE cannot be accessed outside the scope of the
name, while the address produced by a VARIABLE can live forever.
E.g., Gforth has variable-flavoured locals as well as value-flavoured
ones, so you can write:

: foo ( -- addr ) 3 { w^ x } x ; \ a variable-flavoured local X
: bar foo 5 { y } @ ; \ a value-flavoured local Y
bar .

This prints 5, although one would expect 3 (X is initialized to 3 and
never changed, and the @ accesses X.

Another reason is that we usually don't need to take the address of a
local.  Even though Gforth has had variable-flavoured locals for 18
years, I have almost never used them.

>  It seems an easy way to introduce coding mistakes to have two different, (incompatible and asymmetrical) ways of accessing variables in the same piece of code.
>
>a @ TO b
>b a !

There is certainly that, but that has rarely been a problem in
practice, and IIRC never with locals.

- 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 2013: http://www.euroforth.org/ef13/

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


Thread

Locals with a broader scope Brad Eckert <hwfwguy@gmail.com> - 2013-02-16 10:40 -0800
  Re: Locals with a broader scope Brad Eckert <hwfwguy@gmail.com> - 2013-02-16 13:50 -0800
    Re: Locals with a broader scope anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-17 13:24 +0000
      Re: Locals with a broader scope Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-17 09:47 -0600
        Re: Locals with a broader scope anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-18 13:40 +0000
    Re: Locals with a broader scope "Elizabeth D. Rather" <erather@forth.com> - 2013-02-17 21:34 -1000
      Re: Locals with a broader scope Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-18 03:29 -0600
        Re: Locals with a broader scope Bernd Paysan <bernd.paysan@gmx.de> - 2013-02-18 17:29 +0100
      Re: Locals with a broader scope albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-02-18 12:05 +0000
      Re: Locals with a broader scope anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-18 14:39 +0000
        Re: Locals with a broader scope Brad Eckert <hwfwguy@gmail.com> - 2013-02-18 09:04 -0800
          Re: Locals with a broader scope Percy <percival.andrews@gmail.com> - 2013-02-19 02:33 -0800
            Re: Locals with a broader scope anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-19 11:25 +0000
              Re: Locals with a broader scope Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-19 11:42 -0600
  Re: Locals with a broader scope Bernd Paysan <bernd.paysan@gmx.de> - 2013-02-17 02:00 +0100
  Re: Locals with a broader scope Doug Hoffman <glidedog@gmail.com> - 2013-02-17 16:51 -0500
    Re: Locals with a broader scope "A. K." <akk@nospam.org> - 2013-02-18 07:58 +0100
  Re: Locals with a broader scope Brad Eckert <hwfwguy@gmail.com> - 2013-02-19 09:20 -0800
  Re: Locals with a broader scope Brad Eckert <hwfwguy@gmail.com> - 2013-02-22 08:27 -0800

csiph-web