Nov 17
Brad Lindsay Approximating Variables With Method Scope
Nov 17, 2012; 14:17
Brad Lindsay
Approximating Variables With Method Scope
So I thought I'd take a stab at creating something that would approximate creating variables a scope that is larger than a local yet shorter than a thread variable. Essentially I want a local variable that can't be accessed between methods but could be accessed from within an included file or an invoked capture. Below are the methods and the thread variable I'm using for my shenanigans.
<?var(_m_) = map
define m(key::string) => {
local(root) = currentCapture->continuation
while(#root->calledName == 'invoke') => {
#root = #root->continuation
}
try => {
// When not found in the map, I don't want a key not found error, but variable not found
handle(error_code == error_code_invalidParameter) => {
failure_clear
error_reset
fail(-9947, `The method variable "` + #key + `" was not found`)
}
return $_m_->get(#root->calledName)->get(#key)
}
}
define m=(rhs, key::string) => {
local(root) = currentCapture->continuation
while(#root->calledName == 'invoke') => {
#root = #root->continuation
}
protect => {
handle_error => {
$_m_->insert(#root->calledName=map(#key=#rhs))
}
$_m_->get(#root->calledName)->insert(#key=#rhs)
}
}
// [try] method developed by Bil Corey
define try => {
local(e) = pair(0='No error')
local(gb) = givenBlock
protect => {
handle_error => { #e = pair(error_code = error_msg) }
#gB()
}
#e->name != 0 ? fail(#e->name,#e->value)
}
?>
So the code above lets me write code like this:
<?define moosehair => {
m('foo') = 'fame'
}
m('foo') = 'bar'
moosehair
m('foo') // produces 'bar'
?>
I'm guessing that [capture->continuation] lets me walk back up the call chain of captures and methods. I'm also guessing that when [capture->calledName] isn't "invoke" then it's an explicitly defined method. The only flaw I can think of is that if you define 'invoke' as a member method to a type, then that member method would have access to those "variables" at the top (root?) level instead of just the ones defined inside itself. Are there any other pitfalls I'm not seeing? Any solutions to the flaw I mentioned?
Thanks,
Brad
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso
Lasso@lists.lassosoft.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>
Nov 18
Jolle Carlestam Re: Approximating Variables With Method Scope
Nov 18, 2012; 00:43
Jolle Carlestam
Re: Approximating Variables With Method Scope
Nov 17
Brad Lindsay Re: Approximating Variables With Method Scope
Nov 17, 2012; 23:38
Brad Lindsay
Re: Approximating Variables With Method Scope
Nov 18
Jolle Carlestam Re: Approximating Variables With Method Scope
Nov 18, 2012; 06:42
Jolle Carlestam
Re: Approximating Variables With Method Scope
Nov 18
Brad Lindsay Re: Approximating Variables With Method Scope
Nov 18, 2012; 16:04
Brad Lindsay
Re: Approximating Variables With Method Scope
Nov 18
Jolle Carlestam Re: Approximating Variables With Method Scope
Nov 18, 2012; 23:21
Jolle Carlestam
Re: Approximating Variables With Method Scope
Nov 19
Ke Carlton Re: Approximating Variables With Method Scope
Nov 19, 2012; 11:46
Ke Carlton
Re: Approximating Variables With Method Scope
Nov 19
Ke Carlton Re: Approximating Variables With Method Scope
Nov 19, 2012; 11:49
Ke Carlton
Re: Approximating Variables With Method Scope
Nov 19
Ke Carlton Re: Approximating Variables With Method Scope
Nov 19, 2012; 12:44
Ke Carlton
Re: Approximating Variables With Method Scope
Nov 19
Brad Lindsay Re: Approximating Variables With Method Scope
Nov 19, 2012; 10:54
Brad Lindsay
Re: Approximating Variables With Method Scope
Nov 19
Brad Lindsay Re: Approximating Variables With Method Scope
Nov 19, 2012; 10:54
Brad Lindsay
Re: Approximating Variables With Method Scope
Nov 20
Jolle Carlestam Re: Approximating Variables With Method Scope
Nov 20, 2012; 02:51
Jolle Carlestam
Re: Approximating Variables With Method Scope
Nov 19
Brad Lindsay Re: Approximating Variables With Method Scope
Nov 19, 2012; 22:02
Brad Lindsay
Re: Approximating Variables With Method Scope
Nov 20
Ke Carlton Re: Approximating Variables With Method Scope
Nov 20, 2012; 12:26
Ke Carlton
Re: Approximating Variables With Method Scope
Nov 22
Jolle Carlestam Re: Approximating Variables With Method Scope
Nov 22, 2012; 07:38
Jolle Carlestam
Re: Approximating Variables With Method Scope
Nov 22
Ke Carlton Re: Approximating Variables With Method Scope
Nov 22, 2012; 10:30
Ke Carlton
Re: Approximating Variables With Method Scope
Nov 22
Brad Lindsay Re: Approximating Variables With Method Scope
Nov 22, 2012; 09:32
Brad Lindsay
Re: Approximating Variables With Method Scope
Nov 22
Jolle Carlestam Re: Approximating Variables With Method Scope
Nov 22, 2012; 22:55
Jolle Carlestam
Re: Approximating Variables With Method Scope
Dec 02
Jolle Carlestam Re: Approximating Variables With Method Scope
Dec 02, 2012; 21:43
Jolle Carlestam
Re: Approximating Variables With Method Scope
Dec 03
Brad Lindsay Re: Approximating Variables With Method Scope
Dec 03, 2012; 16:52
Brad Lindsay
Re: Approximating Variables With Method Scope
Dec 07
Ke Carlton Re: Approximating Variables With Method Scope
Dec 07, 2012; 11:35
Ke Carlton
Re: Approximating Variables With Method Scope
Dec 07
Ke Carlton Re: Approximating Variables With Method Scope
Dec 07, 2012; 11:42
Ke Carlton
Re: Approximating Variables With Method Scope