2 ms·
https://github.com/PDP-10/its/issues/1268 https://github.com/PDP-10/its/issues/1268 Alexey-Slyusar commented on 9 Oct I know that the Adventure game code is n
by DonHopkins 8y ago
https://github.com/PDP-10/its/issues/1268 https://github.com/PDP-10/its/issues/1268
Alexey-Slyusar commented on 9 Oct
I know that the Adventure game code is not fully functional. But it has
interesting functional programming elements.
Logo world has purely functional code examples such Albert Cuoco's
Investigations in Algebra (I read the book in short parts that available
from Google Books, but I believe that it is true for all book's code. I've
tried to get the whole book in hard copy but unsuccessful - international
book delivery in Amazon is just terrible). And some examples in Brian
Harvey's wonderful CSLS trilogy. (Which I am continuing to learn).
And am I right that the LISP LOGO implementation written in not fully
functional way?
SimHacker commented 29 days ago
There are several meaning of "functional", and the Adventure game might be a good way to help explain that.
One sense is simply that something works, and is not broken.
Another sense is that something manipulates functions, which it does.
A deeper sense is that it manipulates functions and data in a particularly constrained way, without side effects, using read-only data, which it doesn't.
It uses a mutable model of the world. The rooms and connections between them don't change, but you could add mud-like authoring and editing commands like "dig Room", "link Room Direction" to edit the room model.
You edit the item model when you drop or pick up an item, by mutating its room number.
Another aspect of the model is the player's room number, which you change by moving from room to room.
And yet another aspect of the model is the value of the pronoun "it", which gets set to the last item you said by name, because that name is actually bound to a function that sets "it" to the item name and returns the same item name. Nouns remember themselves in the global pronoun "it".
Side effects like changing global variables is not good functional oriented programming style, but it gets the job done. And the way it does it is by dynamically manipulating and defining and naming functions for each item.
But it's actually just a trick that lets us use the Logo top level interpreter conveniently without writing our own parser!
Logo lets you program in a mix of procedural and functional styles, and has its own parser that we can build on top of to define "Dungeon Domain Specific Languages".
Off the top of my head I can't think of a way to implement a purely functional adventure game!
But it might be like heaven, which is a place where nothing ever happens.