· Nov 7, 2022

Adding a class to IRIS namespace 'USER' using terminal


I want to know how to add a class to IRIS namespace 'USER' using terminal.

How do I do this?

I know you can add this class using Visual Studio Code with the Intersystems extension installed on my PC and connected to an IRIS instance.

Is it possible to do this with terminal? From this prompt:

I have a class like in this example:

Class ObjectScript.RightTriangle

/// Compute area and hypotenuse of a right triangle
ClassMethod Main()
    write !, "Compute the area and hypotenuse of a right triangle",
          !, "given the lengths of its two sides."
Product version: IRIS 2022.1
Discussion (4)1
Log in or sign up to continue

You can it enter via terminal, no question about, but it's a little bit cumbersome

// create the class
s cls=##class(%Dictionary.ClassDefinition).%New()
s cls.ProcedureBlock=1
s cls.Super="%RegisteredObject"
s cls.Name="ObjectScript.RightTriangle"

// add one method
s mth=##class(%Dictionary.MethodDefinition).%New()
s mth.Name="Main"
s mth.Description="Compute area and hypotenuse of a right triangle"
d mth.Implementation.WriteLine($c(9)_"write !,""Compute the area and hypotenuse of a right triangle"",")
d mth.Implementation.Write($c(9,9)_"!,""given the lengths of its two sides.""")
d cls.Methods.Insert(mth)

// add one more method
s mth=##class(%Dictionary.MethodDefinition).%New()
s mth.Name="Area",mth.Description="Area, computed from sides 'a' and 'b'"
s mth.FormalSpec="a,b"
d mth.Implementation.WriteLine($c(9)_"quit a*b/2")
d cls.Methods.Insert(mth)

// save the class (it's NOT compiled!)
w cls.%Save()

As you may see, creating a class via an IDE is simpler... but yes, in an emergency case you can do it also via a console access