Re: string_exec()

new topic     » goto parent     » topic index » view thread      » older message » newer message
dcuny said...

I'd assume that there string code would be running in it's own context.

That certainly makes life easier, but I suspect the requirement to obtain/set stuff in the host will turn up soon enough.

dcuny said...

It would be nice if there were a way to pass values to that context, such as:

-- compile code into a context 
{aContext, resultCode} = compile_code("myfile.ex") 
 
-- set top-level value for variable "some_string" to "a_value" 
{aContext, resultCode} = set_value(aContext, "some_string", "a value") 
 
-- execute procedure in context 
{aContext, resultCode} = call_routine(aContext, "some_procedure", {1,2,3}) 
 
-- execute function in context 
{aContext, returnValue, resultCode} = call_routine(aContext, "some_function", {1,2,3}) 
 
-- create an empty context that code can be compiled to 
sequence newContext = create_context() 
 
-- compile code into the context 
{newContext, resultCode} = compile(newContext, "integer a\na=22") 
 
-- retrieve top-level "a" value from the context 
{result, resultCode} = get_value(newContext, "a") 

I was thinking that set_value and get_value might not be as powerful and flexible as simple assignments/return expressions. How about this, to achieve the same result:

ctrl = string_exec(NULL,"include myfile.ex\n"& 
                        "some_string = \"a_value\"\n"& 
                        "some_procedure(1,2,3)\n"& 
                        "return some_function(1,2,3)") 
returnValue = ctrl[RESULT] 
 
newContext = string_exec(NULL,"integer a\na=22\nreturn a") 
result = newContext[RESULT] 

or, also equally:

ctrl = string_exec(NULL,"include myfile.ex") 
ctrl = string_exec(ctrl,"some_string = \"a_value\"") 
ctrl = string_exec(ctrl,"some_procedure(1,2,3)") 
{context,returnValue,errors} = string_exec(ctrl,"return some_function(1,2,3)") 
 
newContext = string_exec(NULL,"integer a") 
newContext = string_exec(newContext,"a=22") 
{newContext,result,errors} = string_exec(newContext,"return a") 


dcuny said...

I'd also assume that if there was an error while executing something in the context, there would be routines for retrieving that information.

Sure. I've no problem with or real preference for either ctrl = string_exec() and retrieving by index, or {context,value,error} = string_exec() at this stage1.
It also strikes me that a simple (integer) error is unlikely to be sufficient, instead {code snippet,line/col,human-readable message,...}, not unlike what we get in an ex.err.
Oh, yes, I see what you were asking now, the context/ctrl is it - everything you could ever possibly need must be available somewhere within it. Details tba.

Pete

1 Random petty detail: by defining context[1] to be a specific integer, say #0C057347, string_exec() could easily cope with getting context or {context,value,error} passed back to it. In other words, in a loop, both ctrl=string_exec(ctrl,s) and {context,value,error}=string_exec(context,s) would be fine. Right now the latter looks better, but needing to throw these things about might tip things in favour of the former.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu