Skip to content

Instantly share code, notes, and snippets.

@zonuexe
Created October 4, 2012 08:44
Show Gist options
  • Select an option

  • Save zonuexe/3832304 to your computer and use it in GitHub Desktop.

Select an option

Save zonuexe/3832304 to your computer and use it in GitHub Desktop.
ShellSclisp

ShellSclisp

How to use

  1. launch terminal, and type bash -i
  2. . ./shellsclisp.sh ( . known as source )
  3. interactive lisp shell!!!

examples

$ (+ 1 $(\* 2 3))          # 1 + (2 * 3) => 6
$ (+ 1 2 3 4 5 6 7 8 9 10) # => 55
$ (/ 10 0)                 # expr: division by zero

copyright

ShellSclisp -- Lisp like functions in Bash
2012 USAMI Kenta <tadsan@zonu.me>

This snippet in licensed under GPL Version 3 and NYSL Version 0.9982 ( in English unofficial ) .

car () { echo $1; }
cdr () { shift; echo ${@}; }
cons () { echo $@; }
atom () { test $# = 1; }
eq () { test "$1" = "$2" ; }
IF () { eval $1; if [ $? = 0 ]; then e=$2; else e=$3; fi; eval $e; }
+ () { if [ $# = 0 ]; then false; elif [ $# = 1 ]; then echo $1; else echo $(expr $1 + $(+ $(cdr ${@}))); fi }
- () { if [ $# = 0 ]; then false; elif [ $# = 1 ]; then echo $1; else echo $(expr $1 - $(- $(cdr ${@}))); fi }
* () { if [ $# = 0 ]; then false; elif [ $# = 1 ]; then echo $1; else echo $(expr $1 \* $(\* $(cdr ${@}))); fi }
/ () { if [ $# = 0 ]; then false; elif [ $# = 1 ]; then echo $1; else echo $(expr $1 / $(/ $(cdr ${@}))); fi }
# むかしやった気がするもの
# https://github.com/zonuexe/rec-on-bash/tree/master/lib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment