context of a function - Enhancement request
[1/5] from: fsievert::uos::de at: 21-Aug-2000 13:23
The best sollution would be to enhance "in" so you can not only get words
out of object's context, but also out of functions context.
f: func [a] [a]
f 2
in :f 'a
== a
same? first second :f in :f 'a
== true
Good idea?
Frank
[2/5] from: lmecir:geocities at: 21-Aug-2000 17:35
> The best sollution would be to enhance "in" so you can not only
get words
> out of object's context, but also out of functions context.
> f: func [a] [a]
<<quoted lines omitted: 5>>
> Good idea?
> Frank
Sure, copy it to feedback, please. I prefer this to the 'Self
idea.
Moreover, I would like to have an option to create objects without
'Self if needed. (I wasn't the one who asked for 'Self.) Opinions?
Regards
Ladislav
[3/5] from: rebol:techscribe at: 21-Aug-2000 22:23
Hi Frank,
>Good idea?
Yes. Let's go:
>> f: func [a] [a]
>> in-func :f 'a
== a
>> f 3
== 3
>> get in-func :f 'a
== 3
>> f 4
== 4
>> get in-func :f 'a
== 4
in-func is based on the the cfunc from my earlier email and a modified
get-context-block function:
in-func: func [f [function!] word [word!] /local cb ] [
cb: get-context-block :f
return bind :word first cb
]
get-context-block: func [f [function!] /local block] [
either all [
function? :f
(pick second :f 1) = 'self
]
[
fblock: make block! length? first :f
foreach word first :f [
if not :word = /local [
append fblock to word! word
]
]
return bind fblock first second :f
][
return none
]
]
cfunc: func [spec body] [
"Defines a user function with given spec and body and adds the word self."
[catch]
spec [block!] {Help string (opt) followed by arg words (and opt type
and string)}
body [block!] "The body block of the function"
either found? find spec /local [
insert tail spec 'self
][
insert tail spec [/local self]
]
insert body 'self
throw-on-error [make function! spec body]
]
BTW
>same? first second :f in :f 'a
>== true
does not work for objects:
>> o: make object! [a: none b: none]
>> second first :o
== a
>> in :o 'a
== a
>> same? (second first :o) (in :o 'a)
== false
so I wouldn't expect it to work for functions either.
At 01:23 PM 8/21/00 +0200, you wrote:
>The best sollution would be to enhance "in" so you can not only get words
>out of object's context, but also out of functions context.
<<quoted lines omitted: 6>>
>Good idea?
>Frank
;- Elan [ : - ) ]
author of REBOL: THE OFFICIAL GUIDE
REBOL Press: The Official Source for REBOL Books
http://www.REBOLpress.com
visit me at http://www.TechScribe.com
[4/5] from: fsievert:uos at: 22-Aug-2000 14:21
On Mon, 21 Aug 2000 [rebol--techscribe--com] wrote:
> BTW
> >same? first second :f in :f 'a
<<quoted lines omitted: 8>>
> == false
> so I wouldn't expect it to work for functions either.
second :f functions body. So I woulc expect, that same? would
return true. Equivalent to object would be:
>> o: make object! [sth: [a] a: 9]
>> same? first second second o bind 'a in o 'self
== true
CU,
Frank
[5/5] from: rebol:techscribe at: 22-Aug-2000 12:12
Hi Frank,
Aha, you wish to determine the equivalence of the BINDed word to the word
the same word IN the object's body. You then must know the index of the
local word you are comparing to in the object body i.e. your expression
first second second o
you wrote:
> >> o: make object! [sth: [a] a: 9]
> >> same? first second second o bind 'a in o 'self
> == true
The equivalent also works with my in-func:
>> f: cfunc [a] [a]
>> same? second second :f in-func :f 'a
== true
I trust that the in-func function I proposed in my previous email, together
with cfunc and get-context-block help solve your serialization problem? Or
is there something I have overlooked?
Take Care,
At 02:21 PM 8/22/00 +0200, you wrote:
>On Mon, 21 Aug 2000 [rebol--techscribe--com] wrote:
>> BTW
<<quoted lines omitted: 20>>
>CU,
>Frank
;- Elan [ : - ) ]
author of REBOL: THE OFFICIAL GUIDE
REBOL Press: The Official Source for REBOL Books
http://www.REBOLpress.com
visit me at http://www.TechScribe.com
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted