Need help on something tricky...
[1/8] from: chrismorency:videotron:ca at: 3-Oct-2001 22:50
Hi,
I'm currently working on a rebol library that implements many useful
features to Rebol, but I have hit a nail I guess... so here's the nail...
and please I know the question, example may sound absurd but I would like to
implement this because developers using this script don't have to know what
it does actually... I only want to make the use of this script easier.
let's say I have a function that bind a word to a value :
bind-word-to: func [word value] [
do reduce [
to-set-word word rejoin [
value " of " to-string word
]
]
]
I would use it like this :
>> bind-word-to 'my-string "this is the value"
== "this is the value of my-string"
>> my-string
== "this is the value of my-string"
Now how could I use it this way instead ?
my-string: bind-word-to "this is the value"
I know the question or example may seem stupid, but it is 1) something I
don't know how to do, 2) something very useful in what I'm trying to attain,
ie user/developer simplicity for my library
Best,
Chris
[2/8] from: tim:johnsons-web at: 3-Oct-2001 20:48
On Wed, Oct 03, 2001 at 10:50:27PM -0400, Christian Morency wrote:
> Hi,
> I'm currently working on a rebol library that implements many useful
<<quoted lines omitted: 16>>
> == "this is the value of my-string"
> Now how could I use it this way instead ?
This isn't the best answer, but think about this until someone else
reads this.... (my wife is telling me to get my butt away from the
computer)
f: func[arg[word!]][print rejoin["the value of " arg " is " get arg]
>> f 't
the value of t is 4
> my-string: bind-word-to "this is the value"
> I know the question or example may seem stupid, but it is 1) something I
<<quoted lines omitted: 6>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.johnsons-web.com
[3/8] from: al:bri:xtra at: 4-Oct-2001 16:04
Chris wrote:
> Now how could I use it this way instead ?
>
> my-string: bind-word-to "this is the value"
There's no sensible or easy way to that. How about instead:
MyValues: reduce [
'my-string "this is the value"
]
and then sequencing through the block like:
foreach [Word Value] MyValues [
set Word Value
]
Would that do what you want?
Andrew Martin
Writing Rebol Dialects...
ICQ: 26227169 New Site Coming soon!
[4/8] from: chrismorency:videotron:ca at: 4-Oct-2001 0:29
Hi Tim,
Thanks for replying...
> This isn't the best answer, but think about this until someone else
> reads this.... (my wife is telling me to get my butt away from the
> computer)
> f: func[arg[word!]][print rejoin["the value of " arg " is " get arg]
> >> f 't
> the value of t is 4
I have to admit my first post wasn't clear, I'm tired these days (working
from 9:30 to 18:00 at the job, 19:00 to 2:00 on Rebol is not good for my
health ;). Ok, here's what I meant :
Let's say you have found a way to do class-object-inheritance under Rebol.
This is of course a speculation ;) You would prefer other developers who are
using your library to write it like :
new-class: make-class [
p: "This is a property"
m: func [] [print self/p]
]
which is quite similar to the current implementation of make instead of :
make-class 'new-class [
p: "This is a property"
m: func [] [print self/p]
]
So far this would be simple... however, let's say I want to make sure the
class-name is somehow integrated within the object and the end-result would
look like :
>> probe a
== make object! [
class-name: 'new-class
p: "This is a property"
m: func [] [print self/p]
]
I don't necessary want the developper to add "manually" this class-name
property... and I can't really trust the developper to do so ;) Now I would
need a way to know the receiver of the class while generating the class! and
the only way I can think of is the make-class 'new-class []
This is what I meant, maybe I didn't understand your example though...
Best,
Chris (who's really working on something like this, but as of yet not tested
enough)
[5/8] from: chrismorency:videotron:ca at: 4-Oct-2001 0:34
Hi Andrew,
> There's no sensible or easy way to that. How about instead:
> MyValues: reduce [
<<quoted lines omitted: 5>>
> ]
> Would that do what you want?
No and yes, of course what you present would work, it would work knowing
that your receiver would be MyValues... but in my case I don't know... See
response to Tim on what I'm trying to achieve...
You really need to see this as a library that others will use for
developping rebol code, you don't know which receiver (variables-name)
they'll use...
(I knew I wasn't clear with that first post ;))
Best,
Chris
[6/8] from: al:bri:xtra at: 4-Oct-2001 16:55
Christian wrote:
> You really need to see this as a library that others will use for
developping rebol code, you don't know which receiver (variables-name)
they'll use...
For my library code, I do (using %eText.r as an example):
rebol []
make object! [
; hidden words & values that only the below function can access:
set 'eText func [Text [string!]][
]
]
and it's used like this:
do %eText.r
eText read %text.txt
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
[7/8] from: al::bri::xtra::co::nz at: 4-Oct-2001 16:55
Christian wrote:
> >> probe a
> == make object! [
> class-name: 'new-class
> p: "This is a property"
> m: func [] [print self/p]
> ]
Would a member function like:
New: does [make self []]
be helpful?
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
[8/8] from: chrismorency:videotron:ca at: 4-Oct-2001 1:24
Hi Andrew,
> Would a member function like:
> New: does [make self []]
> be helpful?
Yes and no, unfortunately, the way "make" works under rebol is to clone
everything from properties to methods.
Try the following :
a: make object! [
p: "nice string"
m: func [] [return self/p]
]
b: make a []
>> probe a
== make object! [
p: "nice string"
m: func [] [return self/p]
]
>> probe b
== make object! [
p: "nice string"
m: func [] [return self/p]
]
now change the following:
a/p: "nasty string"
a/m: func [] [return "nope, this shouldn't be"]
probe a
probe b
>> probe a
== make object! [
p: "nasty string"
m: func [] [return "nope, this shouldn't be"]
]
>> probe b
== make object! [
p: "nice string"
m: func [] [return self/p]
]
You would expect p to remain "nice string" in b, but since m was inherited
from a, you would have expected m to have changed in b too... somehow, since
a was class for b... however class doesn't exist under rebol.
Now let's say you design something big, with let's say 100 objects based on
one class... you would get all properties into each object, which is good,
but you would also get all functions (methods)... now as you can see, RT did
it this way because it somehow make sense when you consider it's a scripting
language BUT you get all of these different objects using a lot of memory.
The way I've implemented my library may eventually be very bad-looking... it
may add a lot of overhead. However, it will use less memory.
In your example : does [return make self []]... it will actually return a
new object based on self. However, everything will be copied.
So far, I've implemented the following methods : make (class declaration),
make/from (class inheritance), new (object declaration) and type-of (object
vs class validation)... I'm about to implement super... after that I have to
test every possible datatype within an object. Class within class within
class will end up being object within object within object... this is all
through recursivity (how many time can I go recursive without having Rebol
hanging on me ?)
Btw, I noticed you were working on a dice roller on the mailing list, I
actually wrote something if you're interested. I always write a dice-roller
as my first software for all language I learn. In fact, the reasons I'm
writing this class-object thing is to build a rpg software.
Best,
Chris
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted