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


Groups > comp.lang.forth > #19791

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-18 13:40 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2013Feb18.144052@mips.complang.tuwien.ac.at> (permalink)
References <a3216023-8480-4845-9975-2e28c763beef@googlegroups.com> <0fb56fee-bbe8-4ed4-8b28-3e59d2520cf4@googlegroups.com> <2013Feb17.142435@mips.complang.tuwien.ac.at> <i5GdnQl11f4UZr3MnZ2dnUVZ_rWdnZ2d@supernews.com>

Show all headers | View raw


Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>We seem to be avoiding answering any question about the utility of
>such a thing.

Has such a question been posed?  I don't think so.  Anyway, let's
answer it:

One of the arguments against locals is that you cannot just grab a
subsequence in a Forth word and factor it into a separate word, unlike
straight-line Forth code that only uses the data stack (return stack
and control flow also restrict this kind of factoring, but I don't see
that argument applied to these featres).  With locals across several
words ypu could do such factoring with code that uses locals.

>  I suppose it's somewhat analogous to nested procedure
>scopes in Algol, but the inner procedures can't be called from
>outside.

I don't think it can be called in Algol (60) or Pascal, and the way
the extension is described, it could be done in Forth with this
extension, but would produce unpredictable results.

It would probably be better to have a syntax where the inner words
would not be visible outside.  E.g., something like

: foo {: First Second -- :}
  l: bar ( -- ) first second + . ;
  bar ;

where L: is a word for defining a colon definition inside a colon
definition.  There would probably be restructions on the definition
and use of locals, and on whether you can tick or postpone BAR to make
the implementation simpler.  Even a simple implementation would be
good enough for the factoring justiication.  If you lift restrictions,
you are into full closures relatively soon.

>It strikes me as more like dynamic scoping in Lisp, which is
>rather horrible, and I much prefer Scheme's lexical scoping.

I don't see any particular relation to dynamic scoping.  My guess is
that in the usage patterns that the OP has in mind, there woiuld be no
difference between static and dynamic scoping.

- 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