1

I'm looking to create an application using the Callin API provided by InterSystems, but some of existing M code I need to use relies on assumed variables.

How can I provide such state to the tags I call?

(Note that if I add the variable as a formal parameter, it will get new'd and other tags will stop working.)


I'd like to create a system whereby I can insert code in another language potentially 'sandwiched' by M code:

s assumed="variable"
s x=$$DoSomethingFunky("FunctionName","arg1","arg2","arg3")

 

; some other file that's being executed by my Callin API program
FunctionName(a1, a2, a3) -> ", ".join(a1, a2, a3, assumed, DoSomethingFunkier(a2))

 

; back to M
DoSomethingFunkier(param1) q "(hello, "_param1_" and "_assumed_")"

So x above would be "arg1, arg2, arg3, variable, (hello, arg2 and variable)".
I'm looking for a way to pass around the value of the assumed variable.

Sean Allred
  • 3,558
  • 3
  • 32
  • 71

1 Answers1

1

It's difficult to tell exactly what you are trying to do. If you had an example that would help very much.

In an absolute emergency to code something in mumps and get a variable you could do something like this: (it is very archaic, but will work)

LineLabel:

s myVar = ^some("global","reference")
d $zf(-1,"echo "_myVar_"> c:\myvar.txt")
q

And then go grab the variable from that text file from c# or whatever language you're using.

Again, the shell out (call back) function ($zf,-1) is archaic and probably costly in terms of performance, but that can be addressed in version 2.0.

Caché uses the term ByRef or By Reference to access variables from a particular job. That may help with research. Good Luck!

Chris G
  • 787
  • 6
  • 20
Mike M
  • 21
  • 2
  • I added an example. I should note that I'm not using ObjectScript in any capacity. – Sean Allred Jan 30 '16 at 16:14
  • Still, I am not sure what DoSomethingFunky looks like. It should be subroutine in the same routine that has the line "s x=$$DoSomethingFunky()" In contrast, DoSomethingFunkier looks like it will be used as a subroutine, not a function. This means the quit value following it will do absolutely nothing upon quitting. Your code looks like it is going to this: d DoSomethingFunkier(a2) DoSomethingFunkier(param1) q You may want to do something like this instead: d DoSomethingFunkier(a2,.as1) DoSomethingFunkier(param1,assumed) s assumed = "Something" this will set .as1 to assumed By Reference – Mike M Feb 02 '16 at 19:43
  • I'm well aware of passing variables by reference :-) In full disclosure, I'm creating a compiled extension to the M language to support programs written in another language -- one that neither has nor needs a concept of pass-by-reference. (In retrospect, it makes more sense to refer to `DoSomethingFunky` as an *intrinsic* function like `$o`.) The fact of the matter is, I still can't access the value of `as1` in the foreign language. That's the crux of the question. – Sean Allred Feb 02 '16 at 19:53
  • Sean, why not send in assumed as a 4th parameter? Then just pass that variable into dosomethingfunkier as a 2nd parameter. Alternatively, you can just use a different variable in the function so assumed won't get re-declared. – Mike M Apr 06 '16 at 16:42
  • Mike, I can't guarantee I can do that. The existing codebase needs to work as-is; my application layer needs to work on top of it. – Sean Allred Apr 06 '16 at 16:49