{"id":19512423,"url":"https://github.com/vmchale/madlang","last_synced_at":"2025-04-26T04:31:34.531Z","repository":{"id":128761318,"uuid":"78316672","full_name":"vmchale/madlang","owner":"vmchale","description":"Madlang is a language for generative literature","archived":false,"fork":false,"pushed_at":"2018-07-10T07:08:22.000Z","size":2335,"stargazers_count":51,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-04T08:01:37.969Z","etag":null,"topics":["generative-art","generative-literature","haskell","language"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vmchale.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-08T02:24:28.000Z","updated_at":"2024-09-10T10:00:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"a419bce0-850b-4426-b2b3-ca7cd727d3e9","html_url":"https://github.com/vmchale/madlang","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmchale%2Fmadlang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmchale%2Fmadlang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmchale%2Fmadlang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmchale%2Fmadlang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vmchale","download_url":"https://codeload.github.com/vmchale/madlang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250931022,"owners_count":21509802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["generative-art","generative-literature","haskell","language"],"created_at":"2024-11-10T23:25:52.545Z","updated_at":"2025-04-26T04:31:34.521Z","avatar_url":"https://github.com/vmchale.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Madlang DSL for generating random text\n\n[![Windows build status](https://ci.appveyor.com/api/projects/status/github/vmchale/madlang?svg=true)](https://ci.appveyor.com/project/vmchale/madlang)\n[![Build Status](https://travis-ci.org/vmchale/madlang.svg?branch=master)](https://travis-ci.org/vmchale/madlang)\n[![Hackage](https://img.shields.io/hackage/v/madlang.svg)](http://hackage.haskell.org/package/madlang)\n\nThis is the Madlang DSL for generating text. You specify a template, and Madlang\nwill create randomized text from the template.\n\nMadlang is an interpreted language, written in Haskell. Madlang can be used as\nan EDSL for Haskell or using the command-line interpreter.\n\nMadlang is intended to explore computational creativity and provide an easy\nway to get started with generative literature.\n\n## Installation\n\n### Binary Releases\n\nHead over to the [releases\npage](https://github.com/vmchale/madlang/releases/latest) and grab a binary for\nyour platform. \n\n### Cabal\n\nIf you do not see you platform listed, you will have to install from source.\nDownload [cabal](https://www.haskell.org/cabal/download.html) and\n[GHC](https://www.haskell.org/ghc/download.html). Then:\n\n```bash\n $ cabal update\n $ cabal new-install madlang\n```\n\nYou may need to add `$HOME/.local/bin` to your `PATH`. To do so:\n\n```\n $ echo 'export PATH=$HOME/.local/bin:$PATH' \u003e\u003e $HOME/.bashrc\n $ source $HOME/.bashrc\n```\n\n## Tutorial\n\nThe smallest program possible in Madlang is simply a return declaration, viz.\n\n```madlang\n:return\n    1.0 \"heads\"\n    1.0 \"tails\"\n```\n\nThe `:return` tells us this that this will be the final value when run, while\nthe numbers in front of the strings denote relative weights. Save this as\n`gambling.mad`, and run\n\n```bash\n $ madlang run gambling.mad\n heads\n```\n\nNow let's try something a little more complicated:\n\n```madlang\n:define person\n    1.0 \"me\"\n    1.0 \"you\"\n\n:return\n    1.0 \"The only one of us walking out of this room alive is going to be \" person \".\"\n```\n\nA bit more sinister, perhaps. The `:define` statement there declares a new\n*identifier*, which we can later reference. Save this as `fate.mad` and run:\n\n```bash\n $ madlang run fate.mad\n The only one of us walking out of this room alive is going to be you.\n```\n\nWe can also refer to another identifier within a `:define` block.\n\n```madlang\n:define coin\n    1.0 \"heads\"\n    1.0 \"tails\"\n\n:define realisticCoin\n    1.0 coin\n    0.03 \"on its side\"\n\n:return realisticCoin\n```\n\nIn addition to identifiers, we can also define *categories*. Categories are just\ngroups of identifiers. We can define one like so:\n\n```madlang\n:define color\n    1.0 \"yellow\"\n    1.0 \"blue\"\n\n:define texture\n    1.0 \"soft\"\n    1.0 \"scratchy\"\n    1.0 \"dimpled\"\n\n:category adjective\n    | color\n    | texture\n\n:return\n    1.0 adjective\n```\n\nThen, when we can `adjective`, it will pick one of \"yellow\", \"blue\",…\n\"dimpled\" with equal probability.\n\nFinally, one of the most powerful features of `madlang` is the ability to\ninclude libraries in a file. Open the following and save it as `gambling.mad`:\n\n```madlang\n:library\n\n:define coin\n    1.0 \"heads\"\n    1.0 \"tails\"\n```\n\nThen, open the following and save it in the same directory as\n`realistic-gambling.mad`:\n\n```madlang\n:include gambling.mad\n\n:define realisticGambling\n    1.0 gambling-coin\n    0.03 \"on its side\"\n\n:return\n    1.0 realisticGambling\n```\n\nThen run it with:\n\n```bash\n $ madlang run realistic-gambling.mad\n```\n\n`madlang` comes with several libraries prepackaged. You can install\nthem for the current user with:\n\n```bash\n $ madlang install\n```\n\nTry this out:\n\n```\n:include colors.mad\n\n:define weirdDog\n    1.0 colors-color \"dog\"\n\n:return\n    1.0 \"On my walk today I saw a \" weirdDog \".\"\n```\n\n### EDSL\n\nYou can use Madlang as a Haskell EDSL, generating values of type `RandTok`.\nThis can be done a couple ways. One is to use the file embedder:\n\n```haskell\nrandomText :: RandTok\nrandomText = $(madFile \"mad-src/some-bot.mad\")\n```\n\nWhile the other is to use the `madlang` quasi-quoter:\n\n```haskell\nrandomText :: RandTok\nrandomText = [madlang|\n:include adjectives.mad\n\n:return\n    1.0 \"I am feeling very \" adjectives-adjective \" today.\"\n|]\n```\n\nYou can then transform this into a random text file with:\n\n```haskell\ngenerateText :: IO Text\ngenerateText = run randomText\n```\n\n### Examples\n\nThere is a Shakespearean insult generator available to test out at [my\nsite](http://blog.vmchale.com/madlang). For a look at using Madlang as an EDSL,\ncheck out my [recursion scheme\ngenerator](https://github.com/vmchale/recursion-schemata)\n\n## Tooling\n\n### Vim\n\nThere is a vim plugin available [here](https://github.com/vmchale/madlang-vim).\n\n### Project Templates\n\nThere is a project template bundled with\n[pi](https://github.com/vmchale/project-init), which you can install with\n\n```bash\n $ curl -LSfs https://japaric.github.io/trust/install.sh | sh -s -- --git vmchale/project-init\n```\n\nand invoke with\n\n```bash\n $ pi new madlang story\n```\n\nThere is also a templated project\n[here](https://github.com/vmchale/madlang-miso) that can be invoked via\n\n```bash\npi git vmchale/https://github.com/vmchale/madlang-miso story\n```\n\n### Manpages\n\nYou can view documentation for `madlang` on Linux, Mac, or BSD by typing:\n\n```bash\n $ man madlang\n```\n\n## Contributions\n\n### Guide\n\nContributions, bug reports, and feature requests are emphatically welcome.\nPlease see the `CONTRIBUTING.md` guide for more specific details.\n\n### Release Naming\n\nReleases are named using the `releases.mad` file found\n[here](https://hub.darcs.net/vmchale/madlang-releases). You will need to install\nthe standard libraries using\n\n```bash\n $ madlang install\n```\n\nbefore running\n\n```bash\n $ just name\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmchale%2Fmadlang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmchale%2Fmadlang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmchale%2Fmadlang/lists"}