Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #19481
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Parallax Propeller |
| Date | 2013-02-05 21:37 +0100 |
| Organization | 1&1 Internet AG |
| Message-ID | <2288352.092EWvyr2r@sunwukong.fritz.box> (permalink) |
| References | (7 earlier) <52dbbaee-c41d-4c9e-a053-9e9acfc360b5@f6g2000yqm.googlegroups.com> <a4032a5a-73c6-485e-8ffa-2ec01da40f51@po6g2000pbb.googlegroups.com> <keqoub$in2$1@speranza.aioe.org> <T5GdnUAcdsK9h4zMnZ2dnUVZ_oGdnZ2d@supernews.com> <7xy5f2vcyx.fsf@ruckus.brouhaha.com> |
Paul Rubin wrote:
> Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>> I think closures are more C++ than C. Closures are really just about
>> notational convenience and expressiveness. There is nothing that you
>> can't write in C, but it might be a lot of C.
>
> C++11 has anonymous functions but they're not Scheme-like closures
> from
> what I can tell. Closures seem much less useful without garbage
> collection. Their point is that any variables that are bound in the
> surrounding context but free in the nested function, have their values
> copied into the closure when the closure is created, and the closure
> (with those values) stays around after the surrounding function has
> returned. Languages without first-class functions usually do this
> sort of thing with OOP or similar.
C++11 "closures" are indeed that: OOP classes that have an overloaded
function call operator, which actually invokes a method.
I don't think that's too wrong. That's the way to do it in an OOP
language. The way I would implement this sort of pseudo-closures in
current Gforth (with OOP vtable for compile, and other stuff) is to
instantiate an object on the heap, which gets its first part filled with
a dodoes CFA and the apropriate vtable for compile, and the other
instance variables are filled with values from the stack. Call it, and
the xt bound to it can access these variables.
Freeing of no longer needed closures would be explicit. Syntax
something like
[:{ a b } ... use of a and b ... ;]
a and b would normal current-object ivars, and the setting of the
current object would be compiled into the quotation-like stuff. To free
it, you simply "dispose" the xt.
The difference from C++11's closures: This would be a real first class
function. It would just be implemented with some minor OOP technique
(instance variables). The ivars would live in the same temporary
dictionary region that's used for local variables, too. They would
actually be a variant of ivars which use TO for assignments...
The point of Forth design is not to exactly mimic something else, which
is overly complex or requires fundamental design changes to the
language, but build a tool, which solves the essence of the problem in a
way that is more natural to Forth.
Example: Let's have a Forth closure for a counter. We give it
initialization value and increment. With real closures, you would do
that as follows:
: counter { start inc -- xt }
[: ( -- value ) start inc + dup to start ;] ;
i.e. you create the locals outside the closure. The way as above would
be
: counter ( start inc -- xt )
[:{ start inc -- value } start inc + dup to start ;] ;
This makes it an extension to Forth, which require some carnal knowledge
(how to add words to the locals space), but otherwise fits into the
standard design decisions of a Forth system, i.e. no garbage collection,
and no non-trivial lexical scoping.
--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Parallax Propeller Peter Jakacki <peterjakacki@gmail.com> - 2013-01-13 06:37 +0000
Re: Parallax Propeller MK <mk@nospam.co.uk> - 2013-01-13 10:26 +0000
Re: Parallax Propeller Peter Jakacki <peterjakacki@gmail.com> - 2013-01-13 12:22 +0000
Re: Parallax Propeller Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-01-13 07:24 -0600
Re: Parallax Propeller Peter Jakacki <peterjakacki@gmail.com> - 2013-01-13 13:55 +0000
Re: Parallax Propeller mhx@iae.nl (Marcel Hendrix) - 2013-01-13 17:13 +0200
Re: Parallax Propeller Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-01-16 06:23 -0600
Re: Parallax Propeller Peter Jakacki <peterjakacki@gmail.com> - 2013-01-16 15:01 +0000
Re: Parallax Propeller Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-01-16 09:12 -0600
Re: Parallax Propeller Peter Jakacki <peterjakacki@gmail.com> - 2013-01-16 15:36 +0000
Re: Parallax Propeller Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-01-16 10:59 -0600
Re: Parallax Propeller Peter Jakacki <peterjakacki@gmail.com> - 2013-01-16 23:38 +0000
Re: Parallax Propeller Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-01-17 04:04 -0600
Re: Parallax Propeller Mark Wills <forthfreak@gmail.com> - 2013-01-17 04:52 -0800
Re: Parallax Propeller Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-01-24 22:48 -0800
Re: Parallax Propeller Mark Wills <forthfreak@gmail.com> - 2013-01-24 23:10 -0800
Re: Parallax Propeller Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-01-28 17:42 -0800
Re: Parallax Propeller "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-05 06:05 -0500
Re: Parallax Propeller Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-05 08:41 -0600
Re: Parallax Propeller Paul Rubin <no.email@nospam.invalid> - 2013-02-05 10:21 -0800
Re: Parallax Propeller Bernd Paysan <bernd.paysan@gmx.de> - 2013-02-05 21:37 +0100
Re: Parallax Propeller "Elizabeth D. Rather" <erather@forth.com> - 2013-02-05 10:44 -1000
Re: Parallax Propeller Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-02-05 15:52 -0600
Re: Parallax Propeller Paul Rubin <no.email@nospam.invalid> - 2013-02-06 00:29 -0800
Re: Parallax Propeller Paul Rubin <no.email@nospam.invalid> - 2013-02-06 00:31 -0800
Re: Parallax Propeller Bernd Paysan <bernd.paysan@gmx.de> - 2013-02-06 19:46 +0100
Re: Parallax Propeller Paul Rubin <no.email@nospam.invalid> - 2013-02-09 00:11 -0800
Re: Parallax Propeller anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-02-09 10:25 +0000
Re: Parallax Propeller Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-02-06 18:26 -0800
Re: Parallax Propeller Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-02-05 15:07 -0800
Re: Parallax Propeller Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-02-05 15:49 -0800
Re: Parallax Propeller "Rod Pemberton" <do_not_have@notemailnotz.cnm> - 2013-02-05 06:04 -0500
Re: Parallax Propeller Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-02-05 15:21 -0800
Re: Parallax Propeller rickman <gnuarm@gmail.com> - 2013-01-16 18:09 -0500
Re: Parallax Propeller Ben Bradley <ben_u_bradley@etcmail.com> - 2013-01-18 21:07 -0500
Re: Parallax Propeller "Paul E. Bennett" <Paul_E.Bennett@topmail.co.uk> - 2013-01-19 10:06 +0000
Re: Parallax Propeller Arlet Ottens <usenet+5@c-scape.nl> - 2013-01-19 13:04 +0100
Re: Parallax Propeller "A. K." <akk@nospam.org> - 2013-01-19 13:22 +0100
Re: Parallax Propeller Bernd Paysan <bernd.paysan@gmx.de> - 2013-01-19 13:38 +0100
Re: Parallax Propeller David Brown <david.brown@removethis.hesbynett.no> - 2013-01-19 17:12 +0100
Re: Parallax Propeller albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-01-19 16:45 +0000
Re: Parallax Propeller David Brown <david.brown@removethis.hesbynett.no> - 2013-01-20 17:49 +0100
Re: Parallax Propeller upsidedown@downunder.com - 2013-01-19 20:54 +0200
Re: Parallax Propeller Paul Rubin <no.email@nospam.invalid> - 2013-01-19 11:04 -0800
Re: Parallax Propeller upsidedown@downunder.com - 2013-01-19 23:05 +0200
Re: Parallax Propeller Mark Wills <markrobertwills@yahoo.co.uk> - 2013-01-20 01:05 -0800
Re: Parallax Propeller Arlet Ottens <usenet+5@c-scape.nl> - 2013-01-20 12:11 +0100
Re: Parallax Propeller upsidedown@downunder.com - 2013-01-20 13:53 +0200
Re: Parallax Propeller upsidedown@downunder.com - 2013-01-20 13:26 +0200
Re: Parallax Propeller Les Cargill <lcargill99@comcast.com> - 2013-01-19 14:23 -0600
Re: Parallax Propeller Les Cargill <lcargill99@comcast.com> - 2013-01-19 14:18 -0600
Re: Parallax Propeller David Brown <david.brown@removethis.hesbynett.no> - 2013-01-20 20:32 +0100
Re: Parallax Propeller Les Cargill <lcargill99@comcast.com> - 2013-01-20 18:08 -0600
Re: Parallax Propeller Walter Banks <walter@bytecraft.com> - 2013-01-20 17:12 -0500
Re: Parallax Propeller Mel Wilson <mwilson@the-wire.com> - 2013-01-20 19:19 -0500
Re: Parallax Propeller Walter Banks <walter@bytecraft.com> - 2013-01-20 21:12 -0500
Re: Parallax Propeller David Brown <david@westcontrol.removethisbit.com> - 2013-01-21 09:01 +0100
Re: Parallax Propeller Walter Banks <walter@bytecraft.com> - 2013-01-21 21:11 -0500
Re: Parallax Propeller upsidedown@downunder.com - 2013-01-22 09:39 +0200
Re: Parallax Propeller Mel Wilson <mwilson@the-wire.com> - 2013-01-22 10:14 -0500
Re: Parallax Propeller Waldek Hebisch <hebisch@math.uni.wroc.pl> - 2013-01-20 02:03 +0000
Re: Parallax Propeller George Neuner <gneuner2@comcast.net> - 2013-01-19 12:29 -0500
Re: Parallax Propeller rickman <gnuarm@gmail.com> - 2013-01-23 12:29 -0500
Re: Parallax Propeller Mark Wills <markrobertwills@yahoo.co.uk> - 2013-01-24 14:03 -0800
Re: Parallax Propeller Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-01-24 22:55 -0800
Re: Parallax Propeller Mark Wills <forthfreak@gmail.com> - 2013-01-24 23:03 -0800
Re: Parallax Propeller Coos Haak <chforth@hccnet.nl> - 2013-01-25 20:02 +0100
Re: Parallax Propeller Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-01-28 17:13 -0800
Re: Parallax Propeller David Brown <david@westcontrol.removethisbit.com> - 2013-01-29 09:15 +0100
Re: Parallax Propeller Anders.Montonen@kapsi.spam.stop.fi.invalid - 2013-01-30 12:19 +0000
Re: Parallax Propeller David Brown <david.brown@removethis.hesbynett.no> - 2013-01-30 21:18 +0100
Re: Parallax Propeller Mark Wills <forthfreak@gmail.com> - 2013-01-30 22:57 -0800
Re: Parallax Propeller Alex McDonald <blog@rivadpm.com> - 2013-01-31 10:38 -0800
Re: Parallax Propeller Mark Wills <forthfreak@gmail.com> - 2013-01-31 12:34 -0800
Re: Parallax Propeller Paul Rubin <no.email@nospam.invalid> - 2013-01-19 10:42 -0800
Re: Parallax Propeller bob@bob.com - 2013-01-19 19:56 -0600
Re: Parallax Propeller rickman <gnuarm@gmail.com> - 2013-01-23 12:40 -0500
Re: Parallax Propeller None <vandys@vsta.org> - 2013-01-24 23:26 +0000
Re: Parallax Propeller Walter Banks <walter@bytecraft.com> - 2013-01-25 11:49 -0500
Re: Parallax Propeller rickman <gnuarm@gmail.com> - 2013-01-25 09:25 -0500
Re: Parallax Propeller None <vandys@vsta.org> - 2013-01-25 21:57 +0000
Re: Parallax Propeller rickman <gnuarm@gmail.com> - 2013-01-26 18:07 -0500
Re: Parallax Propeller Mark Wills <markrobertwills@yahoo.co.uk> - 2013-01-27 00:50 -0800
Re: Parallax Propeller Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-01-27 03:30 -0600
Re: Parallax Propeller Dombo <dombo@disposable.invalid> - 2013-01-27 12:58 +0100
Re: Parallax Propeller rickman <gnuarm@gmail.com> - 2013-01-28 21:38 -0500
Re: Parallax Propeller None <vandys@vsta.org> - 2013-01-27 03:09 +0000
Re: Parallax Propeller rickman <gnuarm@gmail.com> - 2013-01-28 21:51 -0500
Re: Parallax Propeller None <vandys@vsta.org> - 2013-01-30 02:10 +0000
Re: Parallax Propeller rickman <gnuarm@gmail.com> - 2013-01-30 18:32 -0500
Re: Parallax Propeller David Schultz <abuse@127.0.0.1> - 2013-01-20 11:21 -0600
Re: Parallax Propeller albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-01-13 16:24 +0000
Re: Parallax Propeller David Brown <david@westcontrol.removethisbit.com> - 2013-01-14 10:51 +0100
Re: Parallax Propeller Peter Jakacki <peterjakacki@gmail.com> - 2013-01-16 06:06 +0000
Re: Parallax Propeller David Brown <david@westcontrol.removethisbit.com> - 2013-01-16 13:43 +0100
Re: Parallax Propeller Peter Jakacki <peterjakacki@gmail.com> - 2013-01-16 15:27 +0000
Re: Parallax Propeller Rafael Deliano <rafael_deliano@arcor.de> - 2013-01-15 21:10 +0100
Re: Parallax Propeller Peter Jakacki <peterjakacki@gmail.com> - 2013-01-16 06:26 +0000
Re: Parallax Propeller gavino_himself <visploveslisp@gmail.com> - 2013-01-22 06:26 -0800
Re: Parallax Propeller Peter Jakacki <peterjakacki@gmail.com> - 2013-01-13 12:44 +0000
csiph-web