Skip to content

Commit

Permalink
Reduced dependencies to closer-mop, alexandria, and iterate.
Browse files Browse the repository at this point in the history
  • Loading branch information
smithzvk committed May 26, 2011
1 parent ef43db9 commit 2aba4c9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
8 changes: 8 additions & 0 deletions basic.lisp
Expand Up @@ -63,6 +63,14 @@
(setf (apply #'aref new-arr idx) new-val)
new-arr ))

;; @\section{Hash Table Manipulations}

;; @Same deal as arrays. Avoid using this for large hash tables which, quite
;; frankly, is the most common use case for any hash tables. It is just here
;; for completeness. If you are using a hash table and need to functionally
;; modify it many times, then use a functional dictionary structure, like an
;; FSet map or a FUNDS dictionary.

(define-modf-function gethash 2 (new-val key hash-table)
(let ((new-hash (alexandria:copy-hash-table hash-table)))
(setf (gethash key new-hash) new-val)
Expand Down
17 changes: 16 additions & 1 deletion fset.lisp
Expand Up @@ -3,14 +3,16 @@

;; @\section{FSet Integration}

;; @This works with seqs and maps.
;; @Lookup works with {\em seqs} and {\em maps}.

(define-modf-function fset:lookup 1 (new-val collection key)
(fset:with collection key new-val) )

(define-modf-rewrite fset:@ (expr)
`(fset:lookup ,@(rest expr)) )

;; @These are for {\em seqs} only.

(define-modf-function fset:subseq 1
(new-val collection start
&optional (end (fset:size collection)) )
Expand All @@ -36,3 +38,16 @@

(define-modf-rewrite fset:tail (expr)
`(fset:less-first ,@(rest expr)) )

;; @<<fset:arb>> works with everything. To be clear, this really doesn't make
;; the most sense, but it feels like it needs to be here for completeness. The
;; issue is that bags and sets have no concept of internal structure, they just
;; hold objects, so <<modf>> doesn't really make sense at all. You can,
;; however, place values into a bag or seq without regard to the internal
;; structure, which corresponds to pulling out a value from a bag or seq without
;; regard to internal structure. Thus <<fset:with>> is the inversion of
;; <<fset:arb>>.

(define-modf-function fset:arb 1 (new-val collection)
(fset:with collection new-val) )

14 changes: 4 additions & 10 deletions modf.asd
Expand Up @@ -7,17 +7,11 @@
"This library simplifies functional programming by making it easier to make
new data structures with specified changes in place."
:components ((:file "package")
(:file "utils")
(:file "modf")
(:file "rewrite-rules")
(:file "basic")
(:file "fset") )
(:file "basic"))
:serial t
:depends-on (:toolbox :iterate) )
:depends-on (:alexandria :iterate :closer-mop) )


(asdf:defsystem :modf-fset
:name "FSet extensions for MODF"
:author "Zachary Smith <zachkostsmith@gmail.com>"
:license "LLGPL"
:components ((:file "fset"))
:serial t
:depends-on (:toolbox :iterate :modf :fset) )
2 changes: 1 addition & 1 deletion modf.lisp
Expand Up @@ -39,7 +39,7 @@
;; <<>>=
(defmacro define-modf-rewrite (name (expr) &body body)
`(setf (gethash ',name *modf-rewrites*)
(/. (,expr)
(lambda (,expr)
,@body )))

;; <<>>=
Expand Down
15 changes: 8 additions & 7 deletions package.lisp
@@ -1,10 +1,11 @@

(defpackage :modf
(:use :cl :toolbox :iter)
(:export modf
modf-eval
define-modf-rewrite
define-modf-function
define-modf-method
define-modf-expander ))
(:use :cl :iter)
(:import-from :alexandria #:with-gensyms)
(:export #:modf
#:modf-eval
#:define-modf-rewrite
#:define-modf-function
#:define-modf-method
#:define-modf-expander ))

13 changes: 13 additions & 0 deletions utils.lisp
@@ -0,0 +1,13 @@

(in-package :modf)

;; @The point of this file is to remove big library dependencies by placing the
;; handful of functions I use here instead of keeping them in a big library.
;; This means that there is more code to maintain, but it also makes the library
;; more portable and means I can be much sloppier in my toolbox library, so I
;; guess it's a win.

(defun mkstr (&rest args)
"MaKe STRing"
(with-output-to-string (s)
(dolist (a args) (princ a s)) ))

0 comments on commit 2aba4c9

Please sign in to comment.