Skip to content

Instantly share code, notes, and snippets.

@aphyr

aphyr/sara.md Secret

Last active October 4, 2020 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aphyr/c040d3a1d328db2a372433b5a7cb21b3 to your computer and use it in GitHub Desktop.
Save aphyr/c040d3a1d328db2a372433b5a7cb21b3 to your computer and use it in GitHub Desktop.
Scrapped intro to a technical interview piece

Sara's hands rattle you. They perch, crow-like, atop her wrists: each bent slightly inward, fingertips gently touching, and holding very still. Sara herself seems not to notice them. She is speaking, cheerfully, to the hiring manager at the door. Her hair flounces as she laughs, ebony ringlets cascading over the shoulders of her bright floral sundress. One hand cocks slightly, and you nearly drop your tea in alarm.

"Is everything okay, Vidrun?" Something here is definitely not okay. You have felt this in many interviews, at many companies, but never in this particular way. Lie.

"Great, great," she beams. One hand, as if reminded of its purpose, assumes the posture of a normal handshake. "It's so wonderful to finally have the chance to meet you! In person! I've wanted to interview you for ages."

You sincerely doubt she's been alive that long, but smile politely, and take the offered hand. It is warm and supple, suffused with blood, and bears the faint patina of half-committed futures. Your own are impressed with deep, indelible lines. You turn them over, feeling for anything amiss. Normal hands, for a normal girl of twenty-five. Perhaps you can relax.

Sara sits you down, and taps her hands together, and tells you how wonderful it is to work here, and how wonderful your code is, and that she really hopes you'll join the team. Everyone pairs here, she says, and takes the chair next to you. Her fingers trace the tabletop idly as she tells you about the yoga group, and the yogurt bar, and how important life-work balance is to the company. Then she asks you to balance a binary tree.

"I'm sorry..." Stall for time. Even after all these centuries, you've never been very good at grafting limbs. "I have so much trouble remembering the transformation rules."

Plead with the goddess to intercede on your behalf.

vidrun@bamse ~> swipl

"Can you remind me of what balanced means, in this context? We want a tree where both branches are of equal height?"

She smiles sweetly. "Or where one branch is only one level one higher than the other. Here, how about I get us started?"

And before you realize what she meant, those quick-moving hands have whisked your laptop away, and she ticks and taps away at your editor.

?- use_module(library(reif)).
:- discontiguous eval_prim/3.

Unconventional. You respect that. She continues:

eval_prim(Exp, _, Exp) :-
  Exp = nil ;
  Exp = [] ;
  number(Exp).

"Let's make up our trees out of... oh, I don't know, numbers? Lists of numbers? How about a nil, as a sentinel?"

Agree politely, while quietly wishing she would hand your laptop back. Suggest that she take the opportunity to summon a list from the void.

"What a great idea!"

eval_prim([first, List], Env, R) :-
  eval_exp(List, Env, ListR),
  if_(([] = ListR),
    R = nil,
    [R|_] = ListR).

eval_prim([rest, List], Env, R) :-
  eval_exp(List, Env, ListR),
  ((ListR = [], R = nil) ;
   (ListR = [_|R])).

eval_prim([cons, Head, Tail], Env, R) :-
  eval_exp(Head, Env, HeadR),
  eval_exp(Tail, Env, TailR),
  if_((nil = TailR), TailL = [], TailL = TailR),
  R = [HeadR | TailL].

She's read your Github, she explains cheerfully.

Ask about the middle argument. Sara pipes cheerfully about relations, and tells you nothing of value.

eval_prim([quote, R], _, R).

You ask again, and she ignores you. Did she even hear? The next words she types make your blood run cold.

bind(K, V, Env, Env2) :-
  atom(K),
  Env2 = Env.put(K, V).

"I bind you, Vidrun," Sara intones, and she is so much more than twenty-five. You snap your fingers, recalling the laptop to your hands--but she slams her forearm down upon the instrument, pinning it in place, and with her free hand evaluates the file.

Your hands go limp.

"I bind you head and tail."

bind([], _, Env, Env).
bind([K|Ks], Vs, Env, Env3) :-
  (K = &(K2),
   bind(K2, Vs, Env, Env3), !) ;
  ([] = Vs,
   bind(K, nil, Env, Env2),
   bind(Ks, [], Env2, Env3));
  ([V1|V1s] = Vs,
   bind(K, V1, Env, Env2),
   bind(Ks, V1s, Env2, Env3)).

Something dissevers in your spinal column, and your body slumps in the chair.

"To see only that which is given,"

eval_var(Var, Env, R) :-
  atom(Var),
  get_dict(Var, Env, R).

"And to do only that which is given." You recognize the shape of the spell now.

eval_each([], _, []).
eval_each([X | More], Env, [XR | MoreR]) :-
  eval_exp(X, Env, XR),
  eval_each(More, Env, MoreR).

"I close over you, Vidrun."

call_closure(Vars, Args, Body, Env, R) :-
  bind(Vars, Args, Env, Env2),
  eval_exp(Body, Env2, R).

The light dims, and your sense of the world outside fades. The quiet bustle of the office, the bikers whirring by on the street outside, the gentle murmur of the surf beyond; all these and more are lost.

"What may be let, must be."

eval_prim([let, [], Body], Env, R) :-
  eval_exp(Body, Env, R).
eval_prim([let, [K, V | More], Body], Env, R) :-
  eval_exp(V, Env, VR),
  bind(K, VR, Env, Env2),
  eval_prim([let, More, Body], Env2, R).

"And all your choices, fixed." Her voice is confident, rhythmic. She's practiced this, you realize. How long has she waited for this moment?

eval_prim([cond], _Env, nil).
eval_prim([cond, Default], Env, R) :-
  eval_exp(Default, Env, R).
eval_prim([cond, Test, Branch | More], Env, R) :-
  eval_exp(Test, Env, TestR),
  if_((nil = TestR),
    eval_prim([cond | More], Env, R),
    eval_exp(Branch, Env, R)).

"These things alone are yours: nothing and numbers, and the lists you so love,"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment