Introspection in RevTalk
Moderator: Klaus
Introspection in RevTalk
I'd like to be able to "introspect" a script through the language. Not unlike the ability to read properties, I'd like to be able to "get the handlers of me", "get the functions of me.", "get line 3 of handler mouseUp of me", get the localVars of me, and so forth...
This would open the language for very interesting meta-programming. I know I can do all kinds of parsing on a script text, but for various reasons, that is quite suboptimal.
/Carl
This would open the language for very interesting meta-programming. I know I can do all kinds of parsing on a script text, but for various reasons, that is quite suboptimal.
/Carl
Re: Introspection in RevTalk
I'd be interested in those reasons. Parsing a script is not that different then parsing any other text container, and although adding the things you ask for could be done in the engine, making them yourself is trivial. I'm not against your proposal, I just don't see any huge need for it?
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Re: Introspection in RevTalk
Here's a way to get all fuction and command names. I guess this isn't what you want, but currently there is not other possibility.
This script is rather old and you may need to change something to make it work correctly.
Best,
Mark
Code: Select all
getProp handlerNames
put the script of the target into myScript
repeat for each line myLine in myScript
if word 1 of myLine is "private" then
if word 2 of myLine is among the items of "on,command" then
put word 3 of myLine && "command" & cr after myList
else if word 2 of myLine is "function" then
put word 3 of myLine && "function" & cr after myList
else if word 2 of myLine is among the items of "getProp,setProp" then
put word 3 of myLinew & "property" & cr after myList
end if
else if word 1 of myLine is "on" then
put word 2 of myLine && "command" & cr after myList
else if word 1 of myLine is "function" then
put word 2 of myLine && "function" & cr after myList
else if word 1 of myLine is among the items of "getProp,setProp" then
put word 2 of myLine && "property" & cr after myList
end if
end repeat
delete last char of myList
sort lines of myList
return myList
end handlerNames
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Introspection in RevTalk
Bvg, this is not about parsing text.
>>I'd be interested in those reasons.
Sure.
Some of the problems that RunRev “behaviors” solve are good reasons, but introspection (reflection) is a step or two beyond behaviors. It's about giving objects the ability to examine, modify and replicate themselves, depending on a particular execution path and condition --sometimes without changing the original code after it executes.
There are many applications for this feature in the areas of AI, education, software engineering, business, and scientific research. To name a few, you can write specialized, self learning IDEs, build language translators and enhancements, apply business rules, record and replay user's interaction with the software, validation, performance analysis, inject constructors/initializers, support UNDO/REDO, logging, persistence and security. There are also more mundane needs such as fixing bugs, writing patches and utilities after deployment...
Many scripting languages such VB, Ruby, Groovy and even lower-level languages like Java already support this feature for good reason. Revolution has to already have these structures in C++ and might only be a matter of exposing them into Revtalk.
>>I'd be interested in those reasons.
Sure.
Some of the problems that RunRev “behaviors” solve are good reasons, but introspection (reflection) is a step or two beyond behaviors. It's about giving objects the ability to examine, modify and replicate themselves, depending on a particular execution path and condition --sometimes without changing the original code after it executes.
There are many applications for this feature in the areas of AI, education, software engineering, business, and scientific research. To name a few, you can write specialized, self learning IDEs, build language translators and enhancements, apply business rules, record and replay user's interaction with the software, validation, performance analysis, inject constructors/initializers, support UNDO/REDO, logging, persistence and security. There are also more mundane needs such as fixing bugs, writing patches and utilities after deployment...
Many scripting languages such VB, Ruby, Groovy and even lower-level languages like Java already support this feature for good reason. Revolution has to already have these structures in C++ and might only be a matter of exposing them into Revtalk.
Last edited by ooper on Sun Mar 14, 2010 9:15 am, edited 1 time in total.
Re: Introspection in RevTalk
Ooper,
In standalones, you can't change scripts on the fly, if they are longer than 10 lines. I guess RunRev is not for you.
Best,
Mark
In standalones, you can't change scripts on the fly, if they are longer than 10 lines. I guess RunRev is not for you.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Introspection in RevTalk
The limitation Mark refers to is the scriptLimits (see the RevTalk dictionary), but those apply only at runtime while Ooper's post refers to "self-learning IDEs". In the development engine there are no scriptLimits, so I would imagine that with a relatively small library of handlers such as the one Mark posted you could get what you want.
I'd be interested to see what you come up with. There's a lot of room for innovation in IDE design.
I'd be interested to see what you come up with. There's a lot of room for innovation in IDE design.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Introspection in RevTalk
I use introspection in rev quite a bit, but it's all homegrown through uRIP extensions as per the revInterop group specifications. I use it to do things like:
put the uRIP["Triggers"] of control x into tTriggers
if "sqlExecute" is among the lines of tTriggers then
dispatch "sqlExecute" to control x with tParameters
end if
As Richard said, there's a lot of room for innovation in rev. I don't see the advantage of having this set in stone in the engine when it's so easy to craft your own way. And you have more flexibility this way as well.
put the uRIP["Triggers"] of control x into tTriggers
if "sqlExecute" is among the lines of tTriggers then
dispatch "sqlExecute" to control x with tParameters
end if
As Richard said, there's a lot of room for innovation in rev. I don't see the advantage of having this set in stone in the engine when it's so easy to craft your own way. And you have more flexibility this way as well.
Re: Introspection in RevTalk
Thanks guys,
I have already shared the reasons why introspection (exposing and rewriting script elements as objects) is useful, and one that may not be difficult to expose to the language. I think it will help make RevTalk much more competitive, which is good for all of us. I appreciate the info on the state of today's RunRev, but I wasn't looking for a parsing solution --though I truly appreciate the good intentions. I was only throwing in my two-cents to a "feature request", which is what this forum is about.
Mark, I loved HyperCard and I'm digging RunRev thus far; it's gonna take a hell of of a lot more than a missing feature to say it isn't for me
Thanks and regards.
/Carl
I have already shared the reasons why introspection (exposing and rewriting script elements as objects) is useful, and one that may not be difficult to expose to the language. I think it will help make RevTalk much more competitive, which is good for all of us. I appreciate the info on the state of today's RunRev, but I wasn't looking for a parsing solution --though I truly appreciate the good intentions. I was only throwing in my two-cents to a "feature request", which is what this forum is about.
Mark, I loved HyperCard and I'm digging RunRev thus far; it's gonna take a hell of of a lot more than a missing feature to say it isn't for me

Thanks and regards.
/Carl
Re: Introspection in RevTalk
Indeed it is, and I'm glad someone besides me is interested in introspection. But what you originally asked for ("get the handlers of me", etc.) is easy to do with a simple frontscript. Is there something that you see needing to be grafted onto the rev engine?ooper wrote:I was only throwing in my two-cents to a "feature request", which is what this forum is about.
"Script elements as objects", OTOH, is something that we've sorely been needing. I'd love, for example, to create a linked-list script object and subclass it rather than having to code non-OOP workarounds for it.
Re: Introspection in RevTalk
Hi Mark,
Yes, I can see now that my original script examples came short of explaining introspection, but I'm glad we agree that there is such a need.
Best of weekends!
/Carl
Yes, I can see now that my original script examples came short of explaining introspection, but I'm glad we agree that there is such a need.
Best of weekends!
/Carl
-
- Livecode Opensource Backer
- Posts: 10082
- Joined: Fri Feb 19, 2010 10:17 am
Re: Introspection in RevTalk
I don't think this is very complicated:
on mouseUp
replace "EE" with "A" in fld "THIRD"
put the script of me into fld "OUTPUT"
end mouseUp
does the script and then dumps it in fld "OUTPUT"
on mouseUp
replace "EE" with "A" in fld "THIRD"
put the line 2 of the script of me into fld "OUTPUT"
end mouseUp
does the script and then dumps line 2 of it in fld "OUTPUT"
So what is all the stuff about a feature request when the whole thing can be done already?
on mouseUp
replace "EE" with "A" in fld "THIRD"
put the script of me into fld "OUTPUT"
end mouseUp
does the script and then dumps it in fld "OUTPUT"
on mouseUp
replace "EE" with "A" in fld "THIRD"
put the line 2 of the script of me into fld "OUTPUT"
end mouseUp
does the script and then dumps line 2 of it in fld "OUTPUT"
So what is all the stuff about a feature request when the whole thing can be done already?
Re: Introspection in RevTalk
Try that in a standalone with a big script, for example liburl 

Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
- Livecode Opensource Backer
- Posts: 10082
- Joined: Fri Feb 19, 2010 10:17 am
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Introspection in RevTalk
I can see a lot of benefit to manipulating scripts in the IDE, but what's the advantage of doing that at runtime?
Even genetic algorithms are often implemented in compile languages like C, so dynamic behaviors are not hard to do without modifying scripts (and often a lot less work to debug).
Even genetic algorithms are often implemented in compile languages like C, so dynamic behaviors are not hard to do without modifying scripts (and often a lot less work to debug).
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn