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 vernacor (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': ['💽'], '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. :)
Metadata
Release files for vernac 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| vernac-0.0.6.tar.gz | 20.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vernac-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.7 kB
Release files / vernac-0.0.6.tar.gz
| Download URL | vernac-0.0.6.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fe0251b6dec43455b1a6c5f465d80cab57fb4d468b821ff8eb817ea0317ecf21
|
|
BLAKE2b-256 checksum How to use checksums |
af745d28f00d65e51d7ab22c34a23799471b46e853f3e56d205fc775d1c3f680
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|
Release files / vernac-0.0.6-py3-none-any.whl
| Download URL | vernac-0.0.6-py3-none-any.whl |
|---|---|
| Size | 20.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8de52a532aeec0970819d8786898933e12de690c51f014c6ff41220f9ad95a6
|
|
BLAKE2b-256 checksum How to use checksums |
91f24ee06931c325bc35f7568d6df81c36a12c4205599409214e65d3df4a0b13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|
Security for vernac 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.