Skip to main content

Write programs in English

Project description

Vernac: programming (in) language 📖

Vernac is a tool for writing software in "vernacular"—plain language.

Vernac isn't for turning English into code; it's for turning English into programs:

$ cat fizzbuzz.vn
print all the numbers between 1 and 100
print 'fizz' instead of the number if it’s divisible by 3
print 'buzz' if it’s divisible by 5
$ vernac fizzbuzz.vn -o fizzbuzz
$ ./fizzbuzz | head -n 5
1
2
fizz
4
buzz

Caution

Be careful: Vernac is an unstable and somewhat whimsical experiment.

You shouldn't use it in production. You might, however, find it more useful than you expect.

Motivation

To state the obvious: Vernac just does some LLM prompting and generates code under the hood.

Its value is in bundling together known prompts and annoying packaging steps so you can go from English to an executable program in one step.

The dream is that you check the English into git, not the code.

Every modern programmer already uses ChatGPT to generate code, then copies the code into their own source file. That’s a bit like writing your application in assembly and occasionally pasting in output from your compiler. Stay in the highest-level language you have for as long as you can! Today, in the GPT era, our highest-level language is English.

Usage

Prerequisites

  • Python 3.10+
  • OpenAI API key with GPT-4

Install

  • pip install vernac or (recommended →) pipx install vernac

Run

  • export OPENAI_API_KEY=<key>
  • vernac <source_in> -o <executable_out>

The executable bundles its dependencies except for a Python interpreter.

Examples

Hitting an API: emoji

ChatGPT may remember some stale information about an API, but often it's best to paste in relevant details:

- fetch all emoji from https://emojihub.yurace.pro/api/all
- if a keyword is given as command line arg, pick the emoji with the most similar name
- otherwise pick a random emoji
- convert its unicode code point into a character and print that

# references

the emojihub API returns data like this:

```
{'name': 'minidisc', 'category': 'objects', 'group': 'objects', 'htmlCode': ['&#128189;'], 'unicode': ['U+1F4BD']}
```

Writing tests: fizzbuzz-with-tests

Describe test cases and Vernac will run them during compilation:

accept N as a command line arg
print all the numbers between 1 and N
print 'fizz' instead of the number if it’s divisible by 3
print 'buzz' if it’s divisible by 5

# tests

do the right thing with N=20

Splitting code into modules: todo

Vernac can accept multiple input files. It will compile each one separately, guessing which are modules and which is the main program.

todo-storage.vn

# storage module

todo list entries have

- number
- description
- status (done, not done)

todo list entries are stored in `~/.todo` as a json list of objects

todo-tui.vn

# terminal-based todo list

todo list entries have

- number
- description
- status (done, not done)

## usage

- running the program shows a list of all todo list entries ordered by number
- one entry is selected at a time
- up/down arrow keys change the selection
- pressing d toggles the status of the selected entry
- pressing the del key removes the selected entry
- pressing c pops creates a new entry
- pressing s saves to the file
- pressing q saves and quits
- running with `--help` prints instructions and exits immediately

*Note: Ensure that any HTML strings are properly formatted, i.e., all tags are correctly opened and closed.*

## creating a new entry

- to create a new entry, present a dialog to the user
- it should have one text field to provide the description
- pressing esc should close the dialog without creating an entry
- new entries are selected automatically after they are created

Related work

FAQs

What prevents my programs from behaving differently every time I recompile?

Nothing.

What about non-English languages?

They are likely to work, but less likely than English.

This is a joke, right?

Is it? You tell me. :)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vernac-0.0.6.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

vernac-0.0.6-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file vernac-0.0.6.tar.gz.

File metadata

  • Download URL: vernac-0.0.6.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for vernac-0.0.6.tar.gz
Algorithm Hash digest
SHA256 fe0251b6dec43455b1a6c5f465d80cab57fb4d468b821ff8eb817ea0317ecf21
MD5 c4ec7112282c3b821faa50ae09c169b5
BLAKE2b-256 af745d28f00d65e51d7ab22c34a23799471b46e853f3e56d205fc775d1c3f680

See more details on using hashes here.

File details

Details for the file vernac-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: vernac-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for vernac-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f8de52a532aeec0970819d8786898933e12de690c51f014c6ff41220f9ad95a6
MD5 35f1096f614273fac6607be3c4081634
BLAKE2b-256 91f24ee06931c325bc35f7568d6df81c36a12c4205599409214e65d3df4a0b13

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page