Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #50449
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: CfV: Quotations |
| Date | 2016-08-24 15:54 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2016Aug24.175406@mips.complang.tuwien.ac.at> (permalink) |
| References | (5 earlier) <npafji$59r$1@dont-email.me> <2016Aug21.113258@mips.complang.tuwien.ac.at> <npdbbl$vqt$2@dont-email.me> <2016Aug22.155432@mips.complang.tuwien.ac.at> <npg1ao$29b$1@dont-email.me> |
Bernd Paysan <bernd.paysan@gmx.de> writes:
>In Common Lisp, you would do that with closures. In an OOP system, you
>do it with OOP.
Somehow, in the last few years, several popular object-oriented
languages, e.g., Java, C++, and C#, have acquired lambdas; apparently
not everybody does it with OOP.
And actually you are not using the distinctive feature of OOP: dynamic
binding. What you use, is the current-object pointer. However, this
allows access only to locals from one activation record; that's enough
for the man-or-boy test, but not in the general case. Is the general
case needed? Yes, in particular in curried functions each argument is
in a separate activation record.
>And if you want a more compact format of declaring
>things, just define them. You could have an OOP system that declares the
>class in one line, and creates you an instantiation code that takes the
>initial values from stack, just with about the same amount of code we
>need to implement locals (a lot more code than mini-oof2.fs).
>
><base class> O{ k x1 x2 x3 x4 x5 }O mob
>
>certainly is possible. There's even a mini-oof.fs based implementation
>of closures, which does just that. If we wanted to generalize the locals
>declaration, we could easily reuse most of the code in glocals.fs; after
>all, the declaration of a set of locals and the declaration of a set of
>instance variables is the same problem: Create a bunch of names which
>address consecutive elements in memory; one time on a locals stack,
>another time in an object.
Is the locals-derived "class" definition useful for anything besides
locals?
Of course, if we support non-local locals, we will have to enhance the
locals code to create activation records when needed, and also to
create the access to the right activation record. The definition part
is similar to a structure or class definition, but the access part is
quite different for the general case.
We also need a way to specify how an activation record is allocated
and how long it lives. E.g., for something CREATE-DOES>-like we want
to ALLOT the memory:
: constant ( x "name" -- )
['] here-allot <{: x :}
[: x :] <create ;
This would allot the activation record (and HERE-ALLOT is an ALLOT
that returns the address of the allotted memory), and at run-time it
accesses the local and return it.
>If you look at the Rosetta code page of the man-or-boy test, you'll find
>a number of implementations which use classes to implement the activation
>record, so I think that approach is fair and useful.
I also find that the C++11 and C# version 3+ have shorter source code
by using anonymous functions/lambda expressions.
- 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 2016: http://www.euroforth.org/ef16/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-10 16:52 +0000
Re: CfV: Quotations Matthias Trute <matthias.trute@gmail.com> - 2016-08-10 11:19 -0700
Re: CfV: Quotations Paul Rubin <no.email@nospam.invalid> - 2016-08-10 11:55 -0700
Re: CfV: Quotations Bernd Paysan <bernd.paysan@gmx.de> - 2016-08-14 20:52 +0000
Re: CfV: Quotations hughaguilar96@gmail.com - 2016-08-14 14:42 -0700
Re: CfV: Quotations Julian Fondren <julian.fondren@gmail.com> - 2016-08-14 16:43 -0700
Re: CfV: Quotations Paul Rubin <no.email@nospam.invalid> - 2016-08-15 22:16 -0700
Re: CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-16 07:13 +0000
Re: CfV: Quotations Paul Rubin <no.email@nospam.invalid> - 2016-08-18 15:30 -0700
Re: CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-19 15:32 +0000
Re: CfV: Quotations Bernd Paysan <bernd.paysan@gmx.de> - 2016-08-20 20:46 +0000
Re: CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-21 09:32 +0000
Re: CfV: Quotations hughaguilar96@gmail.com - 2016-08-21 11:06 -0700
Re: CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-24 17:02 +0000
Re: CfV: Quotations Bernd Paysan <bernd.paysan@gmx.de> - 2016-08-21 22:52 +0000
Re: CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-22 13:54 +0000
Re: CfV: Quotations Bernd Paysan <bernd.paysan@gmx.de> - 2016-08-22 23:19 +0000
Re: CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-24 15:54 +0000
Re: CfV: Quotations Bernd Paysan <bernd@net2o.de> - 2016-08-28 00:43 +0000
Re: CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-28 09:53 +0000
Re: CfV: Quotations Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-08-28 08:32 -0500
Re: CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-28 14:38 +0000
Re: CfV: Quotations mhx@iae.nl - 2016-08-10 12:02 -0700
Re: CfV: Quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-08-11 17:25 +0100
Re: CfV: Quotations Julian Fondren <julian.fondren@gmail.com> - 2016-08-11 12:48 -0700
Re: CfV: Quotations minforth@arcor.de - 2016-08-16 03:31 -0700
Re: CfV: Quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-08-31 15:15 +0100
Re: CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-31 15:26 +0000
Re: CfV: Quotations Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-09-02 22:33 +0100
Re: CfV: Quotations anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-09-03 06:47 +0000
csiph-web