From 7d389ab0367b1b1c679e85a858f3eda12e14dfb3 Mon Sep 17 00:00:00 2001 From: tony Date: Wed, 7 May 2008 15:23:06 +0200 Subject: [PATCH] check-sequence fixed -- but starting real approach, which is to use generics and methods for select. --- compound.lsp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/compound.lsp b/compound.lsp index 5c31283..c0b5488 100644 --- a/compound.lsp +++ b/compound.lsp @@ -348,11 +348,13 @@ Returns a list of the indices where elements of sequence X are not NIL." (defun check-sequence (a) ;; FIXME:AJR: does this handle consp as well? (Luke had an "or" ;; with consp). - (if (not (typep a 'sequence)) - (error "not a sequence - ~s" a))) + (if (not (or (typep a 'sequence) + (consp a))) + (error "not a sequence or cons - ~s" a))) + -;;; Sequence Element Access +;;; Sequence Element Access ;;; (elt x i) -- NOT. This is more like "pop". (defun get-next-element (x i) @@ -600,6 +602,21 @@ in the original array." ;;; SELECT function ;;; +(defgeneric select (x &rest args) + "Selection of data, Args: (a &rest indices) + +A can be a list or an array. If A is a list and INDICES is a single +number then the appropriate element of A is returned. If is a list and +INDICES is a list of numbers then the sublist of the corresponding +elements is returned. If A in an array then the number of INDICES +must match the ARRAY-RANK of A. If each index is a number then the +appropriate array element is returned. Otherwise the INDICES must all +be lists of numbers and the corresponding submatrix of A is +returned. SELECT can be used in setf.") + +;;(defmethod select ((x list) &rest args)) +;;(defmethod select ((x array) &rest args)) + (defun select (x &rest args) "Args: (a &rest indices) -- 2.11.4.GIT