Giter VIP home page Giter VIP logo

shcl's Introduction

SHCL: Shell Meets Common Lisp

SHCL is

  1. a very customizable shell made with secret alien technology, and
  2. an unholy union of POSIX Shell and Common Lisp.

Behold Common Lisp embedded in POSIX shell embedded in Common Lisp! Notice that the Common Lisp form embedded in the shell expression can access the lexical environment.

(let ((rld "rld"))
  (capture (:stdout)
    #$ echo Hello ,(concatenate 'string "Wo" rld) | wc -c #$))
; => "12"

Now lay your eyes on a lisp function participating in a pipeline!

shcl> : ,(shcl/core/debug:graph-dependencies) | dot -Tpng > graph.png

Building SHCL

SHCL is only really tested against SBCL, but it should be portable to other lisp compilers. Be aware that ECL is known to be problematic because it tries to reap child processes automatically.

First, you’ll need to install some dependencies. To start with, you’ll need Clang and libedit. There’s also some Common Lisp dependencies that need to be taken care of: SBCL, Quicklisp, and cffi-grovel. If you’re new to building Common Lisp projects, you might want to let Roswell set up your lisp environment for you.

# Set up Clang, libedit, and Roswell
make LISP='ros -s cffi-grovel run --'

You can skip Roswell if you want. Just make sure that you set LISP to a command that runs SBCL with Quicklisp and cffi-grovel loaded. For example,

# Set up Clang, libedit, SBCL, and Quicklisp
QUICKLISP_SETUP=~/quicklisp/setup.lisp # or wherever you installed quicklisp
make LISP="sbcl --no-userinit --load \"$QUICKLISP_SETUP\" --eval '(ql:quickload :cffi-grovel)'"

Example Usage

I don’t know what you’re expecting to see here. Its a POSIX-like shell. You can do (almost) all your normal POSIX shell stuff in it.

shcl> echo foobar
foobar
shcl> FOO=$(echo echo foo; false) || echo assignment returned false
assignment returned false
shcl> $FOO
foo
shcl> { echo foobar ; echo baz ; echo blip ; } | tail -n 1
blip
shcl> shcl-enable-lisp-syntax
shcl> if [ ,(+ 1 2 3) = ,(* 2 3) ]; then
> echo woah
> fi
woah
shcl> shcl-repl
shcl (lisp)> (format t "Hello world~%")
Hello world
NIL
shcl (lisp)> (define-builtin set-env (&option print &required var value)
> (loop :for str :across print :do (format t "~A~%" str))
> (setf (env var) value)
> 0)
SET-ENV
shcl (lisp)> ^D
shcl> set-env --print hi --print there VAR value | wc -l
2
shcl> echo $VAR
value
shcl> ^D

Okay, actually, that kind of went off the rails.

shcl's People

Contributors

phmarek avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.