### Configure and Run IRIS via Docker Source: https://context7.com/intersystems/samples-objectscript/llms.txt Commands for building, starting, and accessing the IRIS container environment. ```bash # Build and start IRIS container docker-compose build docker-compose up -d # Access IRIS terminal docker-compose exec iris iris session iris # Switch to SAMPLES namespace and run examples USER>zn "SAMPLES" SAMPLES>do ##class(ObjectScript.Examples).DoubleByVal(2) 4 SAMPLES>do ##class(ObjectScript.DataEntry4).Load() // Loads test data SAMPLES>do ##class(ObjectScript.Lookup2).Main() // Interactive lookup application ``` -------------------------------- ### Build and Run IRIS in Docker Source: https://github.com/intersystems/samples-objectscript/blob/master/README.md Builds and starts an InterSystems IRIS instance using Docker Compose. This command also imports all code into the SAMPLES namespace. ```bash # docker-compose build # docker-compose up -d ``` -------------------------------- ### Execute ObjectScript Method in IRIS Session Source: https://github.com/intersystems/samples-objectscript/blob/master/README.md Connects to an InterSystems IRIS session within a Docker container, changes to the SAMPLES namespace, and executes a method from the Examples class. ```bash # docker-compose exec iris iris session iris USER>zn "SAMPLES" SAMPLES>w ##class(ObjectScript.Examples).DoubleByVal(2) 4 ``` -------------------------------- ### Lookup Person Records by Phone Number or Area Code Source: https://context7.com/intersystems/samples-objectscript/llms.txt Looks up person records by phone number or area code. Demonstrates exact global node lookup with $get and partial matching using 3-argument $order for area code searches. Follow prompts to perform lookups. ```ObjectScript // Run the lookup application SAMPLES>do ##class(ObjectScript.Lookup2).Main() There are 4 records in the database. // Exact phone lookup Lookup: 111-111-1111 1) Jones,Cleon 111-111-1111 07/22/01 // Area code search Lookup: 617- ...finding area code matches 1) Agee,Tommie 617-333-3333 07/27/01 Choose by number: 1 ======================================== Name: Agee,Tommie Phone: 617-333-3333 DOB: 07/27/01 ======================================== ``` -------------------------------- ### Load Test Data for Tutorial Exercises Source: https://context7.com/intersystems/samples-objectscript/llms.txt Populates the database with test records for tutorial exercises. It clears existing data and creates sample Person records using both global storage and the Person persistent class. Confirm storage for each record when prompted. ```ObjectScript // Load test data for tutorial exercises SAMPLES>do ##class(ObjectScript.DataEntry4).Load() Store? (y/n): y ...stored 1 Store? (y/n): y ...stored 1 Store? (y/n): y ...stored 1 Store? (y/n): y ...stored 1 // Four test records loaded: // Jones,Cleon - 111-111-1111 - 07/22/1901 // Agee,Tommie - 617-333-3333 - 07/27/1901 // Swoboda,Ron - 222-222-2222 - 06/30/1903 // Jones,Bobby - 333-444-5555 - 01/26/1929 ``` -------------------------------- ### Demonstrate Output Parameter Source: https://context7.com/intersystems/samples-objectscript/llms.txt Uses the Output keyword to return a value by reference while keeping the input unchanged. This pattern allows returning multiple values from a method. ```objectscript // Output parameter pattern - input unchanged, result returned via Output parameter SAMPLES>set input = 8 SAMPLES>do ##class(ObjectScript.Examples).DoubleByRef2(input, .result) SAMPLES>write "Input: ", input, " Output: ", result Input: 8 Output: 16 ``` -------------------------------- ### Perform String Conversions and Transformations Source: https://context7.com/intersystems/samples-objectscript/llms.txt Demonstrates common string manipulation functions including character translation, substring replacement, case conversion, and whitespace stripping. ```objectscript // String conversion examples SAMPLES>do ##class(ObjectScript.Examples).Conversions() abcde becomes: ybcze abcde becomes: zbcze abcde becomes: zbce abcdebcbc becomes: yzdezz abcdebcbc becomes: yzdebcbc String to translate: hello world Using $translate: HELLO WORLD Using $zconvert: HELLO WORLD Using $zconvert for capitalizing words: Hello World Using $zstrip to remove whitespace: helloworld // Direct function usage SAMPLES>write $zconvert("john doe", "W") John Doe SAMPLES>write $translate("abc123def", "123", "XYZ") abcXYZdef ``` -------------------------------- ### Implement For Loop Patterns Source: https://context7.com/intersystems/samples-objectscript/llms.txt Illustrates various loop control patterns including numeric ranges, iterating over value lists, and infinite loops with conditional exits. ```objectscript // Various For loop patterns SAMPLES>do ##class(ObjectScript.Examples).For() // Numeric range: for i = 1:1:8 I 1 the sandbox. I 2 the sandbox. ... // Value list: for b = "John", "Paul", "George", "Ringo" Was John the leader? n Was Paul the leader? n Was George the leader? n Was Ringo the leader? y // Infinite loop with quit condition Capital of MA? SPRINGFIELD Capital of MA? BOSTON ...did it in 2 tries ``` -------------------------------- ### Manage Persistent Person Objects Source: https://context7.com/intersystems/samples-objectscript/llms.txt Demonstrates creating, saving, querying via SQL, and opening persistent objects in InterSystems IRIS. ```objectscript // Create and save a Person object SAMPLES>set person = ##class(ObjectScript.Person).%New() SAMPLES>set person.Name = "Williams,Ted" SAMPLES>set person.Phone = "617-999-8888" SAMPLES>set person.DOB = 40000 SAMPLES>set status = person.%Save() SAMPLES>write status 1 // Query using SQL SAMPLES>do $system.SQL.Shell() SQL> SELECT ID, Name, LastName, FirstName, Phone, DOB FROM ObjectScript.Person ID Name LastName FirstName Phone DOB 1 Jones,Cleon Jones Cleon 111-111-1111 37105 2 Agee,Tommie Agee Tommie 617-333-3333 37110 ... // Open existing object by ID SAMPLES>set person = ##class(ObjectScript.Person).%OpenId(1) SAMPLES>write person.Name Jones,Cleon SAMPLES>write person.LastName Jones // Property validation patterns: // Name: 1U.L1","1U.L (Last,First format) // Phone: 3n1"-"3n1"-"4n (###-###-#### format) ``` -------------------------------- ### Handle Exceptions Source: https://context7.com/intersystems/samples-objectscript/llms.txt Demonstrates ObjectScript exception handling using try-catch blocks. Shows handling of system exceptions (e.g., UNDEFINED, DIVIDE) and custom exceptions. ```objectscript // Handle exceptions - shows system and custom exception handling SAMPLES>do ##class(ObjectScript.Examples).Exceptions(3) Hello! Error name: Error code: 9 Error location: zExceptions+2^ObjectScript.Examples.1 Additional data: xyz Error name: Error code: 18 Error location: zExceptions+8^ObjectScript.Examples.1 Additional data: Hello! Finished! // Custom exception is thrown when x >= 5 SAMPLES>do ##class(ObjectScript.Examples).Exceptions(5) // ... shows Demo Exception with code 100000 ``` -------------------------------- ### Demonstrate Pass by Reference Source: https://context7.com/intersystems/samples-objectscript/llms.txt Passes an argument by reference using the ByRef keyword. The original variable is modified directly within the method, demonstrating in-place modification. ```objectscript // Pass by reference - original variable is modified SAMPLES>set num = 7 SAMPLES>do ##class(ObjectScript.Examples).DoubleByRef1(.num) SAMPLES>write "Doubled: ", num Doubled: 14 ``` -------------------------------- ### Generate Fibonacci Sequences Source: https://context7.com/intersystems/samples-objectscript/llms.txt Shows implementation of Fibonacci sequence generation using both Do-While and While loop constructs. ```objectscript // Generate Fibonacci sequence SAMPLES>do ##class(ObjectScript.Examples).Fibonacci() Generate Fibonacci sequence up to where? 100 1 1 2 3 5 8 13 21 34 55 89 1 1 2 3 5 8 13 21 34 55 89 ``` -------------------------------- ### Store Person Record with Global Indexing Source: https://context7.com/intersystems/samples-objectscript/llms.txt Stores a person record using globals with transaction support. It stores the record in ^PersonD and maintains indexes in ^PersonI for name, phone, and DOB lookups, plus a bitmap index for record counting. Confirm storage when prompted. ```ObjectScript // Store a person record with full indexing SAMPLES>set answers = $listbuild("Doe,Jane","555-123-4567",54432) SAMPLES>do ##class(ObjectScript.DataEntry4).Store(answers) Store? (y/n): y ...stored // Data is stored in globals: // ^PersonD(id) = $listbuild(name, phone, intdob) // ^PersonI("Name", last, first, id) = "" // ^PersonI("Phone", phone) = id // ^PersonI("DOB", intdob, id) = "" // ^PersonI("Bitmap-ID", chunk) = bitmap of IDs // Verify storage SAMPLES>zwrite ^PersonD ^PersonD=5 ^PersonD(1)=$lb("Jones,Cleon","111-111-1111",37105) ^PersonD(2)=$lb("Agee,Tommie","617-333-3333",37110) ... ``` -------------------------------- ### Iterate Through Global Subscripts with $order Source: https://context7.com/intersystems/samples-objectscript/llms.txt Demonstrates iterating through global subscripts using $order. It shows two equivalent patterns: argumentless For with an explicit quit condition, and a While loop with pre-fetch. $order returns the next subscript in collation order and returns "" when no more subscripts exist. ```ObjectScript // Loop through ^PersonI("Name") index using $order SAMPLES>do ##class(ObjectScript.Examples).SimpleLoop() Using argumentless For Agee Jones Swoboda Using While Agee Jones Swoboda // $order returns the next subscript in collation order // Returns "" when no more subscripts exist SAMPLES>write $order(^PersonI("Name", "")) Agee SAMPLES>write $order(^PersonI("Name", "Agee")) Jones ``` -------------------------------- ### Demonstrate Pass by Value Source: https://context7.com/intersystems/samples-objectscript/llms.txt Passes an argument by value to a method that doubles it. The original variable remains unchanged after the method call. ```objectscript // Pass by value - returns doubled result, original unchanged SAMPLES>set num = 5 SAMPLES>set result = ##class(ObjectScript.Examples).DoubleByVal(num) SAMPLES>write "Original: ", num, " Result: ", result Original: 5 Result: 10 ``` -------------------------------- ### Manipulate JSON Objects and Arrays in ObjectScript Source: https://context7.com/intersystems/samples-objectscript/llms.txt Demonstrates creating JSON objects with literal syntax, modifying properties, iterating through arrays, and parsing JSON strings into dynamic objects. ```objectscript // Working with JSON objects and arrays SAMPLES>do ##class(ObjectScript.Examples).JSON() First JSON object: {"PartNum":"678LM","Price":"7.99","Quantity":"100","Sizes":["Tiny","Large"]} Second JSON Object: Part Number: 345JK Price: 5.99 Quantity: 50 Sizes Key: 0, Size: Small Key: 1, Size: Medium Key: 2, Size: Large Changed Second JSON Object: {"PartNum":"345JK","Price":"8.99","Sizes":["Small","Medium","Large","Extra Large"],"Quantity":75} // Create JSON programmatically SAMPLES>set obj = {"name":"John", "age":30} SAMPLES>set obj.city = "Boston" SAMPLES>write obj.%ToJSON() {"name":"John","age":30,"city":"Boston"} // Parse JSON from string SAMPLES>set str = "{""product"":""Widget"",""price"":9.99}" SAMPLES>set parsed = ##class(%DynamicObject).%FromJSON(str) SAMPLES>write parsed.product, " costs $", parsed.price Widget costs $9.99 ``` -------------------------------- ### Run Right Triangle Calculator Source: https://context7.com/intersystems/samples-objectscript/llms.txt Executes the interactive right triangle calculator program in the IRIS terminal. Demonstrates user input, conditional logic, loops, and private method calls. ```objectscript // Run the right triangle calculator in IRIS terminal SAMPLES>do ##class(ObjectScript.RightTriangle).Main() // Sample interaction: // Compute the area and hypotenuse of a right triangle // given the lengths of its two sides. // // First, choose a unit of measurement: // 1) inches // 2) feet // 3) miles // 4) centimeters // 5) meters // 6) kilometers // // Option? 2 // // Length of side 1: 3 // Accepted. // // Length of side 2: 4 // Accepted. // // The area of this triangle is 6.00 square feet. // The hypotenuse is 5.00 feet. ``` -------------------------------- ### Traverse Multi-Level Name Index with Nested $order Source: https://context7.com/intersystems/samples-objectscript/llms.txt Traverses a multi-level global index (^PersonI("Name", lastName, firstName, id)) to display all records sorted by name. Nested $order calls are used to traverse each level of the index. ```ObjectScript // Traverse multi-level name index SAMPLES>do ##class(ObjectScript.Examples).NameLoop() Agee,Tommie 617-333-3333 07/27/01 Jones,Bobby 333-444-5555 01/26/29 Jones,Cleon 111-111-1111 07/22/01 Swoboda,Ron 222-222-2222 06/30/03 // The index structure: // ^PersonI("Name", "Jones", "Bobby", 4) = "" // ^PersonI("Name", "Jones", "Cleon", 1) = "" // Nested $order calls traverse each level ``` -------------------------------- ### Perform Name Searches in ObjectScript Source: https://context7.com/intersystems/samples-objectscript/llms.txt Use the Name method for flexible searches by full name, last name, or partial name patterns. Supports nested $order loops with prefix matching via $extract. ```ObjectScript // Name search patterns SAMPLES>do ##class(ObjectScript.Lookup2).Main() // Full name search Lookup: Jones,Cleon ...finding name matches 1) Jones,Cleon 111-111-1111 07/22/01 // Last name only Lookup: Jones ...finding name matches 1) Jones,Bobby 333-444-5555 01/26/29 2) Jones,Cleon 111-111-1111 07/22/01 // Partial name (prefix matching) Lookup: Jo,C ...finding name matches 1) Jones,Cleon 111-111-1111 07/22/01 // Partial last name Lookup: Sw ...finding name matches 1) Swoboda,Ron 222-222-2222 06/30/03 ``` -------------------------------- ### Validate Name Formats with Pattern Matching Source: https://context7.com/intersystems/samples-objectscript/llms.txt Uses the pattern match operator (?) to enforce a specific 'Last,First' string format with character class codes. ```objectscript // Validate name format using pattern matching SAMPLES>write ##class(ObjectScript.DataEntry3).ValidName("Smith,John") 1 SAMPLES>write ##class(ObjectScript.DataEntry3).ValidName("john smith") Last,First 0 SAMPLES>write ##class(ObjectScript.DataEntry3).ValidName("SMITH,JOHN") Last,First 0 // Pattern explanation: 1U.L1","1U.L // 1U = exactly one uppercase letter // .L = zero or more lowercase letters // 1"," = exactly one comma // 1U.L = one uppercase followed by lowercase letters ``` -------------------------------- ### Validate Date of Birth with $zdateh and $horolog Source: https://context7.com/intersystems/samples-objectscript/llms.txt Validates dates of birth using $zdateh for parsing and $horolog for comparison against the current date. Returns the internal date format for database storage. Ensure the date is a valid past date. ```ObjectScript // Validate date of birth - must be valid past date SAMPLES>do ##class(ObjectScript.DataEntry3).ValidDOB("01/15/1990", .intdate) SAMPLES>write intdate 54432 SAMPLES>write ##class(ObjectScript.DataEntry3).ValidDOB("12/31/2099", .intdate) Must be a valid past date 0 SAMPLES>write ##class(ObjectScript.ValidDOB).ValidDOB("not a date", .intdate) Must be a valid past date 0 ``` ```ObjectScript // Convert internal date back to display format SAMPLES>write $zdate(54432, 2) 01/15/1990 ``` -------------------------------- ### Validate Positive Number Input Source: https://context7.com/intersystems/samples-objectscript/llms.txt Checks if a given number is positive. Returns 1 if the number is negative or zero, and 0 if it is positive. Demonstrates boolean return values and simple conditional logic. ```objectscript // Check if a number is negative or zero SAMPLES>write ##class(ObjectScript.RightTriangle).IsNegative(-5) Enter a positive number.1 SAMPLES>write ##class(ObjectScript.RightTriangle).IsNegative(10) Accepted.0 ``` -------------------------------- ### Lookup Persons by Date of Birth in ObjectScript Source: https://context7.com/intersystems/samples-objectscript/llms.txt The DOB method finds persons by a specific date of birth. It validates the input date and iterates through matching IDs in the DOB index. ```ObjectScript // Date of birth lookup SAMPLES>do ##class(ObjectScript.Lookup2).Main() Lookup: 07/22/1901 ...finding birthday matches 1) Jones,Cleon 111-111-1111 07/22/01 Choose by number: 1 ======================================== Name: Jones,Cleon Phone: 111-111-1111 DOB: 07/22/01 ======================================== ``` -------------------------------- ### Count Records Using Bitmap Index in ObjectScript Source: https://context7.com/intersystems/samples-objectscript/llms.txt The CurrentCount method efficiently counts total records using a bitmap index and $bitcount. This method avoids traversing all data by counting set bits across bitmap chunks. ```ObjectScript // Count records using bitmap index SAMPLES>do ##class(ObjectScript.Lookup2).CurrentCount() There are 4 records in the database. // Bitmap index structure: // ^PersonI("Bitmap-ID", chunk) contains a bitstring // Each bit position represents an ID // $bitcount(bits, 1) counts the "1" bits // Direct bitmap examination SAMPLES>set chunk = 1 SAMPLES>set bits = ^PersonI("Bitmap-ID", chunk) SAMPLES>write $bitcount(bits, 1) 4 ``` -------------------------------- ### Validate and Normalize Phone Numbers Source: https://context7.com/intersystems/samples-objectscript/llms.txt Uses regular expressions with $match to validate phone number formats and automatically inject a default area code if missing. ```objectscript // Validate and normalize phone numbers using regex SAMPLES>set phone = "555-1234" SAMPLES>write ##class(ObjectScript.DataEntry3).ValidPhone(.phone), " => ", phone 1 => 617-555-1234 SAMPLES>set phone = "800-555-1234" SAMPLES>write ##class(ObjectScript.DataEntry3).ValidPhone(.phone), " => ", phone 1 => 800-555-1234 SAMPLES>set phone = "invalid" SAMPLES>write ##class(ObjectScript.DataEntry3).ValidPhone(.phone) ###-###-#### or ###-#### 0 // Pattern: (\d{3}-)?\d{3}-\d{4} // Optional area code followed by 7-digit number ``` -------------------------------- ### Delete Record with Index Cleanup in ObjectScript Source: https://context7.com/intersystems/samples-objectscript/llms.txt The Delete method removes a person record, ensuring proper locking and transaction support. It deletes data and index entries within a transaction and updates the bitmap index. ```ObjectScript // Delete a record with full index cleanup SAMPLES>do ##class(ObjectScript.Lookup3).Main() There are 4 records in the database. Lookup: Swoboda ...finding name matches 1) Swoboda,Ron 222-222-2222 06/30/03 Choose by number: 1 ======================================== Name: Swoboda,Ron Phone: 222-222-2222 DOB: 06/30/03 ======================================== Delete? (y/n): y ...deleted // Lock prevents concurrent modification: // lock +^PersonD(id):5 - acquire with 5 second timeout // tstart / tcommit - wrap changes in transaction // lock -^PersonD(id) - release lock ``` -------------------------------- ### Edit Record with Selective Index Updates in ObjectScript Source: https://context7.com/intersystems/samples-objectscript/llms.txt The Edit method updates an existing person record, acquiring a lock and using transactions. It selectively updates only modified index entries to maintain data integrity. ```ObjectScript // Edit a record with selective index updates SAMPLES>do ##class(ObjectScript.Lookup3).Main() Lookup: Jones,Bobby ...finding name matches 1) Jones,Bobby 333-444-5555 01/26/29 Choose by number: 1 ======================================== Name: Jones,Bobby Phone: 333-444-5555 DOB: 01/26/29 ======================================== Delete? (y/n): n Edit? (y/n): y Name: Jones,Bobby => Jones,Robert Phone: 333-444-5555 => (617): DOB: 01/26/29=> Store updates? (y/n): y ...updated. // Only changed indexes are updated: // if (newname '= currentname) - update Name index // if (newphone '= currentphone) - update Phone index // if (newintdob '= currentintdob) - update DOB index ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.