quotations (was: Back & Forth - Co-routines)

Liste des Groupes 
Sujet : quotations (was: Back & Forth - Co-routines)
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.lang.forth
Date : 08. Feb 2025, 12:41:32
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2025Feb8.124132@mips.complang.tuwien.ac.at>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : xrn 10.11
dxf <dxforth@gmail.com> writes:
On 7/02/2025 4:20 am, Anton Ertl wrote:
dxf <dxforth@gmail.com> writes:
On 7/02/2025 12:59 am, minforth wrote:
On Thu, 6 Feb 2025 12:57:12 +0000, Anton Ertl wrote:
AFAIR 200x nested definitions were justified on the grounds named
definitions were neither needed nor wanted
 
Really?  There's a proposal to eliminate named definitions?  That's
news to me.
>
I didn't but clearly those that argued for quotations did.

They did what?  Make a proposal for eliminating named definitions?
Where can I find that proposal?  I was one of the proposers of
quotations, so I certainly argued for them, and I am completely
unaware of a proposal like you claim, neither from me, nor Alex
McDonald (the first proposer of quotations), nor of anybody else
arguing for quotations.  Please present evidence of such a proposal.

There's a case for having NONAME: which has no name and must pass an xt.

Let's look at an example from the proposal:

: hex. ( u -- )
  base @ >r
  [: hex u. ;] catch
  r> base ! throw ;

There is no good way for replacing the quotation here with NONAME:, so
NONAME: is a red herring.

But that's not the same as saying there's a need for definitions without
names.

"There's a need for definitions without names" is something completely
different than "named definitions were neither needed nor wanted".

And certainly :NONAME is there because there is a use for colon
definitions without names.  Whether these uses constitute needs is the
question; they often can be replaced relatively easily by using named
definitions.  That's also the case for quotations.  One could replace
the definition above with:

: hex.-helper ( u -- )
  hex u. ;

: hex. ( u -- )
  base @ >r
  ['] hex.-helper catch
  r> base ! throw ;

But would the result be easier to read, write, understand, or consume
fewer resources?  No.

This only strengthened my view forth quotations had nothing to offer but
namelessness.

They also offer nesting.

If want to hide names of definitions I no longer need to
reference I have BEHEAD for that.

Let's see if this is ang better:

| : hex.-helper ( u -- )
  hex u. ;

: hex. ( u -- )
  base @ >r
  ['] hex.-helper catch
  r> base ! throw ;

Not at all.

Interesting but what are you saying - that quotations as we have them
are little more than a gimmick?

Let's see what that means; according to
<https://en.wikipedia.org/wiki/Gimmick>:

|A gimmick is a novel device or idea designed primarily to attract
|attention or increase appeal, often with little intrinsic value.[1][2]
|When applied to retail marketing, it is a unique or quirky feature
|designed to make a product or service "stand out" from its
|competitors.

It is certainly intended to increase the appeal, but not primarily.
It's not a unique or quirky feature, many other languages have nested
nameless definitions.

And Forth has had them too, and some posters love to present the use
of return-stack manipulations to turn code pieces into nameless
definitions that are then called in another context, without any
protest from you.  I think Hans Bezemer does it in the video that he
advertised in the start of this thread (at least that's what the gist
of the discussion here seems to indicate; I usually don't watch
videos).  One example is from the quotations proposal:

: foo bar list> bla blub ;

where the part after LIST> is a separate definition that is called
once for every element in the list.  There is even such a word in
standard Forth (since Forth-79):

: D A does> B ;

Here the "B ;" is a separate definition (it's even specified that way
in Forth-94 f.) that is called whenever another word C to which the
DOES> has been applied is called.

The LIST>-like definition splitting has several disadvantages:

1) It's not obvious when reading the code that some arbitrary word
   splits a definition in that way.

2) There is no way to continue the original definition after the
   LIST>-like word.  E.g., the proposal contains the example

  : dofield ( -- )
  does> ( name execution: addr1 -- addr2 )
      @ + ;
 
  : dozerofield ( -- )
      immediate
  does> ( name execution: -- )
      drop ;
 
  : field ( align1 offset1 align size "name" --  align2 offset2 )
      \ name execution: addr1 -- addr2
      2 pick >r \ this uglyness is just for optimizing with dozerofield
      create-field
      r> if \ offset<>0
        dofield
      else
        dozerofield
      then ;

   Here the need for the separate words DOFIELD and DOZEROFIELD comes
   from the fact that there is no standard way to return to the
   original definition after the DOES>.  The quotations proposal
   <http://www.forth200x.org/quotations.txt> contains a variant that
   encloses DOES> in quotations, but I find it even nicer to use
   SET-DOES> which takes an xt and makes C (the defined word) execute
   the xt.  With that the example becomes:

  : field ( align1 offset1 align size "name" --  align2 offset2 )
      \ name execution: addr1 -- addr2
      2 pick >r \ this uglyness is just for optimizing with dozerofield
      create-field
      r> if \ offset<>0
        [: @ + ;] set-does>
      else
        immediate ['] drop set-does>
      then ;

3) LIST> and similar words are implemented using return-address
   manipulation, which has problems with inlining and tail-call
   elimination.  Either you do not implement inlining and tail-call
   elimination, or implement them only in a restricted way (incurring
   complications for determining whether you can use them), or you
   replace the use of LIST> with ways that do not use return-address
   manipulations.

Users could have written the FOO example above as

: foo-helper bla blub ;

: foo bar ['] foo-helper map-list ;

since at least Forth-83, but apparently they found the need for an
out-of-line definition repulsing enough that they accepted the
disadvantages of going for LIST>.  With quotations, they can write
the helper inline without the disadvantages:

: foo bar [: bla blub ;] map-list ;

And we certainly have a lot of uses of [: in Gforth.

If you prefer to program without quotations, that's fine.  If you
don't want to implement them in your system, your system can still
be standard (if you care about that); quotations are optional.  But
I usually don't brake for deprived systems when I program.

- 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 proceedings: http://www.euroforth.org/ef23/papers/
EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/

Date Sujet#  Auteur
31 Jan 25 * Re: Back & Forth - Co-routines91dxf
31 Jan 25 +- Re: Back & Forth - Co-routines1Anton Ertl
31 Jan 25 +- Re: Back & Forth - Co-routines1albert
31 Jan 25 +* Re: Back & Forth - Co-routines14Hans Bezemer
1 Feb 25 i`* Re: Back & Forth - Co-routines13dxf
1 Feb 25 i `* Re: Back & Forth - Co-routines12Anton Ertl
1 Feb 25 i  +* Re: Back & Forth - Co-routines4dxf
1 Feb 25 i  i+- Re: Back & Forth - Co-routines1albert
1 Feb 25 i  i`* Re: Back & Forth - Co-routines2Anton Ertl
2 Feb 25 i  i `- Re: Back & Forth - Co-routines1dxf
2 Feb 25 i  `* Re: Use of { and } was Re: Back & Forth - Co-routines7dxf
2 Feb 25 i   `* Re: Use of { and } was Re: Back & Forth - Co-routines6Anton Ertl
2 Feb 25 i    +- Re: Use of { and } was Re: Back & Forth - Co-routines1dxf
2 Feb 25 i    +* Re: Use of { and } was Re: Back & Forth - Co-routines2Anton Ertl
2 Feb 25 i    i`- Re: Use of { and } was Re: Back & Forth - Co-routines1Bernd Linsel
6 Feb 25 i    `* Re: Use of { and } was Re: Back & Forth - Co-routines2Waldek Hebisch
6 Feb 25 i     `- Re: Use of { and } was Re: Back & Forth - Co-routines1dxf
1 Feb 25 +* Re: Back & Forth - Co-routines70Ruvim
2 Feb 25 i+- Re: Back & Forth - Co-routines1dxf
2 Feb 25 i+* Re: Back & Forth - Co-routines2Paul Rubin
3 Feb 25 ii`- Re: Back & Forth - Co-routines1dxf
3 Feb 25 i`* Re: Back & Forth - Co-routines66Ruvim
3 Feb 25 i +* Re: Back & Forth - Co-routines57albert
3 Feb 25 i i`* Re: Back & Forth - Co-routines56Paul Rubin
4 Feb 25 i i `* Re: Back & Forth - Co-routines55albert
6 Feb 25 i i  +* Re: Back & Forth - Co-routines2HenryHH
6 Feb 25 i i  i`- Re: Back & Forth - Co-routines1albert
6 Feb 25 i i  `* Re: Back & Forth - Co-routines52minforth
6 Feb 25 i i   +* Re: Back & Forth - Co-routines2albert
6 Feb 25 i i   i`- Re: Back & Forth - Co-routines1minforth
6 Feb 25 i i   `* Re: Back & Forth - Co-routines49Anton Ertl
6 Feb 25 i i    `* Re: Back & Forth - Co-routines48minforth
6 Feb 25 i i     +* Re: Back & Forth - Co-routines19dxf
6 Feb 25 i i     i+* Re: Back & Forth - Co-routines2minforth
7 Feb 25 i i     ii`- Re: Back & Forth - Co-routines1sjack
6 Feb 25 i i     i`* Re: Back & Forth - Co-routines16Anton Ertl
6 Feb 25 i i     i +- Re: Back & Forth - Co-routines1minforth
7 Feb 25 i i     i `* Re: Back & Forth - Co-routines14dxf
7 Feb 25 i i     i  +* Re: Back & Forth - Co-routines2minforth
7 Feb 25 i i     i  i`- Re: Back & Forth - Co-routines1dxf
8 Feb 25 i i     i  `* quotations (was: Back & Forth - Co-routines)11Anton Ertl
9 Feb 25 i i     i   +* Re: quotations9dxf
9 Feb 25 i i     i   i+* Re: quotations4Paul Rubin
9 Feb 25 i i     i   ii`* Re: quotations3dxf
9 Feb 25 i i     i   ii `* Re: quotations2Paul Rubin
9 Feb 25 i i     i   ii  `- Re: quotations1minforth
9 Feb 25 i i     i   i`* Re: quotations4Anton Ertl
9 Feb 25 i i     i   i +- Re: quotations1albert
10 Feb 25 i i     i   i `* Re: quotations2dxf
10 Feb 25 i i     i   i  `- Re: quotations1albert
9 Feb 25 i i     i   `- Re: quotations (was: Back & Forth - Co-routines)1albert
6 Feb 25 i i     +* Re: Back & Forth - Co-routines27Anton Ertl
6 Feb 25 i i     i+- Re: Back & Forth - Co-routines1minforth
7 Feb 25 i i     i`* Re: Back & Forth - Co-routines25minforth
8 Feb 25 i i     i `* Re: Back & Forth - Co-routines24Anton Ertl
8 Feb 25 i i     i  +* Re: Back & Forth - Co-routines4minforth
9 Feb 25 i i     i  i`* Re: Back & Forth - Co-routines3Paul Rubin
9 Feb 25 i i     i  i +- Re: Back & Forth - Co-routines1minforth
9 Feb 25 i i     i  i `- Re: Back & Forth - Co-routines1Anton Ertl
9 Feb 25 i i     i  `* Re: Back & Forth - Co-routines19Paul Rubin
9 Feb 25 i i     i   +* Re: Back & Forth - Co-routines3minforth
9 Feb 25 i i     i   i`* Re: Back & Forth - Co-routines2Paul Rubin
10 Feb 25 i i     i   i `- Re: Back & Forth - Co-routines1minforth
10 Feb 25 i i     i   `* Re: Back & Forth - Co-routines15Anton Ertl
10 Feb 25 i i     i    +* Re: Back & Forth - Co-routines8ahmed
10 Feb 25 i i     i    i`* Re: Back & Forth - Co-routines7Anton Ertl
10 Feb 25 i i     i    i +- Re: Back & Forth - Co-routines1ahmed
10 Feb 25 i i     i    i +- Re: Back & Forth - Co-routines1minforth
10 Feb 25 i i     i    i +* Re: Back & Forth - Co-routines3mhx
10 Feb 25 i i     i    i i+- Re: Back & Forth - Co-routines1albert
10 Feb 25 i i     i    i i`- Re: Back & Forth - Co-routines1Paul Rubin
10 Feb 25 i i     i    i `- Re: Back & Forth - Co-routines1albert
10 Feb 25 i i     i    `* Re: Back & Forth - Co-routines6Paul Rubin
11 Feb 25 i i     i     `* Re: Back & Forth - Co-routines5minforth
11 Feb 25 i i     i      `* Re: Back & Forth - Co-routines4Paul Rubin
12 Feb 25 i i     i       +- Re: Back & Forth - Co-routines1albert
12 Feb 25 i i     i       `* Re: Back & Forth - Co-routines2minforth
14 Feb 25 i i     i        `- Multi-Tasking (was: Back & Forth - Co-routines)1Anton Ertl
7 Feb 25 i i     `- Re: Back & Forth - Co-routines1minforth
22 Mar 25 i `* Re: Back & Forth - Co-routines8sjack
23 Mar 25 i  `* Re: Back & Forth - Co-routines7dxf
23 Mar 25 i   +* Re: Back & Forth - Co-routines2sjack
24 Mar 25 i   i`- Re: Back & Forth - Co-routines1sjack
24 Mar 25 i   +- Re: Back & Forth - Co-routines1sjack
24 Mar 25 i   `* Re: Back & Forth - Co-routines3dxf
24 Mar 25 i    `* Re: Back & Forth - Co-routines2dxf
24 Mar 25 i     `- Re: Back & Forth - Co-routines1dxf
11 Mar 25 `* Re: Back & Forth - Co-routines4dxf
21 Mar 25  `* Re: Back & Forth - Co-routines3dxf
21 Mar 25   `* Re: Back & Forth - Co-routines2dxf
22 Mar 25    `- Re: Back & Forth - Co-routines1dxf

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal