[MATRIX-SIG] reverse of take?

Steven D. Majewski sdm7g@Virginia.EDU
Thu, 26 Jun 1997 22:21:38 -0400 (EDT)


I've only followed this discussion lightly ( in some, but perhaps not
all of it's several incarnations ), but since others have mentioned how 
S and some other math languages  support scatter-gather, I'll offer one
more language for comparison: ( Mainly because the "plumbing" is more
visible in this example. ) 

 LispStat is a version of Lisp oriented to interactive statistics
 and statistical graphics. Some of the capabilities may have been
 inspired by S+ and some other numerical and statistical packages.

LispStat extends many Lisp functions to vectorized versions, for example:
	>( * 10 ( iseq 10 ))
	(0 10 20 30 40 50 60 70 80 90)
	>( * ( iseq 10 ) ( iseq 10 ))
	(0 1 4 9 16 25 36 49 64 81)

This includes comparison functions, which yield a list of boolean values:
	> ( setf x ( normal-rand 10 ))
	(0.38107432228578 1.96131809922812 2.36068411946823 1.19178363587238
	-0.885422972877445 -0.564994188286439 1.04135377723368 -0.595475370701372
	0.941913771141252 0.899280862970745)
	> ( > x 0 )
	(T T T T NIL NIL T NIL T T)

There is a function 'which', which yields a list of the indexes that are 
non-nil: 

	> ( which ( > x 0 ))
	(0 1 2 3 6 8 9)

and a select function that takes a sequence and either an index or 
a list of indexes:

	( select x 3 )
	1.19178363587238
	> ( select x ( which ( > x 0 )))
	(0.38107432228578 1.96131809922812 2.36068411946823 1.19178363587238
	1.04135377723368 0.941913771141252 0.899280862970745)

And which can be used as an argument to SETF:

	( setf ( select x ( which ( < x 0 ))) 0 )
	0
	> x
	(0.38107432228578 1.96131809922812 2.36068411946823 1.19178363587238 0 0
	1.04135377723368 0 0.941913771141252 0.899280862970745)


 The value arg to SETF can be a single value or a list of values,
but if they are both lists, the index list and the value list
have to match in length. 


---|  Steven D. Majewski   (804-982-0831)  <sdm7g@Virginia.EDU>  |---
---|  Department of Molecular Physiology and Biological Physics  |---
---|  University of Virginia             Health Sciences Center  |---
---|  P.O. Box 10011            Charlottesville, VA  22906-0011  |---
All power corrupts and obsolete power corrupts obsoletely." - Ted Nelson


_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________