From fa73ddde5c2c3e7babb388799c78f3fdf1b1060c Mon Sep 17 00:00:00 2001 From: Liam Healy <liam@thinkpad.local> Date: Tue, 29 Jun 2010 19:50:14 -0400 Subject: [PATCH] Combinations working again with foreign-array Combinations working again with foreign-array, and improved return from combination-next and combination-previous. Return value from #'success-failure is now T or NIL. --- data/combination.lisp | 32 +++++++++++++++++--------------- gsll.asd | 4 ++-- init/interface.lisp | 5 +++-- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/data/combination.lisp b/data/combination.lisp index 3aea09bd..79252250 100644 --- a/data/combination.lisp +++ b/data/combination.lisp @@ -1,6 +1,6 @@ ;; Combinations ;; Liam Healy, Sun Mar 26 2006 - 11:51 -;; Time-stamp: <2010-06-29 08:55:43EDT combination.lisp> +;; Time-stamp: <2010-06-29 19:48:55EDT combination.lisp> ;; ;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy ;; Distributed under the terms of the GNU General Public License @@ -95,6 +95,7 @@ "Initialize the combination c to the lexicographically last combination, i.e. (n-k,n-k+1,...,n-1).") +#| (defmfun grid:copy-to-destination ((source combination) (destination combination)) "gsl_combination_memcpy" (((mpointer destination) :pointer) @@ -107,6 +108,7 @@ :documentation ; FDL "Copy the elements of the combination source into the combination destination. The two combinations must have the same size.") +|# ;;;;**************************************************************************** ;;;; Combination properties @@ -154,28 +156,28 @@ (defmfun combination-next (c) "gsl_combination_next" (((mpointer c) :pointer)) - :c-return :success-failure + :c-return (crtn :int) :inputs (c) :outputs (c) + :return ((when (success-failure crtn) c)) :documentation ; FDL - "Advance the combination c to the next combination - in lexicographic order and return T and c. If no further - combinations are available it return NIL and c with - c unmodified. Starting with the first combination and - repeatedly applying this function will iterate through all possible + "Advance the combination c to the next combination in lexicographic + order and return c. If no further combinations are available + it returns NIL. Starting with the first combination and repeatedly + applying this function will iterate through all possible combinations of a given order.") (defmfun combination-previous (c) "gsl_combination_prev" (((mpointer c) :pointer)) - :c-return :success-failure + :c-return (crtn :int) :inputs (c) :outputs (c) + :return ((when (success-failure crtn) c)) :documentation ; FDL - "Step backwards from the combination c to the - previous combination in lexicographic order, returning - T and c. If no previous combination is available it returns - NIL and c with c unmodified.") + "Step backwards from the combination c to the previous combination + in lexicographic order, returning c. If no previous combination is + available it returns NIL with c unmodified.") ;;;;**************************************************************************** ;;;; Examples and unit test @@ -188,15 +190,15 @@ (size comb)) (let ((comb (make-combination 4 2))) ; init-first, combination-next (init-first comb) - (loop collect (copy-seq (cl-array comb)) + (loop collect (grid:contents comb) while (combination-next comb))) (let ((comb (make-combination 4 2))) ; init-last, combination-previous (init-last comb) - (loop collect (copy-seq (cl-array comb)) + (loop collect (grid:contents comb) while (combination-previous comb))) (loop for i from 0 to 4 ; combination-next append (let ((comb (make-combination 4 i))) (init-first comb) - (loop collect (copy-seq (cl-array comb)) + (loop collect (grid:contents comb) while (combination-next comb))))) diff --git a/gsll.asd b/gsll.asd index 7357de6c..b4acbe94 100644 --- a/gsll.asd +++ b/gsll.asd @@ -1,6 +1,6 @@ ;; Definition of GSLL system ;; Liam Healy -;; Time-stamp: <2010-06-28 21:18:11EDT gsll.asd> +;; Time-stamp: <2010-06-29 19:26:27EDT gsll.asd> ;; ;; Copyright 2006, 2007, 2008, 2009 Liam M. Healy ;; Distributed under the terms of the GNU General Public License @@ -81,7 +81,7 @@ ;(:file "copy-cl") (:file "array-tests" :depends-on ("both")) (:file "permutation" :depends-on ("foreign-array" "array-structs")) - ;(:file "combination" :depends-on ("foreign-array" "array-structs")) + (:file "combination" :depends-on ("foreign-array" "array-structs")) )) #+(or) (:file "polynomial" :depends-on (init data)) diff --git a/init/interface.lisp b/init/interface.lisp index f251e524..2f130de0 100644 --- a/init/interface.lisp +++ b/init/interface.lisp @@ -1,6 +1,6 @@ ;; Macros to interface GSL functions, including definitions necessary for defmfun. ;; Liam Healy -;; Time-stamp: <2010-06-27 18:03:21EDT interface.lisp> +;; Time-stamp: <2010-06-29 19:42:14EDT interface.lisp> ;; ;; Copyright 2009 Liam M. Healy ;; Distributed under the terms of the GNU General Public License @@ -59,7 +59,8 @@ (defun success-failure (value) "If status is either +success+ or +continue+, return T; otherwise, return NIL." - (member value (list +success+ +continue+))) + (when (member value (list +success+ +continue+)) + t)) (defun success-continue (value) "If status is +success+, return T, otherwise return NIL." -- GitLab