Guides/Locked Scripts

From J Wiki
Jump to: navigation, search

Locked Scripts (ijl files)

The J development system can load definitions from a locked script file. The names defined by running a locked file can be used normally, but their definitions are hidden from the user. A locked file normally has a file suffix of .ijl. This allows you to use proprietary or protected definitions within the framework of an open J development system. Source is locked with verb 3!:6, for example:

   dat=. fread 'user\projects\util\myapp.ijs' NB. read source
   dat=. 3!:6 dat                             NB. lock source
   dat fwrite 'user\projects\util\myapp.ijl'  NB. create ijl file

The text for abc.ijl is encoded and running it defines its verbs,adverbs, and conjunctions as locked. Locked definitions will not be disclosed by the J interpreter. For example, create foo.ijs and foo.ijl with the following definitions:

   plus =: 4 : 'x+y'         
   mean =: 3 : '(plus/y)%#y' 
   plust=: +                   
   meant=: plust/ % #

Load and test as:

   0!:1 <'foo.ijs'             |    0!:1 <'foo.ijl'
   3 plus 'abc'                |    3 plus 'abc'
|domain error: plus            | |domain error: plus
|   x    +y                  | |   3     plus'abc'
   mean 'abc'                  |    mean 'abc'
|domain error: plus            | |domain error: plus
|   x    +y                  | |   mean    'abc'
   13!:0 [1                    |    13!:0 [1
   mean 'abc'                  |    mean 'abc'
|domain error: plus            | |domain error: plus
|   x    +y                  | |   mean    'abc'
|plus[:0]                      |
      13!:1 ''                 |    13!:1 ''
|domain error                  |
|   x    +y                  |
|plus[:0]                      |
|   (    plus/y)%#y          |
|mean[0]                       |
|       mean'abc'              |
                               |
      13!:0 [1                 |    13!:0 [1
   plus                        |    plus
4 : 'x+y'                    | plus
   meant f.                    |    meant f.
+/ % #                         | meant