• Arbortext’s ACL Language – Part 2

    Continuing from where I left off on the last ACL post. Part 1 stopped where the function was returning a value. More often than not, you will want to store the results returning from a function. You can return the results into a variable and later use that value.

    To create a variable, it is a process of running the function, returning the results and placing it into the variable (or temporary storage). We are going to use the variable to display a response. Variables start with some kind of scope, in this example we are using Global creates the variable that can be used anywhere in the current package (the scripts workspace).  We use a dollar sign ($) to tell ACL to assign it to a name (our example, $user). To help ACL understand when a statement is complete, use the semicolon (;) at the end.

    #— Variable name called $user
    global $user;
    #— Placing the results of the function username() into the valuable $user
    $user = username();
    #— Showing the results using the response function
    response($user);

    Running this code, either as a snippet (small code part in a file) or copying and pasting each line into Arbortext’s command line, will produce a response to the user’s name.

    Comments

    In the last code example there was the use of # sign. Everything after the pound sign is a comment and will be ignored by ACL. It is for humans (not machines) to place comments on why the code was written. Keep in mind, what is fresh in you mind today may not be in six months from now. However, if someone follows after you, it will help them understand why you did what you did. It is not very important to comment on everything as much as commenting on complex areas.

    You can stick comments on top (above example) or to the right of the code.

    global $user;  #— Variable name called $user
    $user = username(); #— Placing the results of the function username() into the valuable $user
    response($user); #— Showing the results using the response function

    Blocks of Code

    A block is a section of code that is a cohesive unit. It is delimited with curly braces { }. You will see them where functions are lengthy, if/else branching, in while and for loops.

    if (tagname  == "pgbrk") {
        dt;
        response("pgbrk tags are not allowed Use <brk>");
    }

    While Loop

    Below is an example of a function that removes comments inside an entire document. It uses a while loop and the find command.  The while loop will do something while it is true and will stop when that condition changes to false.

    function removeComments() {
        #— Removes all the comments in an instance
        #— Douglas Wade Created 5/17/4
        find -m ‘<_comment>’;
        message "Removing all comments…";
        while( selected() ) {
            delete_mark;
            find -m ‘<_comment>’;
        }
    }

    For Loop

    Below is an example of a for loop. The function task is to remove an element named change. It uses a for loop going over each element. If it is a change element, it deletes it.  If it’s not a change element, it skips it, and continues in the loop until all the elements have been reviewed. A for loop will do something until it reaches a limit (the number of oids (explained in a future article) i&lt;=count(oids)). In this example, it uses a counter and on each pass increments the counter by one (i++).

    function delete_change(doc=current_doc()) {
        current_doc(doc)
        local oids[]
        if (oid_find_children(oid_null(), oids, "change")) {
            local i
            for (i=1; i<=count(oids); i++) {
                goto_oid(oids[i])
                if (current_tag_name() == "change") {
                    delete_tag
                }
            }
        }
    }
    This entry was posted on Saturday, April 25th, 2009 at 4:49 pm and is filed under ACL, Arbortext Editor. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 1 Comment

    Take a look at some of the responses we have had to this article.

    1. maxpensyl
      May 29th

      This is great! I hope you continue to grow this tutorial series.

  • Leave a Reply

    Let us know what you thought.

  • Name(required):

    Email(required):

    Website:

    Message: