• Stars
    star
    498
  • Rank 88,494 (Top 2 %)
  • Language
    Shell
  • License
    Mozilla Public Li...
  • Created almost 5 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A LISP that runs wherever Bash is

Fleck wordmark
Fleck is a Clojure-like LISP that runs wherever Bash is.

Fleck screencast

Note

This project is experimental and I am no longer actively working on it. If you need a feature or bug fixed, please send a PR with passing tests and I will review and merge it.

Thank you.

Get it

curl -s https://chr15m.github.io/flk/flk > flk && chmod 755 flk
./flk

Examples | Reference | Contributing | FAQ | make-a-lisp

What?

$ echo '(println "Hello world!") (println "Hostname:" (sh* "hostname")))' > example.clj
$ ./flk example.clj
Hello world!
Hostname: diziet

Why?

Now you can use a humble LISP to do Bash things. Bash as a scripting language has many edges, but it is everywhere. Fleck attempts to round off the edges.

Fleck runs on Bash 4 and higher.

How?

Almost all of this code is from the make-a-LISP project. All I've done is put together a simple Makefile to package it up into an easily deployable single-file bash script.

Reference

A list of variables, macros and functions that are present in Fleck.

Built-ins

This is the set of built-ins from the make-a-lisp project. These more or less work but are generally more limited in functionality than their Clojure equivalents. For example the addition function (+) can only add two integers at a time.

def! | defmacro! | if | do | fn* | try* | sh* | let* | quote | quasiquote | macroexpand | type | = | throw | nil? | true? | false? | string? | symbol | symbol? | keyword | keyword? | number? | fn? | macro? | pr-str | str | prn | println | readline | read-string | slurp | < | <= | > | >= | + | - | * | / | time-ms | list | list? | vector | vector? | hash-map | map? | assoc | dissoc | get | contains? | keys | vals | sequential? | cons | concat | nth | first | last | rest | empty? | count | apply | map | conj | seq | with-meta | meta | atom | atom? | deref | reset! | swap!

  • *ARGV* - list of arguments passed on the command line.

Aliases

These are wrappers around the limited make-a-lisp versions and are much more limited than the Clojure equivalents.

let | when | def | fn | defn

Mal extras

These functions are pulled from a selection of mal/lib/*.mal.

partial | inc | dec | zero | identity | reduce | foldr

Fleck extras

These functions are hand crafted Fleck specials designed to make common shell scripting tasks easier.

  • (str-replace STRING FIND REPLACE) - Replace all occurrences of the string FIND in STRING with the string REPLACE.
  • (str-split STRING SPLIT-CHARACTER) - Split STRING into a list of strings on the single characters SPLIT-CHARACTER.
  • (str-pos HAYSTACK NEEDLE) - Returns the position of string NEEDLE in string HAYSTACK or -1 if not found.
  • (str-upper-case STRING) - Converts string to all upper-case.
  • (str-lower-case STRING) - Converts string to all lower-case.
  • (str-capitalize STRING) - Converts first character of the string to upper-case, all other characters to lower-case.
  • (dc OPERATOR ARRAY-OF-NUMBERS) - Wraps the dc command to do decimal math. E.g. (dc '+ [1 2 3]) yeilds 6.
  • (env [KEY] [VALUE]) - Returns a hash-map of environment variables. Returns the value of KEY if present. Sets the value of KEY to VAL if the latter is present.
  • (sh! COMMAND ARGS) - Run a bash command with arguments in a subshell. Returns [stdout stderr return-code] from the resulting call.
  • (sh-env COMMAND) - Run a bash command string in the current shell, modifying current env, and return the stdout result (useful for export, source etc.).

Interop

  • (env [KEY] [VALUE]) - See above section.
  • (sh! COMMAND [ARGS]) - See above section.
  • (sh-env COMMAND) - See above section.
  • (sh* COMMAND) - Run arbitrary bash strings in a subshell and return the stdout result.

For examples of writing your own Fleck functions in Bash see src/extras.sh. Functions should set the special return value r and use mal type casting functions like _string to wrap the result in a reference. Internal Fleck functions such as _string automatically do this and can be used bare. Use _fref to make your function available to the Fleck namespace e.g. _fref "my-bash-function" _my_bash_function.

Compile

To compile flk itself run make. This combines the original mal scripts with various bash and flk functions into a single binary.

You can make a pure bash script from your Fleck script by bundling your script and Fleck together into a new script.

Say you have a Fleck script called wow.clj, you can bundle it as follows:

make DEST=wow INSERT=./wow.clj NOREPL=1

This will produce a new standalone script called wow with Fleck + wow.clj bundled together.

When you run wow the embedded wow.clj will be run by the embedded Fleck.

Contributing

Flk is built from the mal sources and uses its test framework.

To contribute please follow these guidelines:

  • Add any new bash functions to extras.sh as this is merged into mal at build time.
  • Add new flk functions into src in a new .clj file, and then add the file name to the LOCALMALS list in the Makefile so it gets included in the build.
  • Any changes, bugfixes, etc. to mal itself should be submitted upstream.
  • Document any new functions in this README.
  • Put unit tests for new functions in a .mal file in the tests folder, and to the Makefile test clause.

FAQ

Think of this as homoiconic Bash rather than Clojure, and code as if you're in Bash.

Will my favourite piece of Clojure run in this?

No, it's bash.

Some subset of Clojure-like code will run. See the documentation and examples.

How do I access command line arguments?

Use the special global list *ARGV*.

How do I access and modify environment variables?

Check the (env) function above. See also examples/environment-variables.clj.

How can I execute a one-liner of Fleck code?

Either of these methods will work:

flk <<< '(println "hi")'
echo '(println "hi")' | flk

Why can't I add more than 2 numbers together?

It's bash. Try the dc function: (dc '+ [1 2 3 4])

Where are the floating point numbers?

It's bash. Try the dc function for decimals: (dc '* [8.2 3.5])

dc is set to keep four fractional digits in its results.

How do I cast a string to a number?

Try (read-str "42") but also Bash doesn't care and (+ "1" 1) will yeild 2.

Why can't I iterate on a string?

Try (seq "somestring").

How do I do destructuring?

You can't.

How do I use a key/hash-map as a function in lookups?

You can't. You'll get an error with something like (:a {:a 12}) or ({:a 12} :a).

Instead you must use get like this: (get {:a 12} :a).

Can I use anything as a hash-map key?

Seems unlikely. Better stick to strings.

This is even slower than Python!

Yes.

PS That is not actually a question.

Haven't I seen this before somewhere?

You're probably thinking of Gherkin, the original Clojure-like LISP in Bash by Alan Dipert. Gherkin helped kick off the make-a-lisp revolution. You might also be thinking of babashka which is a bare-metal solution using real Clojure.

Why is it called Fleck?

At 36k and running on any machine with Bash 4, the name seemed appropriate.

 fleck

    n. A tiny mark or spot.
    n. A small bit or flake.

More Repositories

1

DoodleCSS

A simple hand drawn HTML/CSS theme
HTML
1,049
star
2

bugout

Back end web app services over WebRTC.
JavaScript
614
star
3

slingcode

personal computing platform
Clojure
410
star
4

sitefox

Node + cljs backend web framework
Clojure
290
star
5

awesome-clojure-likes

Curated list of Clojure-like programming languages.
184
star
6

rogule.com

A dungeon a day keeps the Balrog away
JavaScript
177
star
7

gitnonymous

Make pseudonymous Git commits over Tor
Shell
176
star
8

PodSixNet

Lightweight multiplayer network library for python games
Python
165
star
9

motionless

Generate static sites with code.
JavaScript
78
star
10

dirc

p2p IRC-inspired self-hosted web chat.
Clojure
77
star
11

blender-hylang-live-code

Live-coding Blender with Hy(lang)
Hy
69
star
12

jsGameSoup

Make games with Javascript.
JavaScript
66
star
13

roguelike-browser-boilerplate

A boilerplate for browser based Roguelike game development
JavaScript
62
star
14

PdDroidParty

Run Pure Data DSP patches on Android - native GUIs emulated.
Java
62
star
15

minimal-stylesheet

CSS to get a web app up and running
HTML
60
star
16

twiiit.com

A redirecting proxy for Nitter
JavaScript
55
star
17

build-decentralized-web-app

Build a decentralized web chat in 15 minutes
HTML
52
star
18

SyncJams

Network-synchronised metronome and state dictionary for music applications.
Pure Data
45
star
19

pd-ws

Websocket communication for Pure Data.
HTML
43
star
20

svg-flipbook

SVG flipbook animation with layers
Clojure
40
star
21

speccy

eight-bit algorave livecoding in clojurescript
Clojure
39
star
22

dreamtime

Peer-to-peer for shell scripts.
JavaScript
38
star
23

aish

Shell script one-liners right in your terminal prompt
Shell
23
star
24

webrtc-signaling-mesh

Decentralized signaling for WebRTC
Clojure
23
star
25

tweetfeast.com

Twitter sentiment analysis SaaS
JavaScript
23
star
26

ntpl

Manipulate and render HTML in Python
Python
22
star
27

frock

Clojure-flavoured PHP
PHP
22
star
28

aSid

Moog-like synth for Commodore 64
C
16
star
29

catch-all-errors

Catch all JavaScript errors and post them to your server
JavaScript
16
star
30

roguelike-celebration-2021

Talk: Building Juicy Minimal Roguelikes in the Browser
HTML
14
star
31

drillbit

Algorave drill-n-bass-ish music generator.
Hy
13
star
32

livereload.net

Browser live-reloading web dev tool
Clojure
11
star
33

lolPd

Tiny wrist-saving DSL for Pure Data.
Pure Data
11
star
34

pd-acid-core

303-style acid instrument for Pure Data.
11
star
35

PocketSync

App to sync pocket operator devices
HTML
11
star
36

media-remote

Reverse engineered S*ny "Android Media Remote" for nodejs
JavaScript
11
star
37

makesprite

Make game sprites with image generators
Clojure
11
star
38

create-sitefox-nbb

Get a ClojureScript + sitefox + nbb server with one command
Clojure
11
star
39

juice-it

CSS game juice animations
CSS
10
star
40

c64core

retrocompute aesthetics twitter bot
Clojure
10
star
41

hexadecimal-die

OpenSCAD script to generate a sixteen sided "spherical cap" style hexadecimal die.
OpenSCAD
10
star
42

ball-smash-dungeon

ball physics roguelike
Clojure
9
star
43

create-shadowfront

Quickly bootstrap ClojureScript + shadow-cljs + Reagent
JavaScript
7
star
44

bitcoin-random-oracle

Use the Bitcoin network as an entropy source.
Python
7
star
45

graphviz-livecoder

Live-code Graphviz
Makefile
7
star
46

sitefox-payments

Stripe subscriptions for Sitefox sites
Clojure
7
star
47

blockhead

A collection of Pure Data abstractions styled after rjlib.
Pure Data
7
star
48

speedy-spa

Fast loading material SPA test in LISP
CSS
7
star
49

algotracker

Algorithmic module tracker generator
JavaScript
6
star
50

motion

svg + react motion graphic experiments
Clojure
6
star
51

jqDeclare

jQuery plugin for React-style declarative UIs.
HTML
6
star
52

pd-algobreaks-core

Pure Data patches for making procedural breakbeats.
Pure Data
6
star
53

autotracker

Ben Russell's autotracker extended
Python
5
star
54

htabuilder

LISP to MS Windows HTA app experiment
JavaScript
5
star
55

marcus

Index and search browser bookmarks from the command line.
Hy
5
star
56

itwriter

Write Impulse Tracker modules with JavaScript
JavaScript
5
star
57

scittle-claude-ai

Prompt Claude AI for ClojureScript & Reagent web app artifacts.
HTML
5
star
58

pocketoperations.com

source code to this website
HTML
4
star
59

bitcoin-notebook

Reproduceable blockchain queries for science.
Python
4
star
60

GarageAcidLab

Pure Data patches and scripts that were used to create the squeakyshoecore records as well as the Android app.
Pure Data
4
star
61

riceprioritization.com

A web app to prioritize your options
Clojure
4
star
62

Infinite8BitPlatformer

User-created-content pixel-aesthetic multiplayer game.
Python
4
star
63

808-thing

Pure Data 808 rc-patches wrapper thing.
Pure Data
4
star
64

pd-net-sync

Utilities for synchronising the timing and data of Pure Data patches on a network.
Pure Data
4
star
65

cljs-ultralight

Utilities for making small ClojureScript UI artifacts
Clojure
4
star
66

michaelsoftproject.com

Simple online Gantt chart planner
JavaScript
4
star
67

pd-midi-guis

Abstractions for doing midi-learn buttons and faders in Pure Data.
Pure Data
3
star
68

sssad

Frank Barknect's sssad (state saving) Pure Data abstractions.
Pure Data
3
star
69

tiny-web-game-engine

Tiny game engine for the web
Clojure
3
star
70

reagent-node-render-demo

Demo of rendering a reagent component from nodejs
Clojure
3
star
71

blender-iso-render-bot

Blender script to render isometric sprites
Python
3
star
72

hexatron

Roguelike rendered minimally in three dimensions
Clojure
3
star
73

gba-gpio-tester

Test the GPIO hardware pins on your GBA.
Makefile
3
star
74

liveloops

Console mode audio looping from decades of yore.
C
3
star
75

MonsterVST

Build VST .dlls on Linux, cross compiled for Windows.
C++
3
star
76

cljs-dopeloop

Webaudio utils for dopeloop.ai
Clojure
3
star
77

bootstrappingthis.com

Landing page generator
JavaScript
3
star
78

weeklybeats-2016

Algorithmic rave music 2016
Hy
3
star
79

fugr

Web based RSS feed reader (stalled)
Python
3
star
80

CanOfBeats-droidparty

Procedural hip hop generator for mobile devices.
Pure Data
3
star
81

castpranker.com

Prank your family with chromecast!
HTML
3
star
82

decentral-utils

JavaScript function utils for web decentralization
JavaScript
3
star
83

php-image-paste-upload

PHP page where you can paste images to upload them
PHP
3
star
84

bugout-box

Bugout service manager
Clojure
3
star
85

dorcx

A personal social network built on your email box.
Python
3
star
86

pinfeed

Full-size Pinterest image feed.
HTML
3
star
87

scrypt-hashcash

Scrypt hashcash implementation for node & browsers.
JavaScript
3
star
88

DoodleRogue

A hand drawn roguelike tileset
Makefile
3
star
89

one-million-or-dead

(game) fear and greed and compound interest
Clojure
2
star
90

s-abstractions

A collection of abstractions for the Pure Data patching language
Python
2
star
91

rss-to-newsletter

Web app to turn your RSS feeds into newsletter posts
JavaScript
2
star
92

clojurescript-threejs-playground

Playing with Clojurescript and Three.js with figwheel in between
Clojure
2
star
93

create-sitefox-shadow-fullstack

Bootstrap a full stack Sitefox + shadow-cljs app
Clojure
2
star
94

HypeFrame

HTML5 game boilerplate WIP
JavaScript
2
star
95

emorogue

Roguelikes with emojis
Clojure
2
star
96

algorave-live-rig

Pure Data rig for live mixing algorave
Pure Data
2
star
97

GarageAcidLab-droidparty

Procedural acid for mobile devices.
Pure Data
2
star
98

pdvst-fx

Collection of PdVST music effects
Pure Data
2
star
99

bugout.network

CSS
2
star
100

gnu-linux-in-tiny-places-plug

Talk: GNU/Linux in tiny places (PLUG)
HTML
2
star