• locals (was: Inefficiency of FSL matrices)

    From Anton Ertl@21:1/5 to dxf on Sat Dec 16 07:45:51 2023
    dxf <dxforth@gmail.com> writes:
    But as Jeff Fox explains:

    "Forth is about words. Words have names. The choice of the names of the words
    in Forth is certainly one of the most important things. And given that humans have limited minds there should be a focus on what words are important. That's
    why it was considered important in the design of Forth to put emphasis on not having to name every temporary storage location. It has a name. It is a called
    a stack. The point being here that you don't have to name items on a stack. If you think you want to name the temporary items on the stack you are missing
    the most important design features of the language."

    I don't see how the last sentence follows from the stuff he wrote
    before.

    And Chuck Moore and others who do not use locals do not practice what
    Jeff Fox preached. They just use VARIABLEs instead of 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: https://forth-standard.org/
    EuroForth 2023: https://euro.theforth.net/2023

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to Anton Ertl on Sat Dec 16 11:17:54 2023
    In article <2023Dec16.084551@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:

    I don't see how the last sentence follows from the stuff he wrote
    before.

    And Chuck Moore and others who do not use locals do not practice what
    Jeff Fox preached. They just use VARIABLEs instead of locals.

    If I want named local storage I use VARIABLE's. There is a
    reentrant and a information hiding aspect to LOCAL's.
    I forego the reentrant aspect and attain information hiding if needed
    with other means with VARIABLE's or whatever other data structure.

    It is not a good to duplicate VARIABLE's with LOCAL's
    DVARIABLE's with DLOCAL's FVARIABLE's with DLOCAL's etc.
    Parsing with TO is an abuse of the powers of Forth.

    Agree to disagree. Should be in the FAQ.

    - anton

    Albert van der Horst
    --
    Don't praise the day before the evening. One swallow doesn't make spring.
    You must not say "hey" before you have crossed the bridge. Don't sell the
    hide of the bear until you shot it. Better one bird in the hand than ten in
    the air. First gain is a cat spinning. - the Wise from Antrim -

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mhx@21:1/5 to none on Sat Dec 16 12:27:43 2023
    none wrote:

    It is not a good to duplicate VARIABLE's with LOCAL's
    DVARIABLE's with DLOCAL's FVARIABLE's with DLOCAL's etc.

    I don't understand why it should be a discussion. Even if
    Forth didn't have a LOCAL concept, users could add it.

    [ BTW, it's not just classical re-entrancy. If a word is
    used from more than one location in a bigger program,
    its variables have to be duplicated. Where do you
    put the copies? ]

    Parsing with TO is an abuse of the powers of Forth.

    Are we preachers or engineers?

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to mhx on Sat Dec 16 14:05:21 2023
    In article <cbdb4357523903a4fbdf42e68ac9690e@news.novabbs.com>,
    mhx <mhx@iae.nl> wrote:
    none wrote:
    <SNIP>
    [ BTW, it's not just classical re-entrancy. If a word is
    used from more than one location in a bigger program,
    its variables have to be duplicated. Where do you
    put the copies? ]
    They are local variables, so they don't need duplicates.
    You're entrenched in LOCAl such that you don't understand
    any more what local variables as a concept are.


    -marcel
    --
    Don't praise the day before the evening. One swallow doesn't make spring.
    You must not say "hey" before you have crossed the bridge. Don't sell the
    hide of the bear until you shot it. Better one bird in the hand than ten in
    the air. First gain is a cat spinning. - the Wise from Antrim -

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to albert@cherry. on Sat Dec 16 22:44:11 2023
    albert@cherry.(none) (albert) writes:
    DVARIABLE's with DLOCAL's FVARIABLE's with DLOCAL's etc.
    Parsing with TO is an abuse of the powers of Forth.

    Whatever problems might result from TO are completely separate from
    whatever problems might result from locals.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to dxf on Sat Dec 16 23:41:21 2023
    dxf <dxforth@gmail.com> writes:
    If I use VARIABLEs as locals it is admission I was beaten. I try to keep that to a minimum :)

    I can't think of Forth as a HLL if users are supposed to do what amounts
    to pipeline scheduling and register allocation in their head, planning
    out the stack juggling and so on.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to dxforth@gmail.com on Mon Dec 18 14:07:02 2023
    In article <ulo1bt$351qd$1@dont-email.me>, dxf <dxforth@gmail.com> wrote:
    On 16/12/2023 6:45 pm, Anton Ertl wrote:
    ...
    And Chuck Moore and others who do not use locals do not practice what
    Jeff Fox preached. They just use VARIABLEs instead of locals.

    Moore has said:

    "Don't use local variables [...] It's bad. It's wrong."

    <https://www.ultratechnology.com/1xforth.htm>

    If he's merely using VARIABLEs where locals would otherwise be used that's >worth investigating. Unfortunately I'm not aware of any substantive code
    by Moore in the public domain to test the proposition.

    As one of the "others who do not use locals" I offer the following sample. >Readers may decide whether such use of VARIABLEs and VALUEs amounts to locals >in the usual meaning of the word. ISTM the more factored the code, the more >difficult it is to apply the term 'local'.

    variable #DIGIT \ #digits entered

    : /FIELD ( n -- 0 )
    drop #digit @ begin dup while
    <bs> emit space <bs> emit 1-
    repeat decimal #digit off ;

    : .VIS ( c -- )
    dup visible? if emit 1 #digit +! end drop ;

    : ?$ ( n c -- n' c' )
    [char] $ of /field hex [char] $ .vis key then ;

    : +DIGIT ( u c -- u' err )
    base @ >digit if swap base @ * + dup 255 u> end
    drop true ;

    : BUILD# ( c -- n c2 ) \ CR or BL exits
    decimal #digit off
    0 swap begin dup bl <> over <cr> <> and while
    ?$ upcase dup .vis +digit if beep /field then key
    repeat decimal ;

    : GET# ( -- n ) key build# drop ;

    variable LEN 0 value MAXCHR

    : ROOM? ( -- f ) len @ maxchr < ;

    : +CHR ( c -- ) ibuf len @ + c! 1 len +! ;

    : DO-NUM ( c -- ) \ CR or BL BL exits
    begin room? while
    build# swap #digit @ if +chr else drop then
    <cr> = if end space key bl of <cr> then
    repeat drop ;

    : DO-ASC ( c -- )
    begin dup <cr> - room? and while
    dup .chr +chr key
    repeat drop ;

    : DIGIT? ( c -- f )
    dup [char] $ = swap [char] 0 [char] 9 between or ;

    : GET$ ( maxlen -- adr len )
    to maxchr len off
    key dup digit? if do-num else do-asc then
    ibuf len @ ;


    An excellent example.

    Another excellent example is the <# # #> wordset.
    They are superbly factored, by virtue of the "global"
    HLD a (user) variable. It is actually more of a
    "package-local" variable. Who are in the habit
    of using LOCAL's as a first resort, are blocked to think
    in this direction.
    In the 2500 lines of the manx package (plays musical score
    simultaneously on midi keyboard and mechanical instruments) you see
    no LOCAL and merely half a dozen VARIABLE or VALUE.
    Some of this are hard (or impossible) to replace by LOCAL,
    e.g. SHIFTER and TICKS-PER-SECOND. They are set by
    a calibration word in the initialisation, then are needed all
    over the place, mostly by words that need not address them directly.
    They convert the system dependant tick rate to real time.

    Then you have the assembler/disassembler ciasdis.
    This implements a "blackboard design pattern" for a
    kind of state machine.
    It is hard to imagine that some one scribbles something on a blackboard,
    and then no one is ever to read it.

    Groetjes Albert
    --
    Don't praise the day before the evening. One swallow doesn't make spring.
    You must not say "hey" before you have crossed the bridge. Don't sell the
    hide of the bear until you shot it. Better one bird in the hand than ten in
    the air. First gain is a cat spinning. - the Wise from Antrim -

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bernd Linsel@21:1/5 to dxf on Mon Dec 18 20:46:26 2023
    On 18.12.2023 00:48, dxf wrote:
    On 16/12/2023 6:45 pm, Anton Ertl wrote:
    ... And Chuck Moore and others who do not use locals do not
    practice what Jeff Fox preached. They just use VARIABLEs instead
    of locals.


    Anno Domini 1999 A.C., the great unfallible

    Moore

    uttered the eternal thruth:

    has said:

    "Don't use local variables [...] It's bad. It's wrong."

    Thou shalt not... etc.


    <https://www.ultratechnology.com/1xforth.htm>


    Sorry, I'm bearing all the respect that Charles Moore deserves, but with
    all his statements about Forth, he never intended to proclaim universal
    truths, but he described, what worked best for himself.

    Undoubtlessly, he discovered (as he himself describes it) Forth, and had
    great influence on the language basics that carry forth until today.
    Some of his recommended practices (factor, factor, factor; don't
    optimize prematurely; hooks are unecessary when in anticipation of some
    still unknown future requirement; and many more), and his general
    approach to Forth programming style (e.g. advocating short, consise definitions, and if you can't track the stack values in your head,
    you've got to factor something out) do still hold today, and not
    exclusively for stack-oriented programming languages only.

    If he's merely using VARIABLEs where locals would otherwise be used
    that's worth investigating. Unfortunately I'm not aware of any
    substantive code by Moore in the public domain to test the
    proposition.

    CMForth sources (https://github.com/ForthHub/cmFORTH), the contents of
    the ArrayForth default block file (download at https://www.greenarraychips.com/home/support/download-03d.php)
    some snippets from his former website colorforth.com (mirrored at https://colorforth.github.io/) ...


    Regards,
    --
    Bernd Linsel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)