Thursday , April 22 2021

chr15m / flk, Hacker News


                    

        

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

Fleck screencast

curl -s https: // chr 15 m.github.io/flk/flk>flk&&chmod 755 flk ./flk

Examples|Reference|FAQ|make-a-lisp

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

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.

Almost all of this code is from themake- a-LISPproject. All I’ve done is put together a simple Makefile to package it up into an easily deployable single-file bash script.

A list of 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 numbers at a time.

def!Defmacro!ifdoFN *Try *sh *let *quoteQuasiquotemacroexpandtype=thrownil?true?false?string?symbolsymbol?keywordkeyword?number?fn?macro?pr-strstrPRNprintlnreadlineread-stringslurp>>=-*/time-mslistlist?vectorVector?hash-mapmap?Assocdissocgetcontains?keysvalssequential?consConcatnthfirstrestempty?countapplymapconjSEQwith-metametaATOMAtom?DerefReset!Swap!

Extras

These functions are defined in Fleck itself or pulled in from themal / lib /folder.

pprintstr-replacestr-split

  • (str-replace STRING FIND REPLACE)– Replace all occurrences of the stringFINDinSTRINGwith the string REPLACE .
  • (str-split STRING SPLIT-CHARACTER) (Split) ****************************** (STRING) into a list of strings on the single characters (SPLIT-CHARACTER) .

Aliases

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

letwhendefFNdefn

You can compile your Fleck script to a one which runs in pure Bash without Fleck. This works by bundling the Fleck sources with your script. Say you have a Fleck script calledwow.clj, you can compile it as follows.

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

This will produce a new standalone executable script calledwowwhich will bundlewow.cljinto Fleck and it will be called at run time.

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

Will my favorite piece of Clojure run in this?

No, it’s bash.

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

It’s bash. Try invoking bc:(sh * "bc

Where are the floating point numbers?

It’s bash. Try invoking bc:(sh * "bc

Why can’t I iterate on a string?

It’s bash. Try(seq "somestring").

How do I do destructuring?

You can’t.

Why is it called Fleck?

At (k and running on any machine with Bash, the name seemed appropriate.)

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

  

Brave Browser
Read More
Payeer

About admin

Check Also

financial district san francisco

Financial District San Francisco, hilton

financial district san francisco , hilton Financial District San Francisco is tourist attraction place it is …

Leave a Reply

Your email address will not be published. Required fields are marked *