struct vs OO vs language
[1/9] from: al::bri::xtra::co::nz at: 27-Sep-2001 16:46
Joel wrote (in another thread):
> I tend to use objects in a more "encapsulated" fashion, in which the
methods of the function are responsible for modifying the attributes of the
object, in constrast to a "c-struct" fashion, in which other code is free to
go in and manipulate the content of the object.
I've been reworking all my accumulated code and simplifying it all. I
discovered that it seemed simpler to work with functions rather than Rebol
objects. For example, I used to have a stack object! that looked some thing
like:
Stack!: make object! [
_Stack: []
Top: does [pick _Stack 1]
Pop: has [Value][Value: Top remove _Stack :Value]
Push: func [Value [any-type!] /only][
head either only [
insert/only _Stack :Value
][
insert _Stack :Value
]
]
]
I also had another function to clear the '_stack block value.
I grew dissatisfied with that approach, though. Now I've got:
Push: func [
"Inserts a value into a series and returns the series head."
Stack [series! port! bitset!] "Series at point to insert."
Value [any-type!] /Only "The value to insert."
][
head either Only [
insert/only Stack :Value
][
insert Stack :Value
]
]
and:
Pop: function [
"Returns the first value in a series and removes it from the series."
Stack [series! port! bitset!] "Series at point to pop from."
][
Value
][
Value: pick Stack 1
remove Stack
:Value
]
This approach now lets me 'push or 'pop values into/from any series, port or
bitset value, and allows me to work on nested blocks or other types of
series. Effectively, I've added two interesting words to Rebol's vocabulary.
I'm now taking the same approach to my version of 'associate and 'associate?
so as to achieve the same amount of versatility with them.
Andrew Martin
ICQ: 26227169 http://zen.scripterz.org
[2/9] from: al:bri:xtra at: 27-Sep-2001 17:01
And to make my point a bit more clearer: Now that I have a 'pop and 'push
word, I can create the equivalent of a queue by:
>> Q: []
== []
>> append Q 1
== [1]
>> append Q 2
== [1 2]
>> append Q 3
== [1 2 3]
>> pop Q
== 1
>> pop Q
== 2
>> pop Q
== 3
:-)
Andrew Martin
ICQ: 26227169 http://zen.scripterz.org
[3/9] from: ammoncooke:yaho:o at: 27-Sep-2001 1:17
----- Original Message -----
From: "Andrew Martin" <[Al--Bri--xtra--co--nz]>
To: <[rebol-list--rebol--com]>
Sent: Wednesday, September 26, 2001 9:46 PM
Subject: [REBOL] struct vs OO vs language
<Snip>
>
> This approach now lets me 'push or 'pop values into/from any series, port
or
> bitset value, and allows me to work on nested blocks or other types of
> series. Effectively, I've added two interesting words to Rebol's
vocabulary.
Didn't you take those words & functions straight from PERL? ;))
[4/9] from: al:bri:xtra at: 27-Sep-2001 18:24
Ammon joked:
> Didn't you take those words & functions straight from PERL? ;))
Actually, they came originally from my Motorola 6809 microprocesser assembly
language. :-)
Andrew Martin
ICQ: 26227169 http://zen.scripterz.org
[5/9] from: jelinem1:nationwide at: 27-Sep-2001 9:24
>> This approach now lets me 'push or 'pop values into/from any series,
port or bitset value, and allows me to work on nested blocks or other
types of series. Effectively, I've added two interesting words to Rebol's
vocabulary.
> Didn't you take those words & functions straight from PERL? ;))
LOL! I'm sure he did! And GUI drag-and-drop functionality came from
MSWindows.
- Michael
[6/9] from: jasonic:panix at: 27-Sep-2001 11:47
Andrew Martin
<[Al--Bri--xtra--co--nz]>
> I've been reworking all my accumulated code and simplifying it all. I
> discovered that it seemed simpler to work with functions rather than Rebol
> objects.
<snip before and after examples>
interesting..this is more like good Forth code, where the real art lies in
factoring out useful words and thus adding to the language not only solving
the problem. The best book on that was the classic 'Thinking Forth' by Leo
Brodie
Paperback 2nd ed edition (1994)
Forth Interest Group; ISBN: 0935533001
The same is true of Postscript, though people dont' really think of it
anylonger as more than a Page description language to be exchanged between
design software and output devices. The NeXT [c.1990] computer used Display
Postscript for all the GUI in the begining. That put some heavy demands on
processor speed and RAM, but it was a good idea. An extended Rebol could
presumably be used for an entire GUI environment.
Anyone know if Forth plays a conscious role in Rebol's development ?
- Jason
[7/9] from: greggirwin:starband at: 27-Sep-2001 10:59
Hi Jason,
<< Anyone know if Forth plays a conscious role in Rebol's development ? >>
I'm not a Forth guy, but aren't blocks a core construct in Forth? I would
bet that Carl has looked at most languages out there and distilled the
best ideas from each of them.
--Gregg
[8/9] from: joel:neely:fedex at: 27-Sep-2001 12:18
Hi, Gregg,
As an old FORTH guy...
Gregg Irwin wrote:
> Hi Jason,
>
> << Anyone know if Forth plays a conscious role in Rebol's
> development ? >>
>
> I'm not a Forth guy, but aren't blocks a core construct in Forth?
> I would bet that Carl has looked at most languages out there and
> distilled the best ideas from each of them.
>
Same word, totally different meaning.
A REBOL "block" is an ordered collection of (zero or more) REBOL
values, etc... A relatively high-level concept.
A FORTH "block" is 1k of disk storage. Originally used both for
data and code. In the case of code, originally presented IIRC as
a 16-line x 64-character view in an editor screen (built into,
and written in, FORTH itself, of course ;-). A very low-level
concept.
-jn-
--
This sentence contradicts itself -- no actually it doesn't.
-- Doug Hofstadter
joel<dot>neely<at>fedex<dot>com
[9/9] from: greggirwin:starband at: 27-Sep-2001 12:32
<< Same word, totally different meaning. >>
Ahhh. Thanks for clearing that up. I knew it was something to do with the
duality of data and code but it was just a foggy bit in the back of my mind.
--Gregg