BOOTSTRAPPING ★ 153 upvotes 2014

Replacing `import` with `accio`: A Dive into Bootstrapping and Python's Grammar

The Founder's Submission

Direct narrative and submission text authored by @ThePhysicist on Hacker News:

Summary of Blog Post (I'm not the author):

At Hacker School, I've been building an alternate universe Python by overwriting builtin functions and statements with Harry Potter spells. This is a thing you can do at Hacker School!

Retrospective Overview & Key Insights

Distilled analysis of the business dynamics, operational challenges, and strategic takeaways:

Published in 2014, this chronicle by @ThePhysicist details the mechanics of building a profitable, self-funded business without venture backing.

Core Principles for Independent Builders:
1
Charging customers from day one acts as the ultimate filter for building software that solves genuine, high-urgency problems.
2
Keeping fixed overhead low and leveraging lean infrastructure allows founders to stay alive until market tailwinds kick in.
3
Small, repetitive improvements in customer retention and conversion rates yield massive returns over multi-year horizons.
Community Debate Themes:

The community focused on B2B customer acquisition channels, cold email vs SEO distribution, and balancing full-time employment with side-project development.

Community Discussions & Critical Reviews

High-signal perspectives, counter-arguments, and peer founder insights debated on Hacker News (28 total discussions):

LA @lawl Peer Contributor

I'm not a python programmer. But shouldn't this be possible at runtime by modifying the AST to change it back to import in the AST? That way you could have a module you can just include to run this without a custom interpreter.

Edit: Looks like this is doable by messing with the tokenizer: http://stackoverflow.com/questions/214881/can-you-add-new-statements-to-pythons-syntax

You could create a loader.py where you tokenize the script yourself, and replace accio with a custom import that again loadds imports by tokenizing them yourself first. And then after you've modified the tokens you should be able to build a valid AST and run it :)

I'm pretty sure you can just throw a SyntaxError there yourself too if you encounter a real "import".

Nice hack nevertheless.

LV @lvh Peer Contributor

Awesome hack!

Did you consider import hooks to accomplish this? Of course that wouldn't make your bootstrap language any different; that'd still be vanilla python. In the imported file you can do whatever you want, for example the inimitable paultag implemented hy, a python lisp, using those.

VA @varenc Peer Contributor

its probably easier to add custom syntax to python by using custom encodings. The dropbox pyxl library does this. Details: https://github.com/dropbox/pyxl#implementation-details

JO @jodrellblank Peer Contributor

I was expecting the magic to be changing

``` import math x = math.ceil(y)

``` into

``` x = accio ceil(y)

``` and having it Just Magically Work (tm).

But it's a nice write up of recompiling Python with a changed grammar.

DA @dalek2point3 Peer Contributor

this is such a great assignment for a principles of programming languages class. there is no better way to learn something than to break it up, change it and make it do your wish. i'm going to be teaching my next batch of muggles this.

HISTORICAL ERA Cloud & Mobile Era (2014–2019)
COMMUNITY SCORE ★ 153 points
TOTAL DISCUSSIONS 28 comments
TOPICS & TECH STACK: