Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: How to bind 'self in parse rules ?
Pages: [1] Print
Author Topic: How to bind 'self in parse rules ?  (Read 306 times)
newbie
Guest


Email
How to bind 'self in parse rules ?
« on: September 13, 2005, 03:12:27 AM »

I have an object with a parse rule, and I want to access self/property of that object withing the rule.

Without binding I have this message
** Script Error: self word has no context

So how to bind self within the context of parse rule ?
Logged
Guest
Guest


Email
How to bind 'self in parse rules ?
« Reply #1 on: September 13, 2005, 04:04:23 AM »

forgot to mention that's I used compose/deep that's why I have a problem:

obj: make object! [
PROPERTY: TRUE
code: to-block "(self/property: false)"
rules: Compose/deep ["do something" (code)]
probe rules
test: "do something"
parse test rules
]

In console this gives
>> obj: make object! [
[        PROPERTY: TRUE
[        rules: Compose/deep ["do something" (to-block "(bind self 'self self/property: false)")]
[        probe rules
[        test: "do something"
[        parse test rules
[    ]
["do something" (bind self 'self self/property: false)]
** Script Error: bind word has no context
** Near: bind self 'self self/property: false
Logged
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
How to bind 'self in parse rules ?
« Reply #2 on: September 13, 2005, 09:17:38 AM »

Your problem is not COMPOSE/DEEP, your problem is TO-BLOCK. Do you really need that?
Logged
Guest
Guest


Email
How to bind 'self in parse rules ?
« Reply #3 on: September 13, 2005, 04:35:06 PM »

>Your problem is not COMPOSE/DEEP, your problem is TO-BLOCK. Do you really need that?
In case do-something is generated dynamically Smiley
In the case of constant code have found this which works (I don't know if it's the most elegant way though):
o: make object! [
property: false
set-property: func [b [block!]][do compose [(B)]]
do-something: [(do bind [set-property [self/property: true]] 'self)]
rules: compose/deep ["do something" (do-something)]
probe rules
test: "do something"
parse test rules
]

>> o: make object! [
[    property: false
[    set-property: func [b [block!]][do compose [(B)]]
[    do-something: [(do bind [set-property [self/property: true]] 'self)]
[    rules: compose/deep ["do something" (do-something)]
[    probe rules
[    test: "do something"
[    parse test rules
[    ]
["do something" (do bind [set-property [self/property: true]] 'self)]
>> o/property
== true
 
Logged
Guest
Guest


Email
How to bind 'self in parse rules ?
« Reply #4 on: September 13, 2005, 04:37:14 PM »

In the case the code is dynamically generated I can't find a solution as this doesn't work:
o: make object! [
property: false
set-property: func [b [block!]][do compose [(B)]]
do-something: [(do bind [set-property [self/property: true]] 'self)]
rules: compose/deep ["do something" (to-block "(do bind [set-property [self/property: true]] 'self)")]
probe rules
test: "do something"
parse test rules
]

>> o: make object! [
[    property: false
[    set-property: func [b [block!]][do compose [(B)]]
[    do-something: [(do bind [set-property [self/property: true]] 'self)]
[    rules: compose/deep ["do something" (to-block "(do bind [set-property [self/property: true]] 'self)")]
[    probe rules
[    test: "do something"
[    parse test rules
[    ]
["do something" (do bind [set-property [self/property: true]] 'self)]
** Script Error: do word has no context
** Near: do bind [set-property [self/property: true]] 'self
>>
 
Logged
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
How to bind 'self in parse rules ?
« Reply #5 on: September 14, 2005, 07:03:28 AM »

You don't need to use strings to dynamically generate code. Smiley Use blocks directly.

Code:
>> b: []
== []
>> insert b 'print
== []
>> insert tail b "Hello"
== []
>> do b
Hello

Anyway, if you really need to use strings, use LOAD instead of TO-BLOCK, since the latter does not bind words to the global context, and does not add new words to the global context. You still have to use BIND to bind words to other contexts though.
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: How to bind 'self in parse rules ?
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 03, 2008, 09:35:13 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2315 Posts in 597 Topics by 4204 Members
Latest Member: hledamka.com

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc