People here are organizing the deaf room, particularly Manolis who has done a lot of
the work before we organized this room.
Anyway, I'm going to talk a little bit about Guy and Zig.
So I prepared two talks.
One talk you can download online.
There was kind of an overview of why I made these choices and why we're doing this.
But I think it's better just to hit the command line or a shell.
Right, so many people will recognize this Emacs.
The letters fall off on the side, it shouldn't matter too much.
And then I'm going to run in a shell.
So I don't know if everyone is aware, but the gig shell is a proper container.
So only the tools are pulled in that we define.
And this is done in the gig.scheme file.
In the gig.scheme file we define the dependency we want.
Right, so Guy is there and Zig is there.
So in the file we find Zig version.
In the container, right, and then Guy minus V is also there.
But Vi, for example, is not.
And if this was properly running on Debian, it would be visible.
So what I'm going to do is I'm going to run Zig to build my library.
It's a dynamic library.
And then I use package config to pick up the Guile compile switches.
And I'm going to compile it against a little C file.
Uh-oh.
Yeah.
Right, yeah, I missed the second line, I see, yeah.
Right.
So Guile is almost designed for linking against C.
Right, so I wrote a little C program to show you that.
And it can, it calls Guile functions.
So scheme from int is a Guile function.
So it switches, it turns test into a Guile integer, essentially.
And then a boolean, and then I call this function here in C.
Right, my increment in function.
And you can see that it uses Guile objects to pass into the function.
And there's also a Guile object returned.
Right.
So it's very minimalistic code.
And I just need to get a compile it.
Now it did compile, but now it doesn't find the library.
So I need to add the library path.
So I'm just doing this raw so you can see what is happening.
You know, I mean, if you had a proper build script, you can account for all this.
But you can see it says hello world from 3 to 4.
Right, so that's what the C function does.
Now I want to do the same thing in Zig.
Right, so I created, actually what I want to do is I want to call Zig from,
you know, the same library that I'm using.
I want to call this from Guile. Right.
So let's try that.
So I'm in Guile now and I added the local search path for the library. Right.
Yeah, so here we load the shared library libmy.so.
Right, it loads into Guile.
And I want to try something like,
and it says it doesn't find the procedure because I haven't defined it.
Yeah, so that doesn't work very well.
Let me see where we are.
Yeah, so call it ping Zig with an underscore.
All right, that's not very Guile-like, is it?
Yeah, so that's some conventions and I already ignored it.
Yeah, so Guile has a wide range of C functions in the library.
And these can be called.
You know, so if you look for the C function, which one did we use before?
Yeah, or a scheme from int you can see here, right?
Scheme from int. And so in the Guile reference manual,
you see in the reference manual almost on every page you see the sort of the C functions that you could also call as list functions.
You know, and the scheme from int should be there.
It's a long list, but that's the idea. So when you actually use the Guile manual,
you will see the C interface to the CABI.
Now the interesting thing about Zig is that it faithfully, you know, uses the CABI.
So, you know, anything you can, you define in Zig, you can essentially access from Guile.
So let's look at my Zig file and I say ping.
Yeah, so this is the equivalent C function, sorry, ZigVinc function that we had defined in C earlier.
Yeah, you have a ping Zig. It takes a scheme object as an input and it returns a scheme object, right?
And it just pings it back.
So how can I see the scheme object as it is defined now?
And as a matter of fact, Zig can export, sorry, can import C include files.
Yeah, it's actually one command.
Yeah, so you say Zig translate C, right, then the path to the include file, then include file itself,
and it turns into a proper Zig file.
And this Zig file you can just import and it will work.
Yeah, so all the functions that are defined by Guile that are exported that you could use from C in principle
are now available in Zig, including the objects.
Yes, if you look at this Zig file, it doesn't look very nice, right?
But it's all there and it actually just worked in one go.
I had to delete one line in it.
All right, so yeah, the other thing of course is that I'm using ping Zig1 right now.
Okay, so let's try hello.
And it pings back hello, right?
I mean that's what we see in the Zig function here.
And Guile is not a strictly typed language.
Yeah, I mean it's typed, but it's not in the sense that here we have a variable that you can, you know,
in the one case I'm using an integer, in the next case I'm using a string.
Yeah, and this makes for, apart from the fact that I'm using a rappel where I'm actually talking to the, you know, to the Zig backend,
it also gives me a lot of flexibility in what, you know, how I define these functions and these variables that get passed.
Okay, so let's do something a little bit more complex.
And, you know, this exploration that I had with Zig and C and Guile, it's also all online, you can just read it.
It's in a GitLab repository.
Yeah, so if you define a function in Zig, you know, just naively like ping Zig here, it won't be immediately visible to Guile.
So you need to create a mapping for that.
Yeah, and this is in the Guile documentation, it's exactly the same thing in C.
See if I can find it, yeah, here it is.
So when you initialize the module, which means when you load the shared library, right, it will call this function,
and you will define a sub, sorry, it will, yeah, define the function call here.
So in Zig here is ping Zig, right, ping Zig and it has one argument.
You need to do that to make the symbol visible to the Guile interpreter.
That's basically what you have to do.
There's nothing more to it, which is kind of boring, you know.
So yeah, I'm also opinion that, you know, that we need multiple programming languages.
Yeah, there's the, when you talk about Zig, there's often, or even C++, you know, there's often the elephant in the room.
I'm not going to name it.
But this is a language that tries to be everything, you know, and you end up with a very complex language.
Also, the compiler is dog slow.
I don't know if anyone is using the unnamed language.
And then it has, you know, it has a borough checker, which acts like, you know, a nagging wife, you know, it keeps talking to you.
And I tried it, you know, and I tried to love it because it's a functional language, you know, it's a functional programming language.
But it kept talking to me and it kept going me out of my flow, you know, I just couldn't keep moving.
So I think, you know, it's probably wiser to have a language like C, which is, you know, you have to realize that most of the code in the world today is written in C++, C++ still.
If you want a type of performance, you will end up with a strictly typed language, which is, you know, imperative to some degree because CPUs are imperative, right?
We don't have, at this point, we don't really have functional programming CPUs.
So to optimize that stuff, you end up, you know, with a type of language that has to cater for that.
But nobody loves programming in C++, you know, and in C programming is also hard, you know, to shoot yourself in the food language.
I call it.
So it's nice if you can have a language that has some somewhat stronger guarantees, but it's still blazingly fast and still, you know, kind of imperative.
And then have something like Gile, which actually allows you to be, you know, productive, right?
And do functional programming when you want to.
So you end up with this type of mixture.
Have we got five minutes?
Five minutes.
Five minutes to two questions.
Okay, so one thing, one additional thing I would like to show you.
Sorry, that's mine.
Yeah, so you can, I mean, using the Gile libraries, you can essentially build up lists, you know, which is the fundamental for many list-like programming efforts.
But, you know, when you talk about performance, you'd like to deal with arrays of data.
So it continues blocks of memory where you have integers in a row or doubles in a row, and you're able to address these integers and doubles.
Of course, you can do that from Gile, but, you know, if you want to do, if you write high-performance code like we do, you want to be able to, you know, use it as a vector in ZIG.
Yeah, so you have an index, the base pointer to the vector, and then you have an index, and you should be able to fetch out the data object that you want.
So just write a little example here.
So this is the list example.
Let me see if I can, the vector array.
Yeah, so you have, I wrote a little, let me move that down.
A little ZIG function, which has my increment in floating point 64 bits vector ZIG, you know, I'm very good at naming, apparently.
You pass in a Gile vector, which is, again, a scheme object.
It returns a scheme object, which is, again, a vector, right?
And then it calls this Gile function, scheme f64, oh, that's where the naming came from.
It came from Gile, yes, so I set X, you know, so I set, I'm set in the vector, I set at position one, right?
So index one, I set the value 3.7.
So this is kind of happening in Gile-ish C code, so it's calling essentially Gile C functions.
Yeah, and I prove that it works, you can look it up.
But here, here I'm using a proper index, I think, let me see, yeah.
So you increment the f64 vector, right?
This is the old version.
Here I get a handle on the array.
And then I get the data, so I get a vector here.
If our data is a vector, yeah, of the elements of the vector array, right?
And then I index the data points based on the vector, you know, of the floating points, and show 0, 1, and number 2.
Yeah, and that's what it shows, so I'm not going to do that live, but that's the idea.
Yeah, I'm done.
Yeah, so it's in a nutshell, the code and the slides are online, so you can have a look, have a go.
Any questions?
Yes.
I tried quite long actually, so I read five books.
I probably took two months and wrote a thousand lines of code or so to decide it wasn't for me.
But yeah, I hear quite a few stories like this, which are very similar.
I think, you know, it's a language for masochists.
A language for masochists.
You have to be a brilliant person, right?
Well, a brilliant masochist, let's put it that way.
You have to be brilliant to keep that all in your head.
Yeah, so see.
Yeah, you know, I'm not complaining about it because people who program in Rust, they do better than in C++.
So the compiler does help a lot, and I think it does lead to better code.
I've given students, you know, work in Rust, and they do write better code because the compiler actually helps you.
All right, but it also takes them a long time to get something done.
So it depends on what your goals are, right?
I mean, if you have to write, you know, perfect software to launch your rocket, you might, you know, want to do it that way.
But if it's just like me, you know, in my job, we write mostly throw away code.
It doesn't pay.
Bioinformatics, so I'm in science.
We have long-lived code, but it's usually by accident, right?
So you write something, and people start using it, and then 10 years later, it becomes mainstream.
It's actually happened to one of our projects, yeah.
It's kind of, yeah.
And then, you know, then it's too late to do better.
So at one point, you showed us how to convert the ZIG file to C, right?
But it wasn't really necessary in order to, or it wasn't necessary in order to call the style stuff from within ZIG?
No, I mean, it's, the guy that adheres to the C ABI, right?
So it has a C calling interface.
You can use the scheme object, yeah, so that came from there.
But actually, the scheme object is really simple when you look at it.
So it could be that, you know, just, you can just roll your own.
Yeah?
So you create the language for scratch.
So why did you decide to use the semicolons and curly braces in it?
Well, I didn't design ZIG.
I should have been clearer.
Nor have I any input on guile, unlike other people here.
But, yeah, you know, I dabble in languages.
You know, I use, people often ask me, what is the language of the year?
I think at that point it was Scala.
I'm embarrassed to say.
But, no, I think, you know, ZIG does appeal to me.
Yeah?
The second question is, so if I'm running, if I want to make a formal program,
and I do them in Fortran or Julia, why would they use it?
So Fortran is, you know, it's a bit difficult,
because the very different language is Fortran and Julia.
But I think, you know, ZIG tries to be in the space of C.
Yeah.
It's a general purpose systems programming and uncompromising speed.
And it is fast.
Yes, the compiler itself compiles itself in 10 minutes about on a standard machine.
But I think, for example, it doesn't have exception handling.
Yeah, it uses a different approach, which is more like a maybe monad.
You know, and even C++, typically you'll have exception handling,
which, you know, every time you call a function, it has to carry state with it
to be able to unroll the stack.
And this causes overheads.
That's one thing.
Now, with C++, the other thing is that in the background,
there's often a lot of memory allocation going on.
Yeah, especially when, I mean, it's kind of unavoidable to use the SEL these days.
That's best practice.
And I find that in ZIG, because it's closer to the C philosophy,
it's actually much faster.
Yeah, so.
Oh, hey.
Are you planning to write like a tutorial in the guide manual for how to do this?
Yeah, we should.
I think the next speaker needs to go on.
No?
How much time do we have?
Two minutes, one and a half.
Yeah, you can.
It's good to switch.
Thank you.
I'll switch on.