#cplusplus meets #cobol and #lisp

Call it madness, but I have a fascination with trying to transcribe my C++ accounts program to COBOL.

I have an idea of a kind of interoperative facility, where I can code in a mixture of both. As a first stage, I have written a small program in Lisp which contains a record schema and an input converter. Here is the schema:

(defparameter *amount* ‘(amount dec 12 2))
(defparameter *dstamp* ‘(dstamp str 10))
(defparameter *quantity* ‘(quantity dec 12 3))
(defparameter *ticker* ‘(ticker str 6))
(defparameter *yahoo* `(,*dstamp*
(tstamp str 8)
,*ticker*
(rox dec 6 4)
(price dec 12 6)
,*amount*))

(defparameter *record-descriptor*
`(( “comm-1” (,*ticker*
(dload str 1)
(typ str 4)
(unit str 3)
(name str 22)))
(“etran-1” (,*dstamp*
(folio str 4)
,*ticker*
,*quantity*
(amount dec 12 2)
(way str 1)
(taxable str 1)
(desc str 20)))
(“leak-1” (,*dstamp*
(folio str 4)
,*ticker*
,*quantity*
(taxable str 1)
(desc str 20)))
(“nacc” ((dr-acc str 4)
(cr-acc str 4)
(acc-type str 1)
(mult dec 1 0)
(desc str 20)))
(“nb” ((desc str 20)))
(“ntran” (,*dstamp*
(dr-acc str 4)
(cr-acc str 4)
,*amount*
(desc str 20)))
(“yahoo” ,*yahoo*)
(“yahoo-1” (,@*yahoo*
(desc str 20)))

))

I have written some Lisp functions that takes in free-form input, dispatches on the type of record, and produces a fixed string line output. The next step would be to see if I could generate COBOL copybooks and C++ structures from the schema.

On the COBOL side, this should make reading in the data fairly straightforward, as it can transfer a line from input directly into the copybook structure.

I think C++ would be trickier. It doesn’t have fixed-length strings or structs that I can simply serialise and deserialise.

On the other hand, if I want to cut Lisp out of the loop, it will be more difficult to persuade COBOL to convert raw input into record format. I had solved the problem a long time ago on C++.

My COBOL is virtually non-existent, so there’s certainly a learning curve in me massaging it into behaving the way I want it to.

My Lisp is fairly weak, but to a large extent, you don’t have to know much Lisp. I found myself creating the requisite macros quickly. The two points that stood out to me is that I had to spend a long time on the formatting routines. The format statement is powerful, but somehow it did not seem powerful enough. I had to wrap it in a few convenience functions to obtain the output I wanted.

What I also noticed is that Lisp (I am using clisp) is a slow old beast. It took nearly 0.5 seconds (clock time) to process the input. My guess – and it’s a guess shaped from an anlogous experience – is that C++ would be able to process this in a tenth of the time probably at most, and I imagine COBOL would be somewhere in that region, too. The notion, as some Lispers would claim, that Lisp could be “just as fast as C++” seems fanciful.

COBOL is a strange language. It is, at once, an easier, and more difficult, language to use.

The experiment continues.

Advertisements

About mcturra2000

Computer programmer living in Scotland.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s