FUCK YEAH RECURSION

A Function to Un-Nest Nested Structures in MATLAB

So I’m flying back from Shanghai right now, (youalreadyknow it’s business class) and I decided to business-expense-splurge for the in-flight wifi, which is about as fast as a snail in the process of peacefully passing away. This means the only scrap of entertainment I can garner from my laptop is writing code in MATLAB. Writing fuckaround code in a pretend programming language in a rickety IDE has a provided surprising source of succor; if you were here you’d know it too because you’d notice I have been sitting FOR HOURS WITHOUT MY SEATBELT ON because I was simply too enraptured by the alternating tides of hate and happiness that MATLAB so easily exerts on the user.

Basically, I’m working on a GUI that allows a user to programmatically  create test limits for test data, while also allowing the user to efficiently adjust the limits where our absurd test data manages to invalidate centuries of statistical knowledge. This requires allowing the user to load a specific test from within an absurdly packaged data file which comes from a test system written by someone who clearly much prefers obfuscating and hiding things over effective data collection WHICH in turn means deeply and variably nested structures. Like 400-megabyte-CSV, stuck-in-limbo-with-Leonardio-DiCaprio, booger-that-you-can-feel-but-after-several-embarrassing-red-lights-you-cannot-remove levels deep.

Therefore, after careful perusal of mathworks, I wrote the following code. It uses recursion to return an array of strings describing each and every branch of a struct, down to the twig. It is surely my greatest accomplishment thus far.

function allfields=fieldnamesr(struct);
% FIELDNAMESR recursively explores the depths of nested structs To find all
% possible branches
%      fuck yeah recursion
fields=fieldnames(struct); %are there any field names?
idx=1; %increment variable
for i=1:1:size(fields,1) %for all field names
    if isstruct(struct.(fields{i})) %see if that field name itself is a structure 
        temp=structRecurrr(struct.(fields{i})); %if also structure, then we must go deeper!
        for j=1:1:length(temp) %for all returned values 
        allfields{idx,1}=sprintf('%s.%s',fields{i},temp{j}); %return a string containing returned values
        idx=idx+1; %increment
        end
    else
        allfields{idx}=fields{i}; %if field name not struct, then we are at bottom level
        idx=idx+1; %increment
    end
end

PSR J1748-2446ad

Hey baby,

what’s the world coming to these days? It’s all going to hell isn’t it?
what if we just got away from it all? like light years away
fuck all that noise, all the people hurting each other
with the sky figuratively falling and with the economy and the people and the election and the state of things

you’re the one thing that’s good in the world

so

I was thinking

let’s just get away from it all, like you’ve always wanted

you and me in a cottage on the sea side
you know? Let’s do something crazy and just run away
we don’t need anyone if we have each other.
Just you and me
I can see you’re with me to the end no matter what
so let’s elope,

let’s go some where crazy

I’ve got the perfect spot in mind:
let’s go to PSR J1748-2446ad
what if we did that? let’s just get away
I know this is a little out of the blue, a little crazy, I can see you’re a little worried, but it’ll be perfect

let me tell you about J1748-2446ad

it’s a little spot up north, in Sagittarius, by Terzan 5, it’s exactly the kind of place we’ve always imagined we’d grow old together in

there’ll be plenty of room for kids if we want to have some

it’s a fix me up for sure, the heating’s a little wacky, it’s probably like 6×105K there year-round
but I love the way a little sweat looks on your skin

the foundation needs some work, the whole place might collapse into a black hole
but you’re all the foundation I’ve ever needed

it’s a bit bright there; 1.29×1026watts of emitted X-Rays would either instantly vaporize us or instantly give us cancer and then instantly vaporize us
I’m not worried about that though, your smile is pretty damn radiant and I haven’t vaporized yet, have I?

but it’s a perfect place to watch the sun set, though we might get a little motion sick because J1748-2446ad rotates at about 44,000 miles per hour. But you already spin me right round baby (like a record).
anyways, that’s 61,862,299 more sunsets a day we can watch together with our toes in neutron sand

also probably the wifi won’t be that good, what with us moving at 0.25 the speed of light and the 2.3×1013 Gauss magnetic field that will erase all of our devices

and also instantly destroy them

and also instantly crush our bodies

but I think it’s nice to unplug from everything every once in a while

we’ve got to watch for the tide, or at least the tidal forces, because J1748-2446ad’s gravitational field,
it’s about 106,387,117,347 times stronger than the earth’s

but together we’d figure out how to make it work
and once we get there it’ll be our own little paradise
what if we did it? what if we just got up and dropped everything and left right now?
with only high-energy astrophysics to bother you and I
we can finally have a cottage on the sea side like you always wanted

it’ll be just you and me

and a sea

of ultra-densely packed neutrons radiating gravitational waves into the starry sky

a place where we can just be us

just you and me
and PSR J1748-2446ad

everything is so grim these days

so

let’s just do it, let’s just drop everything and go
I know its late at night, babe, but it’s 18,000 light years a way so we better get going
it’ll take 134,123,326 more anniversaries to get there if we sling shot by Jupiter

we can celebrate on the road