2019-05-26: Trnx; STDOUT being polymorphic; about projects

I'm trying to get back into the habit of doing & making, after some years of accumulated fear around this. So this will be much rougher than my usual efforts. Read at your peril.

Printing & STDOUT

So I've got as far as modelling the instruction pointer getting incremented every cycle, and now I need to do something interesting. Printing to standard out.

I have a challenge — how do I model standard out? You might suppose that it is state, if you draw a ring around what the program is that includes that, but it isn't ever read back and so you might conclude it isn't state.

It would be neat if the code = data thing we've got going on so far was preserved, but I might have to trade that away and consider standard out a bit like a 'ticker', i.e. a literal printer like on ye olde computers.

Concretely, I initially imagined standard out would be a region of memory (say, lines 100 to 200) and we just display that, but it's also visible in the code window. But that would be kind of annoying, because we'd just have a bunch of blank lines and scrolling and would be sort of paying bad faith to our visualizable constraint.

So I looked up how it's done in asm and it's abstracted away with system calls — so the program says, here's my data, kernel, now do with it what you like. That way the data can go where it likes and can be written out of memory etc. It does seem nice and flexible.

Side-note: I watched a talk by Not My Uncle once where he made the point that standard in/out/err were early examples of polymorphism — since one program (e.g. cat) can do many things (e.g. write to a file, write to terminal, read from a file, read from terminal, write to network etc). This is a nice idea and I sort of see how the idea evolved and that it is quite elegant.

Yes, I think maybe that is the way to go. Could also have a nice 'standard in' flow where you give it a line number and then it goes and fetches it from the user, then it magically appears in the code window.

Also, now I think of it, this is definitely not the first instruction to start with. We should start with self-modifying instructions.

Getting our hello world loop!

Self-modifying and standard out now done. So we can run this program:

2
print "Hello, world!"
append #2, #3

And here it is working:

self-modifying hello world loop liiiives pic.twitter.com/AKS2nljlT3

— kay (@neoeno) May 26, 2019

I nixed the parentheses in the end. They were a silly affectation.

I feel happy with the interpreter so far, it uses a proper parser (I got as far as realising I'd have to parse quoted strings and realised I wasn't going to get far with regexes — the most useful senior dev power!). The interface logic is a little rushed but it's fine.

Next is getting fizzbuzz working, which I think means implementing jumps & conditional jumps, which means implementing writes & conditional writes!

Some reflection on my feelings doing this

I started to feel less happy towards the end of working on this today. I'm watching this quite closely, because I've recently made a connection between my habit of not really making anything, and a few realisations around my therapy that I don't let my own interests lead my life. Instead, I focus on the interests of others, so that I can avoid them doing things that scare me and get them to do things that make me feel good.

(If you're reading this — yes a certain amount of this is fine, but the degree to which I do it is not so fine, I believe. Maybe it's like alcohol — some is fine, a lot is less fine, and not knowing what to do without it is very difficult.)

So I'm picking up on a possible dynamic in my life — I decide to do something because I have an interest, and then I talk about it, and others pick up on it or don't, and then the attention or lack thereof from others sort of eclipses the original interest and destroys it. The further I get into it, the more I forget about my own interest in what I'm doing.

And so eventually I get so exhausted by returning to my historic destructive interest — the attention of other people — that I give up on whatever it was, and it feels like a relief, because I haven't been enjoying it for its own sake in a long while.

I can feel the dynamic starting to kick in now. The bracketed section above was for you, the reader, to convince you to be more sympathetic to me, and not for me.

The first solution, like with so many things, is to learn to notice it. Mostly everything else figures itself out after that. They say, in the jargon, I think, that this is turning something from ego-syntonic to ego-dystonic. I imagine this like taking a bit of me and ejecting it out of the me-sphere. After the personality, which is sometimes styled as the mind's immune system, identifies it as foreign — most of the time it can remove it or compensate for its effects.

So I've already been working on trying to remember why I enjoy what I'm doing, and asking myself if I am, and what I might enjoy doing next. The other challenge is that there's also a bit of adult self-management that needs to be done since we can't always be doing things we enjoy, and that's another thread I have to learn and weave in.

Before I made dinner, I wrote this down: wanting to speak is enough.

I think it means I don't have to worry so much about what people are going to get from what I'm writing or making, not unless I want to. I can also just speak because I want to speak. It doesn't have to always be about the needs of others.

I feel concerned about seeming humblebrag-y selfless, but it's really not a virtue. Ask yourself what it would be like if you needed everyone around you to be happy all the time, and what feelings & behaviours that might lead a person towards.