So, hello everybody, I'm talking about Doc, a canoe arc, and like it says we're extending it
really because we can.
It's really looking at and say, do we need to?
And the answer is, it doesn't matter.
It's there, so we're going to go ahead and do it.
So, just for a little bit of background, we have a short timeline of the sea standards,
of the start of Unix and the start of time in 1970, which was in assembly and then it's
which to see.
In 1978, KNRC was as established as it was with the sea programming language book.
In 1989, we got an actual MCC with the C89 flag, and then we've a couple other ones,
every couple years.
You know, new things that get added, that make things, that, you know, everything works better.
Things are more defined.
There's a lot less undefined behavior going on.
Compare that with a short timeline of arc.
It appeared in 1977, in 1988, dish.
It'll hold bunch of things.
Unix system 5 came out with a new arc version, and the second arc book.
Apparently it's about the same time for the first release of canoe arc.
And then 40-ish years later, we got the second arc programming language book.
So, looking at a short overlap of the two, we have Unix's rewritten in C.
We got arc.
See, we got KNRC, got the new arc, got MCC, and I've been told we're here in 2025 now.
So, really, when you're looking at arc, you're also looking backwards in time back at KNRC,
and you end up with a lot of things that just look at and say,
and who thought that was a good idea?
So, I guess a little bit about me before I move on.
I was at I did.
It's the first programming language that, I mean, other than basic and key basic,
that stuck with me was I did a C and C plus plus class in the early 2000s,
and then comparing that back with the C timeline, you know, looking at C99 or so,
wasn't that much.
There were newer things, but that's, you end up being a,
I always thought of it as my happy place, and playing with arc,
really, I wasn't so happy after all with that,
but it's, you know, it's about where I fell back to,
normally, to this part of why I ended up trying to do this.
So with arc, you end up with a collection of pattern action pairs,
you have a condition and an action, and so a condition can be,
and we'll go on to that afterwards, but there's a whole bunch of options for conditions,
and action is whatever you want, you know, written in basically KNRC,
and you can also run things before and after using a begin or end block,
and as in KNRC, everything is optional.
So you could have nothing, and that's a valid program, or just begin,
or just end, or just the conditions, or just the actions.
So other than the begin and end, we can have one of each,
the different patterns are expressions or regular expressions,
I can combine them together with hands or ears,
you can have ranges in the patterns, you get all sorts,
you get some options with all of those.
So, ready with this one.
This one I was looking for the word, the.
So it just begins with prints, you know,
print the frequency of the word, the.
So here we're searching for the, we have our regular expression with the T's,
so we look for capital N lowercase ones here, line count.
I'm not declaring line count, I'm not declaring what kind of that it's an integer.
I use it, and it's brings into existence, it starts at zero.
It's just there.
This one here with I equals zero, that one actually,
without that cycle through when you're checking here,
NF is number field.
So, for example, searching through here,
the patterns and test uses rejects.
That's five, but you've already searched everything in this line.
So you're already at two, four, six, seven-ish.
So you get here, you're at I equals eight, or so.
You're not searching anything anymore.
So you actually have to reset it.
So you end up with a bunch of things where
you can just say, it, you know,
line count brings into existence when I, when I want it,
but unless you actually initialize it,
you end up with running into problems.
Same thing with the semicolons at the end of line.
You actually don't need them.
So I don't know if anyone is actually counting the number of times that the occurred.
So it looks like the occurred on two lines and five times.
And then using prep dash C for the,
prep degrees that it was on two different lines.
So I'm not going to go back.
I'm just going to assume that that was actually the case.
I don't remember where it was with that.
Fizz buzz.
You know.
I mean, like it says, you print fizz,
if it's number of line, if it's divisible by three,
buzz if it's divisible by five, both.
If it's divisible by both of them.
So no pattern.
And so just go straight straight into the action here,
between nine and 15 and NR is number of record.
It counts how many basically how many lines you've gone through.
So far while reading.
So we just say if it's, if NR module of three is divisible by zero,
if the remainder is zero, then add on fizz.
If it's five add on buzz and then print the output line.
And again back at 11, we reset it again to the line number with the space.
So here there's no concatenating strings.
We just have output equals output fizz or buzz.
There's no plus, there's no dot, there's no concatenation.
It's just, it's just there.
You have a white space between it.
And it gets merged in together.
And you see that, it looks like it works.
But yeah, so it's, you know, ended up looking at the manual constantly to figure out.
How, how does this exactly work?
So there are some built-in variables that you end up with.
I don't think this was the full list.
This was the list at least in the first off book.
If number of records, file number of records was,
this was if you were reading multiple files.
Then if the first file had 100 records, the second file had 100 records,
the third file of the second, the third record of the second file would have an FNR of 3,
and an R of 103.
Other ones, the number of fields, file name, field separator, and record separator.
So using this as an example with the FS, there's an actual string for,
you know, I guess, rejects for what the field separators are.
But the space between the D and the S and field separator is a break.
And between the FS and the field, all of that space counts as one break.
So you don't end up with a problem like you would have split that with cut.
We'd say, okay, let me count how many spaces there are between FS and field.
You say, here's a white space.
Plus, dash is one field, FS is one field, field is one field.
Separator is one field.
So you can go and change that to use commas.
If you want it to use CSV or other things like that,
record separator default is a new line.
But you can actually set it to say two new lines.
And then if you just have a paragraph of things, you can say,
well, this four line segment is one record,
and then you separate it differently, and you can parse addresses that way.
And then you can also set the output field separator and stuff
for actually printing at the end.
You can make self-contained ox grips.
Dash F, and we're actually using short flags because, you know,
that's the way it is.
And it really does just print itself.
It seems like press the wrong direction.
Then I guess in terms of actually extending it, there were a couple of ways.
This one, we're switching the case letter by letter of the incoming text.
So there is a two upper and two lower function.
So I for the array, we're just, so we're splitting.
$0 is the full incoming text.
We're splitting it into the array, my input, and iterating through it.
And if it's capital, make it lower case, if it's lower case,
make it capital, printed out at the end.
So here's the actual thought for thought.
Here's the actual code for switching the cases.
So comparing, so here come through 15, we say,
we're checking, my input, we're checking, is it lower case,
make it up for case, otherwise make it lower case.
Here was, sorry, went the wrong way again.
Here we're saying we're passing it through this function called switcher,
which we've brought out here into switcher.ock,
where two through six or seven is the same function.
We're just going to, we've pulled it out and put it in a separate file.
And so we'd say, goc-f, our second file,
and we're including the switcher one that we've pulled out.
And we can actually useock paths to say,
actually, all of my library code is in this file,
is in this directory called include, just use dash i switcher.ock in this case.
So defaultock path is, you know, user local shareock.
And, you know, the filter has me here at the time.
So it, you search everything there, you can write a library
and actually just stick it there and reference it from other things.
And, you get, you know,
and, you know, it can get switch based on the prefix,
as how you've compiled gawk.
The other one that's different specific to gawk is oclib path,
where you have user local lib gawk instead of user local shareock.
And so these ones are actually compiled files,
and they are loaded instead of included.
So difference here would be,
so here, very similar to the previous one,
except here online three, we have outload switcher,
which is a library that I've written for this,
and we're doing the same output equals output,
c switcher, my input i.
And so, beginning we have, according to gawkapi.h,
just a series of includes,
because it includes literally nothing just in case,
you're using an old system that doesn't have any of those.
And so, you know, I've just put in the notes,
beginning of header end of header,
because of how it works, so we've gone into clear the functions
that I was going to make.
And then, here's the bottom part of the file,
it registers it,
and there's no initialization required when running the function.
It adds switcher to the function table.
And then in terms of actually switching the things,
this one actually ended up running into all sorts of issues
and then to being, you know,
where I said, see, actually it turns out,
isn't my happy place.
So yeah, so it really just, I mean,
there is the two upper two lower and ways to compare,
but I ended up doing it this way.
So, so the main part here is,
you know, other than here on 23,
where we have the defining the function,
we have our actual, we're getting our argument,
which is an ox string,
and we're extracting the first letter
because we know we're passing it letter by letter
and we're using K and RC,
so we can literally do whatever we want.
So we're just going to ignore that it's a string,
pretend it's a character array,
and grab our letter,
and then we're going to test it out.
I had some magical thing I ran into
that I couldn't get to work,
so I recreated a ox string
and stuck my letter back in the magic spot
where I said it was going to be,
and I ran in,
suddenly it started working almost.
So I got my ABCDE123 to switch,
and then I ran it through again,
and I have a double-free.
So, I'd love to know where it was,
I don't think I'm going to return to that code.
That's 23ish, 24 lines,
I've managed to make a double-free error,
so lots of fun with that,
but I mean, everything is in Gok API.H.
When you install Gok,
it includes the API header,
and it tells you all of the things
that you can get with it.
This one was the ox string,
it has a, has a string in the length.
Number types are either doubles or MPFR.
Number thing is,
for the fancier math.
All numbers are doubles,
which becomes fun.
This one was the loading the function.
I'm going to skip that.
Is it a number or a string?
The answer is yes.
It is a number and a string,
and ox value is what ox works on,
and you can see it is,
I mean, you can declare what it is,
but it's a string and a number and an array,
and it can also be a scalar or a Boolean.
It is all of them,
depending on how you interact with it.
Let's go and skip that part.
There are some fun programs written in Gok TranslateShell.
That checks uses curl to do translation in the terminal,
and so it does,
you know, a frame I think we have to still.
Okay.
We'll say check that out.
Shepard run.
I wrote and had lots of fun with that.
So, yeah.
Let me switch quickly to,
You got it done, really.
And there's Gok Explive,
which I did not make a slide for,
but here there's a collection of extensions
for working with Postgres or with CSVs or with JSON,
or Redis XML, everything,
and people working together to actually create libraries
to work with us,
that work generally with the upload function.
And you think, well, who would do this?
Yeah.
Go ahead, have fun.
Look out for double-free hours.
Awesome.
He keeps all right.