### Starting Forthic Example Server (Shell/PowerShell) Source: https://github.com/linkedin/forthic/blob/main/README.md Commands to set up and run the example Flask server with embedded Forthic interpreters. This process creates a Python virtual environment, installs Forthic into it, and starts the web server on http://localhost:8000. ```Shell # On Mac and Linux make ``` ```PowerShell # On Windows .\make-install.ps1 .\make-server.ps1 ``` -------------------------------- ### Basic Usage Example with JavaScript Source: https://github.com/linkedin/forthic/blob/main/forthic-ts/README.md Demonstrates how to create an Interpreter instance, run a Forthic command, retrieve the result from the stack, and print it. Requires the @forthic/interp package to be installed. ```JavaScript import { Interpreter } from "@forthic/interp" (async () => { const interp = new Interpreter(); await interp.run("[1 2 3] '3 *' MAP"); const result = interp.stack_pop(); console.log("Howdy!", {result}); })(); ``` -------------------------------- ### Illustrating Nested Module Structure in Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Provides an example of nested modules to show how a module stack is created, influencing the order in which words are searched during execution. ```Forthic {first {second {third # At this point, the current module is `third` # The next module in the module stack is `second` # The final module in the module stack is `first` } } } ``` -------------------------------- ### Example: Storing and Retrieving Data with Forthic Cache Source: https://github.com/linkedin/forthic/blob/main/docs/modules/cache_module.md This example demonstrates the basic workflow of the Forthic cache module. It shows how to load the module, configure the cache directory, store a data structure (an array) under a specific key, and then retrieve that data using the same key. ```Forthic ["cache"] USE-MODULES "~/my_stuff" cache.CWD! # Sets the current working directory [1 2 3 "Howdy"] "my_array" cache.CACHE! # Stores the array in the cache "my_array" cache.CACHE@ # Retrieves the array from cache 3 NTH # ([1 2 3 "Howdy"] -- "Howdy") ``` -------------------------------- ### Example Usage of Excel Module in Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/modules/excel_module.md Demonstrates basic interactions with the excel module in Forthic. It shows how to use `USE-MODULES`, store workbook information from a URL using `WORKBOOK-INFO`, retrieve sheet names using `SHEET-NAMES`, get table names using `TABLE-NAMES`, and fetch table records using `TABLE-RECORDS`. Requires a `CredsContext` to be pushed onto the stack using `excel.PUSH-CONTEXT!`. ```Forthic ["excel"] USE-MODULES # NOTE: You must create an Excel `CredsContext` and apply it using PUSH-CONTEXT! # This stores the workbook info from a specified Excel URL ["workbook_info"] VARIABLES "https://link-to-excel-workbook" excel.WORKBOOK-INFO workbook_info ! # This returns an array of sheet names in the workbook workbook_info @ excel.SHEET-NAMES # This returns an array of table names from the `mytab` tab workbook_info @ "mytab" excel.TABLE-NAMES # This returns an array of records from `Table 1` of the `mytab` tab workbook_info @ "mytab" "Table 1" excel.TABLE-RECORDS ``` -------------------------------- ### Defining a New Word in Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Explains how to create a new word (definition) in Forthic using the `:` (start definition) and `;` (end definition) tokens, combining existing words. ```Forthic : DOUBLE 2 * ; ``` -------------------------------- ### Using org_module for Organizational Queries (Forthic) Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v2/org_module.md This example demonstrates basic usage of the org_module words to perform organizational queries. It shows how to get the full reporting chain, direct reports, direct managers, and a user's manager's manager. Note that an OrgContext must be set up before using these words. ```Forthic ["org"] USE-MODULES # NOTE: You must set up an OrgContext first 'director1' org.FULL-ORG # Returns all usernames reporting up to director1 'director1' org.DIRECTS # Returns all direct reports of director1 'director1' org.DIRECT-MANAGERS # Returns all managers who directly report to director1 'user1' org.MANAGER org.MANAGER # Returns user1's manager's manager ``` -------------------------------- ### Example Jira Operations in Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/modules/jira_module.md This comprehensive example demonstrates how to use the `jira` module in Forthic to perform various operations including searching for tickets using JQL, creating a new ticket from a record, retrieving the changelog for a specific ticket and field, and determining the value of a field at a particular date from the changelog. It requires a pre-configured JiraContext. ```Forthic ["jira"] USE-MODULES # NOTE: You must set up a JiraContext first (see ../apps/examples/ex_jira.py) : JQL "assignee=currentUser() and resolution is null"; : FIELDS ['Summary' 'Assignee']; # Returns ticket records with the specified fields matching the specified JQL JQL FIELDS jira.SEARCH : TICKET-REC [ ["Project" "A-JIRA-PROJECT"] ["Summary" "A sample ticket"] ["Issue Type" "Task"] ] REC; # Creates a new Jira ticket TICKET-REC jira.CREATE ["changes"] VARIABLES # Gets assignee for "PROJECT-1234" as of 2020-07-25 "PROJECT-1234" ["Assignee"] jira.CHANGELOG changes ! 2020-07-25 changes @ 'Assignee' jira.FIELD-AS-OF ``` -------------------------------- ### Example Usage - Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v3/datasets_module.md This example demonstrates the core functionality of the datasets module in Forthic. It shows how to define records, store them as datasets using DATASET!, retrieve them with DATASET, update them by merging records, pull specific fields using RECORDS, handle missing fields (default NULL or dropped with !DROP-NULLS), and overwrite a dataset using the !OVERWRITE flag. ```Forthic ["datasets"] USE-MODULES : EVENS [2 4 6 8 10]; : ODDS [1 3 5 7 9]; : PRIMES [3 5 7 11]; : NUMBERS [ ["evens" EVENS] ["odds" ODDS] ["primes" PRIMES] ] REC; # Store a dataset "numbers" datasets.DATASET! # Retrieve a dataset "numbers" datasets.DATASET # Update a dataset [["evens" [2 4 6 8 10 12]]] REC dataset.DATASET! # Pull specific fields from a dataset ["odds" "primes"] dataset.RECORDS # Missing fields: Default is to return NULL ["odds" "garbage" "primes"] dataset.RECORDS # => [[1 3 5 7 9] NULL [3 5 7 11]] # Missing fields: Drop NULL values ["odds" "garbage" "primes"] dataset !DROP-NULLS dataset.RECORDS # => [[1 3 5 7 9] [3 5 7 11]] # Overwrite a dataset [["evens" [2 4 6 8 10 12]]] REC dataset.!OVERWRITE dataset.DATASET! ``` -------------------------------- ### Using isoweek module for quarter calculations (Forthic) Source: https://github.com/linkedin/forthic/blob/main/forthic-py/docs/isoweek_module.md This example demonstrates how to use the Forthic `isoweek` module to calculate the start and end dates of a calendar quarter containing a specific date, and how to compute the fiscal quarter and year for a date given a fiscal year offset. ```Forthic ["isoweek"] USE-MODULES # Compute start/end of a quarter containing a specified date 2022-08-09 isoweek.QUARTER-START # 2022-07-04 2022-08-09 isoweek.QUARTER-END # 2022-10-02 # Computes fiscal quarter for a company with a FY offset by 2 quarters 2022-08-09 2 isoweek.QUARTER/YEAR # [1, 2023] i.e., FY23Q1 2022-06-19 2 isoweek.QUARTER/YEAR # [4, 2022] i.e., FY22Q4 ``` -------------------------------- ### Example Usage of org_module Words (Forthic) Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v3/org_module.md Demonstrates how to use various words from the `org` module in Forthic to perform organizational queries like getting the full organization reporting to a manager, direct reports, direct managers, and traversing the management chain. It notes the requirement to set up an `OrgContext` first. ```Forthic ["org"] USE-MODULES # NOTE: You must set up an OrgContext first 'director1' org.FULL-ORG # Returns all usernames reporting up to director1 'director1' org.DIRECTS # Returns all direct reports of director1 'director1' org.DIRECT-MANAGERS # Returns all managers who directly report to director1 'user1' org.MANAGER org.MANAGER # Returns user1's manager's manager ``` -------------------------------- ### Using isoweek module for quarter calculations (Forthic) Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v2/isoweek_module.md This example demonstrates how to use the isoweek module in Forthic to compute the start and end dates of a calendar quarter containing a specific date, and how to calculate the fiscal quarter and year for a date given a fiscal year offset. ```Forthic ["isoweek"] USE-MODULES # Compute start/end of a quarter containing a specified date 2022-08-09 isoweek.QUARTER-START # 2022-07-04 2022-08-09 isoweek.QUARTER-END # 2022-10-02 # Computes fiscal quarter for a company with a FY offset by 2 quarters 2022-08-09 2 isoweek.QUARTER/YEAR # [1, 2023] i.e., FY23Q1 2022-06-19 2 isoweek.QUARTER/YEAR # [4, 2022] i.e., FY22Q4 ``` -------------------------------- ### Example Using CHAIN-KEY-FUNC for Sorting - Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/modules/org_module.md This example demonstrates how to use the "CHAIN-KEY-FUNC" word to create a sorting key based on management distance to a root user. It defines a list of users and a root user, then uses the generated key function with "SORT-w/KEY-FUNC" to sort the list by seniority relative to the root. This requires an active OrgContext. ```Forthic : USERS-TO-SORT ["user1" "mgr2" "mgr3" "director4"]; : ROOT-USER "ceouser"; USERS-TO-SORT ROOT-USER org.CHAIN-KEY-FUNC SORT-w/KEY-FUNC # Sorts by most senior person first ``` -------------------------------- ### Opening and Using an Existing Module in Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Demonstrates how to re-open an existing module using the same `{}` syntax to add new definitions or execute words defined within that module. ```Forthic {my-module : DOUBLE 2 *; } {my-module 4 DOUBLE # 8 } ``` -------------------------------- ### Installing Forthic Gem Directly (Bash) Source: https://github.com/linkedin/forthic/blob/main/forthic-rb/README.md Installs the 'forthic' gem globally or into the current Ruby environment using the gem command, for projects not using Bundler. ```bash gem install forthic ``` -------------------------------- ### Simple Table Example - Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-react/v1/docs/elements/RecordsTable.md Defines sample record data and column configuration, then instantiates a RecordsTable component with these properties to create a basic table. ```Forthic : RECORDS [ [["key" "a"] ["greek" "alpha"]] REC [["key" "b"] ["greek" "beta"]] REC [["key" "c"] ["greek" "gamma"]] REC ]; : COL-INFO [ [["field" "key"] ["label" "Letter"]] REC [["field" "greek"]] REC ]; : SIMPLE-TABLE RecordsTable [ ["records" RECORDS] ["column_info" COL-INFO] ] REC {% for letter in letters %}
  • {{ letter }}
  • {% endfor %} "; MY-TEMPLATE MY-DATA jira.RENDER ``` -------------------------------- ### Batch Update Request JSON Example Source: https://github.com/linkedin/forthic/blob/main/forthic-py/docs/gsheet_module.md Example JSON structure for the update_requests parameter used with BATCH-UPDATE-TAB!. This demonstrates how to format cells, add notes, and specify the range and fields for the update. ```JSON update_requests = [{ "updateCells": { "range": { "sheetId": spreadsheet_id, "startRowIndex": startRowIndex, "startColumnIndex": startColumnIndex, }, "rows": [ { "values": [ { "userEnteredFormat": { "backgroundColor": { "blue": 1 }, "textFormat": { "foregroundColor" : { "green": 1 }, "italic": True } } }, { }, { "userEnteredFormat": { "backgroundColor": { "green": 1 } }, "note": "My note for the green cell" } ] }, { "values": [ { "userEnteredFormat": { "backgroundColor": { "red": 1 } } }, { "userEnteredFormat": { "backgroundColor": { "blue": 1 } } } ] } ], "fields": "userEnteredFormat.backgroundColor,userEnteredFormat.textFormat,note" } }] ``` -------------------------------- ### Starting profiling run (Forthic) Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v2/global_module.md Initiates a profiling session. This action clears previous timestamps and resets all counters, preparing for a new measurement period. ```Forthic ( -- ) ``` -------------------------------- ### Setting Up Gsheet Credentials Context (Python) Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v2/gsheet_module.md Provides a Python function to initialize a Forthic interpreter, register the gsheet_module, define a custom CredsContext subclass to handle credential retrieval, and push this context onto the module's stack using gsheet.PUSH-CONTEXT!. This setup is necessary before using gsheet operations in Forthic. ```Python def get_interp(): interp = Interpreter() interp.set_dev_mode(True) def configure_gsheet_module(interp): interp.register_module(gsheet_module.GsheetModule) class GSheetCredsContext(gsheet_module.CredsContext): def get_app_creds(self): res = { "client_id": , "client_secret": , } return res def get_auth_token(self): res = return res interp.run("['gsheet'] USE-MODULES") interp.stack_push(GSheetCredsContext()) interp.run("gsheet.PUSH-CONTEXT!") return configure_gsheet_module(interp) return interp ``` -------------------------------- ### Calling Server Forthic from Browser Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/IDIOMS.md Provides an example of defining server-side and browser-side Forthic words in the same file, demonstrating how browser code (`REFRESH-PROFILE`) can call server code (`GET-PROFILE`) via `SERVER-PROMISE`. ```Forthic # ----- Server code ------------------------------------- : GET-PROFILE CUR-USERNAME USERNAME>PROFILE; # ----- Browser code ------------------------------------ : BROWSER-FORTHIC """ : PROFILE-BUTTON "profile-button" ID>ELEMENT; : REFRESH-PROFILE 'GET-PROFILE' SERVER-PROMISE AWAIT RENDER-PROFILE; : ADD-UPDATE-HANDLER PROFILE-BUTTON "click" "REFRESH-PROFILE" ADD-LISTENER; """ ; ``` -------------------------------- ### Cell Format Example Forth Definition Source: https://github.com/linkedin/forthic/blob/main/forthic-py/docs/gsheet_module.md Example Forth definition showing the structure of a 'cell' record used with the !CELL-FORMAT flag. It includes fields for the cell's content and a nested updateRequest for formatting and notes. ```Forth : CELL1 [ # `content` is the string content of the cell ["content" "This is my new content"] # `updateRequest` allows the cell to be formatted, notes to be added, etc. ["updateRequest" [ ["userEnteredFormat" [ ["backgroundColor" [["red" 0.796] ["green" 0.004] ["blue" 0]] REC] ["textFormat" [ ["foregroundColor" [["red" 0.42] ["green" 0.66] ["blue" 0.31]] REC] ["italic" TRUE] ["bold" TRUE] ] REC] ] REC] ["note" "This is a note I just added!"] ] REC] ] REC; ``` -------------------------------- ### Configuring gsheet module credentials in Python Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v3/gsheet_module.md Provides a Python example for initializing the Forthic interpreter, registering the gsheet module, creating a custom CredsContext with application credentials and auth token, and pushing it onto the Forthic context stack for authentication. ```Python def get_interp(): interp = Interpreter() interp.set_dev_mode(True) def configure_gsheet_module(interp): interp.register_module(gsheet_module.GsheetModule) class GSheetCredsContext(gsheet_module.CredsContext): def get_app_creds(self): res = { "client_id": , "client_secret": , } return res def get_auth_token(self): res = return res interp.run("['gsheet'] USE-MODULES") interp.stack_push(GSheetCredsContext()) interp.run("gsheet.PUSH-CONTEXT!") return configure_gsheet_module(interp) return interp ``` -------------------------------- ### Example Usage of Forthic Cache Module Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v3/cache_module.md This snippet demonstrates the core functionality of the Forthic cache module, including importing the module, setting the cache directory, storing an array using `cache.CACHE!`, retrieving it using `cache.CACHE@`, and accessing an element from the retrieved array. ```Forthic ["cache"] USE-MODULES "~/my_stuff" cache.CWD! # Sets the current working directory [1 2 3 "Howdy"] "my_array" cache.CACHE! # Stores the array in the cache "my_array" cache.CACHE@ # Retrieves the array from cache 3 NTH # ([1 2 3 "Howdy"] -- "Howdy") ``` -------------------------------- ### Start Profiling Run - Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-py/docs/global_module.md Enables a profiling run. This clears all timestamps and resets all counters. ```Forthic PROFILE-START ( -- ) ``` -------------------------------- ### High-Level One-Line Definition Example (Forthic) Source: https://github.com/linkedin/forthic/blob/main/docs/IDIOMS.md Provides a real-world example of a concise, one-line Forthic definition (`UPDATE`) that orchestrates a complex process (pulling Jira data, constructing a report, publishing to Confluence) by calling other high-level words. This illustrates the one-line definition idiom. ```Forthic : UPDATE SPACE PARENT-TITLE TITLE CONTENT confluence.UPSERT-PAGE; ``` -------------------------------- ### Start Forthic Definition (:) Source: https://github.com/linkedin/forthic/blob/main/experimental/pre-forthic/forrth-erl/specs/DEFINITIONS.txt The ':' word initiates a new definition in Forthic. It creates a new dictionary entry, switches the interpreter into compiling mode, and associates the definition with the 'execute_definition' routine. ```Forthic { : } ``` -------------------------------- ### Example Usage of Forthic Cache Module Source: https://github.com/linkedin/forthic/blob/main/forthic-py/docs/cache_module.md This snippet demonstrates the basic usage of the `cache_module`. It shows how to import the module, set the cache directory, store an array using `cache.CACHE!` with a specific key, and retrieve it later using `cache.CACHE@`. ```Forthic ["cache"] USE-MODULES "~/my_stuff" cache.CWD! # Sets the current working directory [1 2 3 "Howdy"] "my_array" cache.CACHE! # Stores the array in the cache "my_array" cache.CACHE@ # Retrieves the array from cache 3 NTH # ([1 2 3 "Howdy"] -- "Howdy") ``` -------------------------------- ### Example Usage of org Module Words (Forthic) Source: https://github.com/linkedin/forthic/blob/main/forthic-py/docs/org_module.md Demonstrates basic usage of the `org` module words like `FULL-ORG`, `DIRECTS`, `DIRECT-MANAGERS`, and `MANAGER` to perform organizational lookups. Requires setting up an `OrgContext` first. ```Forthic ["org"] USE-MODULES # NOTE: You must set up an OrgContext first 'director1' org.FULL-ORG # Returns all usernames reporting up to director1 'director1' org.DIRECTS # Returns all direct reports of director1 'director1' org.DIRECT-MANAGERS # Returns all managers who directly report to director1 'user1' org.MANAGER org.MANAGER # Returns user1's manager's manager ``` -------------------------------- ### Configuring Excel Module Credentials in Python Source: https://github.com/linkedin/forthic/blob/main/docs/modules/excel_module.md Provides a Python example for setting up the Forthic interpreter and configuring the excel module. It shows how to register the module, define a custom `ExcelCredsContext` class to provide application credentials and authentication tokens, push the context onto the stack using `excel.PUSH-CONTEXT!`, and initialize the module for use. ```Python from forthic.interpreter import Interpreter import forthic.modules.excel_module as excel_module def get_interp(): interp = Interpreter() interp.set_dev_mode(True) def configure_excel_module(interp): interp.register_module(excel_module.ExcelModule) class ExcelCredsContext(excel_module.CredsContext): def get_app_creds(self): res = { "client_id": , "client_secret": , } return res def get_auth_token(self): res = return res interp.run("['excel'] USE-MODULES") interp.stack_push(ExcelCredsContext()) interp.run("excel.PUSH-CONTEXT!") return configure_excel_module(interp) return interp ``` -------------------------------- ### Creating and Using Memoized Definitions in Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Explains how to create a memoized definition using `@:` which caches the result of the first execution and returns it on subsequent calls, unless refreshed with `!`. ```Forthic @: TICKETS JQL FIELDS jira.SEARCH; TICKETS # Will do the Jira search and save a copy of the results TICKETS # Will return the results from the previous call TICKETS! # Will perform the Jira search again and save a new copy of the results TICKETS # Will return the latest copy of the results ``` -------------------------------- ### NULL Forthic Word Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Returns the host language's null value. For example, in Python, this corresponds to `None`. ```Forthic NULL ``` -------------------------------- ### Using confluence.UPSERT-PAGE in Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/modules/confluence_module.md This Forthic example demonstrates how to use the `UPSERT-PAGE` word from the confluence module to create or update a Confluence page. It requires a confluence context to be set up and applied using `PUSH-CONTEXT!` before execution. ```Forthic ["confluence"] USE-MODULES # NOTE: You must create a confluence context and apply it using PUSH-CONTEXT! 'SPACE' 'Parent title' 'Page title' 'h2. My Content' confluence.UPSERT-PAGE ``` -------------------------------- ### Getting Keys/Indices of Data (KEYS) - Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v3/global_module.md Given an array, returns an array of its indices starting from 0. Given a record, returns its keys. ```Forthic ( array -- indices ) ( record -- keys ) ``` -------------------------------- ### Find Range Index - Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-py/docs/global_module.md Given a value `val` and an array of `start_ranges` that give the starting values of an array of ranges, this returns the index where `val` falls. If `val` is less than the first start range, then `NULL` is returned. NOTE: `start_ranges` must be in ascending order. ```Forthic RANGE-INDEX ( val start_ranges -- index ) ``` -------------------------------- ### Using SHEET-ID/RANGE gsheet.ROWS # Store a gsheet ID for rest of examples 'https://gsheet-tab-url' gsheet.URL>SHEET-ID/RANGE POP sheet_id ! # Get all rows in "Sheet1" sheet_id @ 'Sheet1' gsheet.ROWS # Look for a header row and return rows beneath it as an array of records sheet-id @ 'Sheet1' ['Heading1' 'Heading2'] gsheet.RECORDS # Write data to a range of cells sheet-id @ 'Sheet1!D1:F2' [["Col1" "Col2" "Col3"] ["1" "2" 30]] gsheet.ROWS! ``` -------------------------------- ### Using Literal Values in Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Demonstrates how literal values such as integers, floats, dates, and times are represented and pushed onto the stack in Forthic. ```Forthic 1 2.4 2021-02-18 09:30 ``` -------------------------------- ### *DEFAULT Forthic Word Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Checks the top of the stack. If it is the `NULL` value, it executes a specified Forthic string to compute and replace its value. ```Forthic *DEFAULT ``` -------------------------------- ### Configuring gsheet Module Credentials in Python Source: https://github.com/linkedin/forthic/blob/main/docs/modules/gsheet_module.md Provides a Python example demonstrating how to create an Interpreter, register the gsheet module, define a custom CredsContext class to provide application credentials and authentication tokens, and push this context onto the gsheet module's context stack using PUSH-CONTEXT! in Forthic. ```Python def get_interp(): interp = Interpreter() interp.set_dev_mode(True) def configure_gsheet_module(interp): interp.register_module(gsheet_module.GsheetModule) class GSheetCredsContext(gsheet_module.CredsContext): def get_app_creds(self): res = { "client_id": , "client_secret": , } return res def get_auth_token(self): res = return res interp.run("['gsheet'] USE-MODULES") interp.stack_push(GSheetCredsContext()) interp.run("gsheet.PUSH-CONTEXT!") return configure_gsheet_module(interp) return interp ``` -------------------------------- ### Importing Module Words with USE-MODULES in Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v2/global_module.md Provides examples of using the `USE-MODULES` word to import words from other registered modules. It demonstrates importing with the default module name prefix (`jira.SEARCH`), importing with a custom prefix (`j.SEARCH`), and importing without a prefix (`SEARCH`) by specifying an empty string as the prefix. ```Forthic ["jira"] USE-MODULES "assignee = someuser" ["Summary" "Due Date"] jira.SEARCH [["jira" "j"]] USE-MODULES "assignee = someuser" ["Summary" "Due Date"] j.SEARCH [["jira" ""]] USE-MODULES "assignee = someuser" ["Summary" "Due Date"] SEARCH ``` -------------------------------- ### Creating Records with REC in Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v2/global_module.md Shows how to use the `REC` word to construct a record (object) from an array of key-value pairs. The example takes an array of `[key value]` pairs and converts it into a record with corresponding fields and values. ```Forthic [ ["id" 101] ["title" "My Title"] ["cost" 9.99] ] REC # {"id": 101, "title": "My Title", "cost": 9.99} ``` -------------------------------- ### Basic Forthic Interpreter Usage (Ruby) Source: https://github.com/linkedin/forthic/blob/main/forthic-rb/README.md Demonstrates initializing the Forthic interpreter, running a simple Forthic command to map a list, and retrieving the result from the stack. ```ruby require 'forthic' interp = Forthic::Interpreter.new interp.run("[1 2 3] '8 *' MAP") puts interp.stack_pop ``` -------------------------------- ### Using SLICE for Sub-Collection in Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-py/docs/global_module.md ( array start end -- array ) ( record start end -- record ) For an array, returns an array whose elements start at `start` and end at `end`, inclusively. Nonnegative values of `start` and `end` behave as normal indexes. Negative values start at the end of the array and move towards the front (e.g., -1 is the last element, -2 is the next to last element, etc.). Values larger than the length of the list refer to the end of the list. Elements are returned in order starting from `start` and going to `end`. For a record, the behavior is as follows: * Sort the record keys * Apply the same `start` and `end` logic to the sorted keys as with an array * Return a record with the resulting key/value pairs ```Forthic ['x'] VARIABLES ['a' 'b' 'c' 'd' 'e' 'f' 'g'] x ! x @ 0 2 SLICE # ['a' 'b' 'c'] x @ 1 3 SLICE # ['b' 'c' 'd'] x @ 5 3 SLICE # ['f' 'e' 'd'] x @ -1 -2 SLICE # ['g' 'f'] x @ 4 -2 SLICE # ['e' 'f'] x @ 5 10 SLICE # ['f' 'g' NULL NULL NULL NULL] ``` -------------------------------- ### Constructing Arrays Using Words in Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Shows that arrays are constructed using words, allowing other words (like `SWAP`) to be executed during array creation before the `]` token finalizes the array. ```Forthic 1 [ SWAP 2 3 ] # Has the same effect as [ 1 2 3 ] ``` -------------------------------- ### Using VARIABLES in Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v3/global_module.md Demonstrates how to declare variables using `VARIABLES`, set their values with `!`, and retrieve them with `@`. The example declares variables 'x' and 'y', assigns values 20 and 30 respectively, and then retrieves them into an array. ```Forthic ["x" "y"] VARIABLES 20 x ! 30 y ! [x @ y @] # [20 30] ``` -------------------------------- ### JSON> Forthic Word Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Parses a JSON string on the stack and converts it into a corresponding Forthic object. ```Forthic JSON> ``` -------------------------------- ### Forrth INTERPRET Word Example Source: https://github.com/linkedin/forthic/blob/main/experimental/pre-forthic/forrth-cs/HoloForrth/Specs/FORRTH.txt Demonstrates the usage of the INTERPRET word in Forrth. It pushes the string 'SAMPLE' onto the stack, then calls INTERPRET, which executes the string as Forrth code. This results in the word 'SAMPLE' being executed. ```Forrth ." SAMPLE" INTERPRET SAMPLE ``` -------------------------------- ### Demonstrating Word Redefinition in Forthic Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Illustrates that definitions are stored in an array-like structure, allowing words to be redefined without affecting existing definitions that were created using the old definition. ```Forthic : DOUBLE 2 *; : QUADRUPLE DOUBLE DOUBLE; 3 DOUBLE # 6 : DOUBLE [ SWAP DUP ]; 3 QUADRUPLE # 12 3 DOUBLE # [3 3] ``` -------------------------------- ### Log Profiling Timestamp - Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-py/docs/global_module.md Logs a `label` and the current time since the start of the profiling run. ```Forthic PROFILE-TIMESTAMP ( label -- ) ``` -------------------------------- ### Configuring Excel Credentials Context Python Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v2/excel_module.md This Python code provides an example of how to set up a Forthic interpreter and configure the excel module with necessary credentials. It shows how to define a custom ExcelCredsContext subclass to provide application credentials (client ID, client secret) and an authentication token, and then push an instance of this context onto the excel module's stack using the excel.PUSH-CONTEXT! word. ```Python from forthic.interpreter import Interpreter import forthic.modules.excel_module as excel_module def get_interp(): interp = Interpreter() interp.set_dev_mode(True) def configure_excel_module(interp): interp.register_module(excel_module.ExcelModule) class ExcelCredsContext(excel_module.CredsContext): def get_app_creds(self): res = { "client_id": , "client_secret": , } return res def get_auth_token(self): res = return res interp.run("['excel'] USE-MODULES") interp.stack_push(ExcelCredsContext()) interp.run("excel.PUSH-CONTEXT!") return configure_excel_module(interp) return interp ``` -------------------------------- ### DEFAULT Forthic Word Source: https://github.com/linkedin/forthic/blob/main/docs/SYNTAX.md Checks the top of the stack. If it is the `NULL` value, it replaces it with a specified value provided as an argument. ```Forthic DEFAULT ``` -------------------------------- ### Example: Applying Borders - Google Sheets (Forthic) Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v2/gsheet_module.md Defines a border record specifying borders for all sides and inner lines, then applies it to a sheet and range. ```Forthic : BORDERS [ ["top" BORDER] ["bottom" BORDER] ["left" BORDER] ["right" BORDER] ["innerHorizontal" BORDER] ["innerVertical" BORDER] ] REC; MY-SHEET MY-RANGE BORDERS UPDATE-BORDERS ``` -------------------------------- ### Declaring and Using Variables in Forthic Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v2/global_module.md Demonstrates how to declare variables using `VARIABLES`, set their values with `!`, and retrieve them with `@`. The example shows declaring variables "x" and "y", setting them to 20 and 30 respectively, and then retrieving their values into an array. ```Forthic ["x" "y"] VARIABLES 20 x ! 30 y ! [x @ y @] # [20 30] ``` -------------------------------- ### Getting Jira Field Value As Of Date (Forthic) Source: https://github.com/linkedin/forthic/blob/main/forthic-in/docs/v3/jira_module.md Illustrates how to retrieve the historical value of a specific field for a ticket at a given date. It first uses jira.CHANGELOG to get the change history for the specified fields, stores it in a variable, and then uses jira.FIELD-AS-OF with the date, changes array, and field name to get the value. ```Forthic ['changes'] VARIABLES "MYPROJ-1234" ["Assignee"] jira.CHANGELOG changes ! 2020-07-25 changes @ "Assignee" jira.FIELD-AS-OF # ( -- "user1" ) ```