Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The world is coming to an end ... SAVE YOUR BUFFERS!!!


devel / comp.lang.forth / Re: .Re: Lisp benefits against other functional programming languages

SubjectAuthor
* .Re: Lisp benefits against other functional programming languagesRobert L.
`* Re: .Re: Lisp benefits against other functional programming languagesHans Bezemer
 `* Re: .Re: Lisp benefits against other functional programming languagesDoug Hoffman
  +* Re: .Re: Lisp benefits against other functional programming languagesminf...@arcor.de
  |`- Re: .Re: Lisp benefits against other functional programming languagesDoug Hoffman
  +* Re: .Re: Lisp benefits against other functional programming languagesJali Heinonen
  |+- Re: .Re: Lisp benefits against other functional programming languagesDoug Hoffman
  |`* Re: .Re: Lisp benefits against other functional programming languagesAnton Ertl
  | `* Re: .Re: Lisp benefits against other functional programming languagesRon AARON
  |  `* Re: .Re: Lisp benefits against other functional programming languagesAnton Ertl
  |   +* Re: .Re: Lisp benefits against other functional programming languagesminf...@arcor.de
  |   |`- Re: .Re: Lisp benefits against other functional programming languagesHans Bezemer
  |   +- Re: .Re: Lisp benefits against other functional programming languagesRon AARON
  |   `* Re: .Re: Lisp benefits against other functional programming languagesKrishna Myneni
  |    `* Re: .Re: Lisp benefits against other functional programming languagesminf...@arcor.de
  |     `* Re: .Re: Lisp benefits against other functional programming languagesKrishna Myneni
  |      `* Re: .Re: Lisp benefits against other functional programming languagesminf...@arcor.de
  |       `- Re: .Re: Lisp benefits against other functional programming languagesKrishna Myneni
  `* Re: .Re: Lisp benefits against other functional programming languagesHans Bezemer
   +* Re: .Re: Lisp benefits against other functional programming languagesminf...@arcor.de
   |`- Re: .Re: Lisp benefits against other functional programming languagesMarcel Hendrix
   `* Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
    `* Re: .Re: Lisp benefits against other functional programming languagesRon AARON
     `* Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
      +* Re: .Re: Lisp benefits against other functional programming languagesRon AARON
      |+* Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
      ||+- Re: .Re: Lisp benefits against other functional programming languagesdxforth
      ||`* Re: .Re: Lisp benefits against other functional programming languagesRon AARON
      || `* Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
      ||  `* Re: .Re: Lisp benefits against other functional programming languagesRon AARON
      ||   +* Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
      ||   |`* Re: .Re: Lisp benefits against other functional programming languagesRon AARON
      ||   | +- Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
      ||   | `* Re: .Re: Lisp benefits against other functional programming languagesHans Bezemer
      ||   |  `* Re: .Re: Lisp benefits against other functional programming languagesRon AARON
      ||   |   `* Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
      ||   |    `* Re: .Re: Lisp benefits against other functional programming languagesAnton Ertl
      ||   |     `* Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
      ||   |      `* Re: .Re: Lisp benefits against other functional programming languagesAnton Ertl
      ||   |       `* Re: .Re: Lisp benefits against other functional programming languagesBrian Fox
      ||   |        `* Tail call optimization (was: .Re: Lisp benefits ...)Anton Ertl
      ||   |         `* Re: Tail call optimization (was: .Re: Lisp benefits ...)Hans Bezemer
      ||   |          `* Re: Tail call optimization (was: .Re: Lisp benefits ...)Anton Ertl
      ||   |           `- Re: Tail call optimization (was: .Re: Lisp benefits ...)Hans Bezemer
      ||   +* Re: .Re: Lisp benefits against other functional programming languagesAnton Ertl
      ||   |`- Re: .Re: Lisp benefits against other functional programming languagesRon AARON
      ||   `- Re: .Re: Lisp benefits against other functional programming languagesMarcel Hendrix
      |`* Re: .Re: Lisp benefits against other functional programming languagesAnton Ertl
      | +- Re: .Re: Lisp benefits against other functional programming languagesRon AARON
      | +- Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
      | `* Re: .Re: Lisp benefits against other functional programming languagesrussell mcmanus
      |  +* Re: .Re: Lisp benefits against other functional programming languagesminf...@arcor.de
      |  |`- Re: .Re: Lisp benefits against other functional programming languagesAnton Ertl
      |  `* Re: .Re: Lisp benefits against other functional programming languagesAnton Ertl
      |   `* Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
      |    `- Re: .Re: Lisp benefits against other functional programming languagesAnton Ertl
      +* Re: .Re: Lisp benefits against other functional programming languagesAnton Ertl
      |`- Re: .Re: Lisp benefits against other functional programming languagesPaul Rubin
      `- Re: .Re: Lisp benefits against other functional programming languagesDoug Hoffman

Pages:123
Re: .Re: Lisp benefits against other functional programming languages

<87y20papkr.fsf@vc6-54.vc.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17430&group=comp.lang.forth#17430

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: russell_...@yahoo.com
Newsgroups: comp.lang.forth
Subject: Re: .Re: Lisp benefits against other functional programming languages
Date: Thu, 31 Mar 2022 15:29:08 -0400
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <87y20papkr.fsf@vc6-54.vc.panix.com>
References: <t0hs0f$80v$1@gioia.aioe.org>
<9f5fd43a-7fa6-4611-8fbf-6d2a77fe0de6n@googlegroups.com>
<6231998a$0$697$14726298@news.sunsite.dk>
<292c2ba5-aa78-43d3-acee-05c3f669a9a8n@googlegroups.com>
<87o825a2zq.fsf@nightsong.com> <t0ufjd$g3n$1@dont-email.me>
<87fsnh9mds.fsf@nightsong.com> <t0uhor$v0v$1@dont-email.me>
<2022Mar17.082842@mips.complang.tuwien.ac.at>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="17a37e4b174ff51aff42eded9f47e6f9";
logging-data="23502"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197Brocdi7lqp5AdcYDYCb8"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (berkeley-unix)
Cancel-Lock: sha1:ae5ZcDd9KUA5RsJsYps2VvuY6EI=
sha1:RT/Ai3kqYwLm361KxccjVlyXis4=
 by: russell_...@yahoo.com - Thu, 31 Mar 2022 19:29 UTC

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:

> Ron AARON <clf@8th-dev.com> writes:
>>On 17/03/2022 7:30, Paul Rubin wrote:
>>> Lists are also natural if you program in functional style, since you
>>> don't have to mutate existing objects (consing is just new allocations:
>>> the old stuff stays the same). The immutable equivalent of arrays is
>>> balanced trees, which are way more complicated to implement.
>>
>>I don't understand this. Arrays are just as immutable as balanced trees.
>>Or, rather, just as mutable. Either can be modified.
>
> His point is: If you have a language that does not support changing
> existing data structures, you program by creating a new item that
> represents the new state. In case of an array this means copying all
> the data that is not changed. In the case of a tree this means
> copying only the unchanged data in changed nodes and their ancestor
> nodes. For large data structures, this is much more efficient.
> Therefore, functional programs use trees instead of arrays.

There are implementations of functional arrays that do not require
copying all of the data that is not changed on each update. To
implement the "update" operation, you build and return a "view" of the
original array which implements the "update" and "lookup" operations so
that a view can be used wherever an array can itself be used. The view
contains a map of {index, value} representing changed values, as well as
a reference to the original array. The "lookup" operation on a view
first checks the map, then the underlying array. The "update" operation
on the view returns a new view with a modified map and reference to the
same array. It is straight forward to implement various policies which
will perform a full array copy when the number of elements in the map
reaches some threshold, whether it be a fixed number of items, or a
percentage of the size of the underlying array. In this way the cost of
copies can be amoritized.

-russ

Re: .Re: Lisp benefits against other functional programming languages

<6152cf3c-e331-420d-ba1e-fa13990c9f91n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17439&group=comp.lang.forth#17439

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:57d5:0:b0:2e0:70a8:4419 with SMTP id w21-20020ac857d5000000b002e070a84419mr11739026qta.257.1648901320039;
Sat, 02 Apr 2022 05:08:40 -0700 (PDT)
X-Received: by 2002:ac8:5dcb:0:b0:2e1:ce48:c186 with SMTP id
e11-20020ac85dcb000000b002e1ce48c186mr11799688qtx.2.1648901319884; Sat, 02
Apr 2022 05:08:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 2 Apr 2022 05:08:39 -0700 (PDT)
In-Reply-To: <87y20papkr.fsf@vc6-54.vc.panix.com>
Injection-Info: google-groups.googlegroups.com; posting-host=79.224.111.239; posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 79.224.111.239
References: <t0hs0f$80v$1@gioia.aioe.org> <9f5fd43a-7fa6-4611-8fbf-6d2a77fe0de6n@googlegroups.com>
<6231998a$0$697$14726298@news.sunsite.dk> <292c2ba5-aa78-43d3-acee-05c3f669a9a8n@googlegroups.com>
<87o825a2zq.fsf@nightsong.com> <t0ufjd$g3n$1@dont-email.me>
<87fsnh9mds.fsf@nightsong.com> <t0uhor$v0v$1@dont-email.me>
<2022Mar17.082842@mips.complang.tuwien.ac.at> <87y20papkr.fsf@vc6-54.vc.panix.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6152cf3c-e331-420d-ba1e-fa13990c9f91n@googlegroups.com>
Subject: Re: .Re: Lisp benefits against other functional programming languages
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Sat, 02 Apr 2022 12:08:40 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 55
 by: minf...@arcor.de - Sat, 2 Apr 2022 12:08 UTC

russell...@yahoo.com schrieb am Donnerstag, 31. März 2022 um 21:24:58 UTC+2:
> an...@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>
> > Ron AARON <c...@8th-dev.com> writes:
> >>On 17/03/2022 7:30, Paul Rubin wrote:
> >>> Lists are also natural if you program in functional style, since you
> >>> don't have to mutate existing objects (consing is just new allocations:
> >>> the old stuff stays the same). The immutable equivalent of arrays is
> >>> balanced trees, which are way more complicated to implement.
> >>
> >>I don't understand this. Arrays are just as immutable as balanced trees..
> >>Or, rather, just as mutable. Either can be modified.
> >
> > His point is: If you have a language that does not support changing
> > existing data structures, you program by creating a new item that
> > represents the new state. In case of an array this means copying all
> > the data that is not changed. In the case of a tree this means
> > copying only the unchanged data in changed nodes and their ancestor
> > nodes. For large data structures, this is much more efficient.
> > Therefore, functional programs use trees instead of arrays.
>
> There are implementations of functional arrays that do not require
> copying all of the data that is not changed on each update. To
> implement the "update" operation, you build and return a "view" of the
> original array which implements the "update" and "lookup" operations so
> that a view can be used wherever an array can itself be used. The view
> contains a map of {index, value} representing changed values, as well as
> a reference to the original array. The "lookup" operation on a view
> first checks the map, then the underlying array. The "update" operation
> on the view returns a new view with a modified map and reference to the
> same array. It is straight forward to implement various policies which
> will perform a full array copy when the number of elements in the map
> reaches some threshold, whether it be a fixed number of items, or a
> percentage of the size of the underlying array. In this way the cost of
> copies can be amoritized.
Thanks for the clarification. Given the typical amount of views and/or slices even
in moderate NumPy or Matlab code, I assume that garbage collection can become
rather complex.

Given the typical compactness of Forth, automatic garbage collection would
mean overkill. OTOH dynamically allocated/resized/freed maps and arrays are no
rocket science, but unfortunately with everybody's homebrewed syntax.

Re: Tail call optimization (was: .Re: Lisp benefits ...)

<070601a6-d56c-4d55-964f-9837a60eeca9n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17440&group=comp.lang.forth#17440

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:1304:b0:2eb:89a0:cf43 with SMTP id v4-20020a05622a130400b002eb89a0cf43mr11947071qtk.655.1648907195209;
Sat, 02 Apr 2022 06:46:35 -0700 (PDT)
X-Received: by 2002:a05:6214:1cc3:b0:443:689a:9b72 with SMTP id
g3-20020a0562141cc300b00443689a9b72mr21134141qvd.125.1648907195064; Sat, 02
Apr 2022 06:46:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 2 Apr 2022 06:46:34 -0700 (PDT)
In-Reply-To: <2022Mar20.230449@mips.complang.tuwien.ac.at>
Injection-Info: google-groups.googlegroups.com; posting-host=82.95.228.79; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 82.95.228.79
References: <t0hs0f$80v$1@gioia.aioe.org> <t0uvic$qr9$1@dont-email.me>
<87v8wc8288.fsf@nightsong.com> <t1156o$iu1$1@dont-email.me>
<87r16z94ap.fsf@nightsong.com> <t1185m$54o$1@dont-email.me>
<7d82f345-17ca-4470-81df-d176ee91856an@googlegroups.com> <t151c1$uno$1@dont-email.me>
<878rt56cdk.fsf@nightsong.com> <2022Mar19.195204@mips.complang.tuwien.ac.at>
<87wngprapl.fsf@nightsong.com> <2022Mar19.225323@mips.complang.tuwien.ac.at>
<22696f9d-0242-4ce3-b548-6d846e154123n@googlegroups.com> <2022Mar20.230449@mips.complang.tuwien.ac.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <070601a6-d56c-4d55-964f-9837a60eeca9n@googlegroups.com>
Subject: Re: Tail call optimization (was: .Re: Lisp benefits ...)
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Sat, 02 Apr 2022 13:46:35 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 30
 by: Hans Bezemer - Sat, 2 Apr 2022 13:46 UTC

On Sunday, March 20, 2022 at 11:16:58 PM UTC+1, Anton Ertl wrote:
> In Gforth it would be more complex, because there is some native code
> compiled along with the threaded code. I think the way to go would be
> to delay passing along a call to the later stages of compilation. If
> the next thing to compile is a ";s", generate a branch, otherwise
> generate a call followed by whatever is behind it.
I can't look in anyones implementation, but I CAN give a few hints how 4tH pulled it of:
(1) There is a FENCE (not to be confused with Forth-79 FENCE), which determines the point where
no more optimization is allowed. E.g. in this case:

15 BEGIN 10+ (..) REPEAT

4tH's peephole optimizer would be triggered to do constant folding (since BEGIN compiles to nothing).
By letting BEGIN move the FENCE to "15" it will NOT be considered for ANY optimization.
The same goes for THEN, so:

: dummy IF this ELSE that THEN ;

Will not result in a BRANCH at the very end (because "that" is called), but still trigger an EXIT. Of course,

: dummy IF this EXIT THEN that ;

Will result in much tighter code (since both "this" and "that" can be tail optimized). For that reason 4tH
supports ;THEN (which should be considered "syntactical sugar"):

: dummy IF this ;THEN that ;

(2) Disabling the optimizer - but this is RARE (and mostly manual). It is also very temporary, because the
compiler will reenable it after compiling the next instruction (unoptimized).

Hans Bezemer

Re: .Re: Lisp benefits against other functional programming languages

<2022Apr2.174700@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17443&group=comp.lang.forth#17443

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: .Re: Lisp benefits against other functional programming languages
Date: Sat, 02 Apr 2022 15:47:00 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 36
Message-ID: <2022Apr2.174700@mips.complang.tuwien.ac.at>
References: <t0hs0f$80v$1@gioia.aioe.org> <9f5fd43a-7fa6-4611-8fbf-6d2a77fe0de6n@googlegroups.com> <6231998a$0$697$14726298@news.sunsite.dk> <292c2ba5-aa78-43d3-acee-05c3f669a9a8n@googlegroups.com> <87o825a2zq.fsf@nightsong.com> <t0ufjd$g3n$1@dont-email.me> <87fsnh9mds.fsf@nightsong.com> <t0uhor$v0v$1@dont-email.me> <2022Mar17.082842@mips.complang.tuwien.ac.at> <87y20papkr.fsf@vc6-54.vc.panix.com>
Injection-Info: reader02.eternal-september.org; posting-host="10dd54bcaacc39b5b6f7c604ae6a8c90";
logging-data="8685"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/K0fCr702EgIE3abyrTpAq"
Cancel-Lock: sha1:lAM9d3EF1/wSTrR9kdSGYypkxWM=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sat, 2 Apr 2022 15:47 UTC

russell_mcmanus@yahoo.com writes:
>There are implementations of functional arrays that do not require
>copying all of the data that is not changed on each update. To
>implement the "update" operation, you build and return a "view" of the
>original array which implements the "update" and "lookup" operations so
>that a view can be used wherever an array can itself be used. The view
>contains a map of {index, value} representing changed values, as well as
>a reference to the original array. The "lookup" operation on a view
>first checks the map, then the underlying array. The "update" operation
>on the view returns a new view with a modified map and reference to the
>same array. It is straight forward to implement various policies which
>will perform a full array copy when the number of elements in the map
>reaches some threshold, whether it be a fixed number of items, or a
>percentage of the size of the underlying array. In this way the cost of
>copies can be amoritized.

How is the map implemented?

Most likely with some trie or search tree, i.e., the same you would
use if you did not have the flat array, only with only a part of the
members. You would probably use the balance of reads vs. updates to
decide when to consolidate the updates into a new flat array: with
mostly updates, the flat array does not pay off, whereas with very
rare upates, it may pay off to consolidate on a flat array after only
a few of them.

Another approach is known as "linear logic": If you know that the
original array is no longer alive after the update, you can update the
flat array directly.

- 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 2021: https://euro.theforth.net/2021

Re: .Re: Lisp benefits against other functional programming languages

<2022Apr2.180341@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17444&group=comp.lang.forth#17444

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: .Re: Lisp benefits against other functional programming languages
Date: Sat, 02 Apr 2022 16:03:41 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 19
Message-ID: <2022Apr2.180341@mips.complang.tuwien.ac.at>
References: <t0hs0f$80v$1@gioia.aioe.org> <9f5fd43a-7fa6-4611-8fbf-6d2a77fe0de6n@googlegroups.com> <6231998a$0$697$14726298@news.sunsite.dk> <292c2ba5-aa78-43d3-acee-05c3f669a9a8n@googlegroups.com> <87o825a2zq.fsf@nightsong.com> <t0ufjd$g3n$1@dont-email.me> <87fsnh9mds.fsf@nightsong.com> <t0uhor$v0v$1@dont-email.me> <2022Mar17.082842@mips.complang.tuwien.ac.at> <87y20papkr.fsf@vc6-54.vc.panix.com> <6152cf3c-e331-420d-ba1e-fa13990c9f91n@googlegroups.com>
Injection-Info: reader02.eternal-september.org; posting-host="10dd54bcaacc39b5b6f7c604ae6a8c90";
logging-data="8685"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2/utpg1gCuEhILEVqFEwt"
Cancel-Lock: sha1:gW/AZUyl7n+/giqdzSxpLu2kZWI=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sat, 2 Apr 2022 16:03 UTC

"minf...@arcor.de" <minforth@arcor.de> writes:
>Thanks for the clarification. Given the typical amount of views and/or slic=
>es even
>in moderate NumPy or Matlab code, I assume that garbage collection can bec=
>ome
>rather complex.

Garbage collection typically does not care about the actual complexity
of the data structures, and a stop-the-world garbage collector for
single-threaded programs is not particularly complex. Things that
make it complex are simultaneous multiprocessing (SMP) and (soft)
real-time requirements.

- 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 2021: https://euro.theforth.net/2021

Re: Tail call optimization (was: .Re: Lisp benefits ...)

<2022Apr2.194209@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17447&group=comp.lang.forth#17447

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: Tail call optimization (was: .Re: Lisp benefits ...)
Date: Sat, 02 Apr 2022 17:42:09 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 25
Message-ID: <2022Apr2.194209@mips.complang.tuwien.ac.at>
References: <t0hs0f$80v$1@gioia.aioe.org> <87r16z94ap.fsf@nightsong.com> <t1185m$54o$1@dont-email.me> <7d82f345-17ca-4470-81df-d176ee91856an@googlegroups.com> <t151c1$uno$1@dont-email.me> <878rt56cdk.fsf@nightsong.com> <2022Mar19.195204@mips.complang.tuwien.ac.at> <87wngprapl.fsf@nightsong.com> <2022Mar19.225323@mips.complang.tuwien.ac.at> <22696f9d-0242-4ce3-b548-6d846e154123n@googlegroups.com> <2022Mar20.230449@mips.complang.tuwien.ac.at> <070601a6-d56c-4d55-964f-9837a60eeca9n@googlegroups.com>
Injection-Info: reader02.eternal-september.org; posting-host="10dd54bcaacc39b5b6f7c604ae6a8c90";
logging-data="13573"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hjgasLfj/IGiV0wOakB1u"
Cancel-Lock: sha1:oj/6R9VJw+RZn2217Lr617jr3xI=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sat, 2 Apr 2022 17:42 UTC

Hans Bezemer <the.beez.speaks@gmail.com> writes:
>The same goes for THEN, so:
>
>: dummy IF this ELSE that THEN ;
>
>Will not result in a BRANCH at the very end (because "that" is called), but still trigger an EXIT.

Note that in this example the calls to THIS and THAT are tail-calls
and can be tail-call optimized by a sufficiently sophisticated
compiler. However, I recently did some measurements that showed that
the dynamic sequence

call branch ;s

(e.g., for the THIS tail-call in the example above) is relatively rare
rare, so it does not pay to go to great lengths to optimize such
cases. But optimizing the THAT call into a branch would be fine (you
just cannot leave the ;S/EXIT after the THEN away).

- 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 2021: https://euro.theforth.net/2021

Re: .Re: Lisp benefits against other functional programming languages

<87v8vrf4a8.fsf@nightsong.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17450&group=comp.lang.forth#17450

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no.em...@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth
Subject: Re: .Re: Lisp benefits against other functional programming languages
Date: Sat, 02 Apr 2022 16:34:39 -0700
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <87v8vrf4a8.fsf@nightsong.com>
References: <t0hs0f$80v$1@gioia.aioe.org>
<9f5fd43a-7fa6-4611-8fbf-6d2a77fe0de6n@googlegroups.com>
<6231998a$0$697$14726298@news.sunsite.dk>
<292c2ba5-aa78-43d3-acee-05c3f669a9a8n@googlegroups.com>
<87o825a2zq.fsf@nightsong.com> <t0ufjd$g3n$1@dont-email.me>
<87fsnh9mds.fsf@nightsong.com> <t0uhor$v0v$1@dont-email.me>
<2022Mar17.082842@mips.complang.tuwien.ac.at>
<87y20papkr.fsf@vc6-54.vc.panix.com>
<2022Apr2.174700@mips.complang.tuwien.ac.at>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="eb1cb23e3d6de75ea7671688830a01c1";
logging-data="484"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cqlBDtXzKMmQeo7A6Q5AZ"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:gzDRFg85wOgTih3yHrRgMoxX9+k=
sha1:XGvdwFdwEDJHr0IkCFEAsDW2xdk=
 by: Paul Rubin - Sat, 2 Apr 2022 23:34 UTC

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
> Another approach is known as "linear logic": If you know that the
> original array is no longer alive after the update, you can update the
> flat array directly.

It's enough to just analyze the data flow for that. That's how STRef
and mutable arrays in Haskell work: they have special datatypes that
ensure that the mutable values are never used in two different places.
If the program tries to do otherwise, the type checker complains.

Re: Tail call optimization (was: .Re: Lisp benefits ...)

<1ae6f278-5365-4b9e-b451-6b2a42d58082n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17453&group=comp.lang.forth#17453

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:21a3:b0:441:35fd:920e with SMTP id t3-20020a05621421a300b0044135fd920emr14078176qvc.41.1648989639201;
Sun, 03 Apr 2022 05:40:39 -0700 (PDT)
X-Received: by 2002:a05:620a:2481:b0:67b:39ef:b3eb with SMTP id
i1-20020a05620a248100b0067b39efb3ebmr11282306qkn.188.1648989639082; Sun, 03
Apr 2022 05:40:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 3 Apr 2022 05:40:38 -0700 (PDT)
In-Reply-To: <2022Apr2.194209@mips.complang.tuwien.ac.at>
Injection-Info: google-groups.googlegroups.com; posting-host=82.95.228.79; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 82.95.228.79
References: <t0hs0f$80v$1@gioia.aioe.org> <87r16z94ap.fsf@nightsong.com>
<t1185m$54o$1@dont-email.me> <7d82f345-17ca-4470-81df-d176ee91856an@googlegroups.com>
<t151c1$uno$1@dont-email.me> <878rt56cdk.fsf@nightsong.com>
<2022Mar19.195204@mips.complang.tuwien.ac.at> <87wngprapl.fsf@nightsong.com>
<2022Mar19.225323@mips.complang.tuwien.ac.at> <22696f9d-0242-4ce3-b548-6d846e154123n@googlegroups.com>
<2022Mar20.230449@mips.complang.tuwien.ac.at> <070601a6-d56c-4d55-964f-9837a60eeca9n@googlegroups.com>
<2022Apr2.194209@mips.complang.tuwien.ac.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1ae6f278-5365-4b9e-b451-6b2a42d58082n@googlegroups.com>
Subject: Re: Tail call optimization (was: .Re: Lisp benefits ...)
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Sun, 03 Apr 2022 12:40:39 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 36
 by: Hans Bezemer - Sun, 3 Apr 2022 12:40 UTC

On Saturday, April 2, 2022 at 7:47:51 PM UTC+2, Anton Ertl wrote:
> Hans Bezemer <the.bee...@gmail.com> writes:
> Note that in this example the calls to THIS and THAT are tail-calls
> and can be tail-call optimized by a sufficiently sophisticated
> compiler.

I stand corrected by both you AND my compiler! The EXIT is required for the
IF part of the conditional - but not the ELSE part. And that's what 4tH does:

: this ; : that ;
: bla 0 if this else that then ;

4tH message: No errors at word 11
Object size: 11 words
String size: 0 chars
Variables : 0 cells
Strings : 0 chars
Symbols : 0 names
Reliable : Yes

Addr| Opcode Operand Argument

0| branch 2
1| exit 0
2| branch 4
3| exit 0
4| branch 11
5| literal 0
6| 0branch 8
7| call 1
8| branch 10
9| branch 3
10| exit 0

BTW, I edited the BRANCH addresses for those unfamiliar with 4tH.

Hans Bezemer

Re: .Re: Lisp benefits against other functional programming languages

<2022Apr3.183014@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17455&group=comp.lang.forth#17455

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: .Re: Lisp benefits against other functional programming languages
Date: Sun, 03 Apr 2022 16:30:14 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 38
Message-ID: <2022Apr3.183014@mips.complang.tuwien.ac.at>
References: <t0hs0f$80v$1@gioia.aioe.org> <9f5fd43a-7fa6-4611-8fbf-6d2a77fe0de6n@googlegroups.com> <6231998a$0$697$14726298@news.sunsite.dk> <292c2ba5-aa78-43d3-acee-05c3f669a9a8n@googlegroups.com> <87o825a2zq.fsf@nightsong.com> <t0ufjd$g3n$1@dont-email.me> <87fsnh9mds.fsf@nightsong.com> <t0uhor$v0v$1@dont-email.me> <2022Mar17.082842@mips.complang.tuwien.ac.at> <87y20papkr.fsf@vc6-54.vc.panix.com> <2022Apr2.174700@mips.complang.tuwien.ac.at> <87v8vrf4a8.fsf@nightsong.com>
Injection-Info: reader02.eternal-september.org; posting-host="07ea556e7cce6840430f16d07da63976";
logging-data="12929"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UmCgakyJFVjSX8tnebF5D"
Cancel-Lock: sha1:ijdVkV3UiCREQOINBeFn5CXd1NI=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sun, 3 Apr 2022 16:30 UTC

Paul Rubin <no.email@nospam.invalid> writes:
>anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>> Another approach is known as "linear logic": If you know that the
>> original array is no longer alive after the update, you can update the
>> flat array directly.
>
>It's enough to just analyze the data flow for that. That's how STRef
>and mutable arrays in Haskell work: they have special datatypes that
>ensure that the mutable values are never used in two different places.
>If the program tries to do otherwise, the type checker complains.

Well, of course Haskell uses its type checker to achieve this.

How would a Forth solution look like? Here's my take: Have a stack of
arrays (or, more generally, objects), and, e.g., array variables. An
array variable fetch pushes the array from the value to the array
stack, and zeros the array variable (unlike an ordinary variable
fetch). An array variable write deallocates the array currently in
the variable (if it is non-zero), and stores the array reference
there. There is no ADUP for the array stack, or if there is, it
creates a new copy. Likewise, all other array operations (e.g.,
updates of an element) are designed such that the reference to the
array is not copied.

My vector words <http://www.euroforth.org/ef17/papers/ertl.pdf> have
value semantics, which requires an implementation along the lines
outlined above. It does not follow a strict linear logic approach,
but there is, e.g., v@', which is the variant of v@ that zeros the
variable. As an alternative to copying on vdup (called "linear" in
the paper), there is also the possibility to use reference counting
(and copy on write).

- 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 2021: https://euro.theforth.net/2021

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor