Tuesday | 05 NOV 2024
[ previous ]
[ next ]

Creating I Type Dictionaries

Title:
Date: 2023-08-19
Tags:  pick

You can run subroutines from within a dictionary. This came in handy for my blog as I transform the title of my posts into a URL. I would like to see my URLs from TCL and one way is to use an I type. I could use an F correlative but I don't know enough to do it quickly.

Instead I did it directly in BASIC!

The first step is to set up the dictionary.

ED DICT DEVLOG-FILE URL

Inside the URL dictionary item we need to set the various attributes:

1: I
2: SUBR('GENERATE.URL',@RECORD,@ID)
3:
4: 
5: URL
6: 50L

The first field is set to I, the second field will contain the subroutine to call. You name the subroutine and pass in the record and the ID. This is enough information to do everything I needed.

Now we can do the listing.

LIST DEVLOG-FILE URL

This will throw an error:

Program ".ITYPE.": pc = 0, Incorrect VOC entry for GENERATE.URL.
Program ".ITYPE.": pc = 0, Unable to load subroutine.

We need to write the GENERATE.URL program and also catalog it.

   SUBROUTINE GENERATE.URL(URL,RECORD,ITEM.ID)
*
   TITLE = RECORD<2>
   FILENAME = OCONV(TITLE,'MCL')
   FILENAME = CHANGE(FILENAME,' ','-')
   FILENAME = FILENAME : '.html'
   URL = FILENAME
*
   RETURN
*
* END OF PROGRAM
*
   END
*

This routine transform my titles into the urls that I use on my site.

CATALOG BP GENERATE.URL

Once it is cataloged we should be able to do the listing again and see that it working.

> LIST DEVLOG-FILE URL
Four Function Calculator four-function-calculator.html

If you look inside the I type dictionary you will see that there is now data in field 16-20. This is compilation information that is saved for the I type.

You may need to do the compile dict command to compile I types but I found that I didn't need to.

> CD DEVLOG-FILE URL
Compiling "URL".
SUBR ( GENERATE.URL , @RECORD , @ID )