Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: matrix operations

126 views
Skip to first unread message

WJ

unread,
Oct 26, 2012, 6:36:17 AM10/26/12
to
Barry Margolin wrote:

> (defun (all-elements-equal (list)
> (destructuring-bind (head . tail) list
> (every #'(lambda (x) (equal x head))
> tail))))
>
> (defun any-rows-equal (matrix)
> (any #'all-elements-equal matrix))

Racket:

(define (all-elements-equal xlist)
(match-define (list head tail ...) xlist)
(andmap (curry equal? head) tail))

(define (any-rows-equal matrix)
(ormap all-elements-equal matrix))

WJ

unread,
Dec 5, 2012, 9:27:55 PM12/5/12
to
WJ wrote:

> Barry Margolin wrote:
>
> > (defun (all-elements-equal (list)
> > (destructuring-bind (head . tail) list
> > (every #'(lambda (x) (equal x head))
> > tail))))

The fellow didn't even test that once; he merely
assumed that he was infallible.

It ought to have been:

(defun all-elements-equal (list)
(destructuring-bind (head . tail) list
(every #'(lambda (x) (equal x head))
tail)))

This is another example of the insufferable, overweening pride
of worshippers of Commune Lisp.


EMACS Lisp:

(require 'cl)

(defun* all-elements-equal ((head . tail))
(every (apply-partially 'equal head) tail))

WJ

unread,
Dec 27, 2012, 1:28:35 AM12/27/12
to
newLISP:

(define (all-elements-equal lst)
(apply = lst))

(define (any-rows-equal matrix)
(exists all-elements-equal matrix))

(any-rows-equal
'((a b c d)
(2 3 4 5)
("q" w e r)
(9 9 9 9)))

==> (9 9 9 9)

(any-rows-equal
'((a a a a)
(2 3 4 5)
("q" w e r)
(9 9 9 9)))

==> (a a a a)

WJ

unread,
Dec 24, 2013, 9:36:34 AM12/24/13
to
Clojure:

(defn any-row-equal [matrix]
(some #(apply = %) matrix))

jdi...@gmail.com

unread,
Dec 24, 2013, 3:45:07 PM12/24/13
to
Doesn't the (require 'cl) command defeat the purpose of providing a non-CL example?

WJ

unread,
Apr 10, 2015, 3:17:41 AM4/10/15
to
WJ wrote:

> Barry Margolin wrote:
>
> > (defun (all-elements-equal (list)
> > (destructuring-bind (head . tail) list
> > (every #'(lambda (x) (equal x head))
> > tail))))

Gauche Scheme:

(define (all-elements-equal list)
(every (cute equal? <> (car list)) (cdr list)))

WJ

unread,
Apr 24, 2016, 5:22:00 PM4/24/16
to
Why this is marked as abuse? It has been marked as abuse.
Report not abuse
OCaml:

let rec all_equal = function
[] | [_] -> true
| x::y::tail -> if x=y then all_equal (y::tail) else false ;;

--
"Anti-racism," Shamir writes, "is a denial of the autochthon's [native's] right
to decide his fate; a tool to separate Man from his native landscape. This
concept de-legitimizes objections to swamping a land with a flood of immigrants
and ruining the society's fabric."
www.theoccidentalobserver.net/authors/Connelly-Gaza2.html
0 new messages