Hacker News new | ask | show | jobs
by banku_brougham 2929 days ago
Thank you, I remember wanting to follow up on these more abstract constructions in the book. They seemed to be leading me somewhere amazing and very computer science-y. Programs that take programs as input and generate new code to do that thing I wanted with some data files — I’m sure this will be useful if I put the time in.

Am I right that qawk was included as a program in the text? Did they ever follow up with further uses?

1 comments

Yeah, the code is all in the book, and it works! Here's the main body of the qawk interpreter:

  BEGIN { readrel("relfile") }
  /./ { doquery($0) }
where

- relfile is a file containing the field attributes used in various database files,

- readrel is a function that parses the relfile and stores the fields in a dictionary, and

- doquery is a function that takes a qawk query, converts it to an awk query by replacing the field names with their corresponding field numbers, and then executes the awk command.

The whole thing runs about 60 lines.