Coder Social home page Coder Social logo

sigma's Introduction

License

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Christopher Mark Gore nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Introduction

This is a library of utility functions that I use in ANSI Common Lisp. I find them useful, and hopefully you will too. Most of the code should work in any ANSI Common Lisp, but I use SBCL exclusively and some of the code will assume that and only work there. You will need a working and modern ASDF system.

How To Use

First we need to clone the utilities.

 % mkdir -p ~/programming/lisp
 % cd ~/programming/lisp
 % git clone [email protected]:cgore/sigma.git

Now we need to make a directory for our project and symlink to the ASDF definition. There are other ways to load ASDF libraries, especially if you want to have them available globally; I strongly recommend you read the documentation to ASDF.

 % mkdir our-new-project
 % cd our-new-project
 % ln -s ~/programming/lisp/sigma/sigma.asd

Now we need to start up our Lisp REPL. The best way to do this for perfonal use is SLIME from within Emacs, but I will demonstrate using the shell itself here.

 % sbcl

Now we are in SBCL.

 (require :asdf) ; Require ASDF
 (asdf:operate 'asdf:load-op 'sigma) ; Require the system via ASDF.
 (sigma:use-all-sigma) ; This will pollute COMMON-LISP-USER
 (sum (loop for i from 1 to 100 collect i)) ; Returns 5050 and makes Euler sad.

Have fun!

sigma's People

Contributors

cgore avatar

Stargazers

Mike Ferrara avatar  avatar Amaury Hernandez-Aguila avatar  avatar  avatar

Watchers

 avatar James Cloos avatar

sigma's Issues

implement macro-alias

There should be a macro-alias that works about the same as function-alias, just for macros. Actually doing this was confusing to me for some reason, so I'll come back to it later.

factorial is a naive implementation

The factorial function is a naive implementation that only works for positive integers, and slowly at that. This should be re-implemented. This also affects the choose function.

sigma/os is missing #+sbcl/#-sbcl conditionals

such as:

(defun ruby (&rest code)
"This is a simple function to easily call Ruby code snippets. It is far
from a full interface, instead just a convenient little script runner."
#+sbcl
(sb-ext:run-program ruby-path
`("-e" ,(apply #'strcat code))
:output t)
#-sbcl (error "Please implement ~S for ~A" 'ruby (lisp-implementation-type)))

or better, use uiop/run-program:run-program.

multicond doesn't respect the lexical scope

The following test fails, because the use of eval doesn't honor the lexical scope.

(behavior 'multicond
  (should-equalp '(positive positive)
                 (let ((r '())
                       (x 12))
                   (multicond ((oddp x)  (push 'odd      r))
                              ((evenp x) (push 'even     r))
                              ((< x 0)   (push 'negative r))
                              ((< 0 x)   (push 'positive r)))
                   r)))

Create a memoize macro

This shouldn't be a simple variant like from Paul Graham's On Lisp; instead, something complex like in Clojure.

stringify is wrong too.

(defun stringify (argument)
"The STRINGIFY function takes in an argument of any type and converts it to a
string. Also see TO-STRING."
(with-standard-io-syntax (format nil "~A" argument)))

Or, if you want to keep "As is to-string. And why are there two functions todo the same thing?"
then your test cases are wrong, and with-standard-io-syntax should wrap them instead.

*print-case* (and other such variable) can be set by the user!

Therefore this fails:

sigma/sequence> (assert (equal (join-symbol-to-all-preceeding :foo '(:bar :foo :baz :foo))
'(:barfoo :bazfoo)))

Debug: Failed assertion: (equal (join-symbol-to-all-preceeding :foo '(:|barfoo| :foo :baz :foo)) '(:barfoo :bazfoo))
While executing: (:internal swank::invoke-default-debugger), in process repl-thread(188).
Type :GO to continue, :POP to abort, :R for a list of available restarts.
If continued: test the assertion again.
Type :? for other options.
1 > :q
; Evaluation aborted on #<simple-error #x3020052BBFCD>.
sigma/sequence> print-case
:downcase
cl-user>

Instead of format ~A, use:
(intern (concatenate 'string (prin1-to-string previous) (string symbol)) "KEYWORD"))

Implement -> from Clojure.

This is a "thread-first" macro. It is so that you can write
(-> x (foo y) (bar z) (baz w))
Instead of
(baz (bar (foo x y) z) w)
Which is supposed to be a bit clearer.
I think this should be named both "thread-first" and "->"

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.