From 4dfad613bf4f9ef09485213bedd7311e47af7ebb Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 1 Jan 2018 23:00:01 +0100 Subject: [PATCH] mes: Support equal? with arbitrary number of arguments. * module/mes/base.mes (equal2?): Rename from equal?. (equal?): Implement. --- module/mes/base.mes | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/module/mes/base.mes b/module/mes/base.mes index ad66a987..54959aa7 100644 --- a/module/mes/base.mes +++ b/module/mes/base.mes @@ -1,7 +1,7 @@ ;;; -*-scheme-*- ;;; Mes --- Maxwell Equations of Software -;;; Copyright © 2016,2017 Jan Nieuwenhuizen +;;; Copyright © 2016,2017,2018 Jan Nieuwenhuizen ;;; ;;; This file is part of Mes. ;;; @@ -90,17 +90,23 @@ (define (and=> value procedure) (and value (procedure value))) (define eqv? eq?) -(define (equal? a b) ;; FIXME: only 2 arg +(define (equal2? a b) (if (and (null? a) (null? b)) #t (if (and (pair? a) (pair? b)) - (and (equal? (car a) (car b)) - (equal? (cdr a) (cdr b))) + (and (equal2? (car a) (car b)) + (equal2? (cdr a) (cdr b))) (if (and (string? a) (string? b)) (eq? (string->symbol a) (string->symbol b)) (if (and (vector? a) (vector? b)) - (equal? (vector->list a) (vector->list b)) + (equal2? (vector->list a) (vector->list b)) (eq? a b)))))) +(define (equal? . x) + (if (or (null? x) (null? (cdr x))) #t + (if (null? (cddr x)) (equal2? (car x) (cadr x)) + (and (equal2? (car x) (cadr x)) + (apply equal? (cdr x)))))) + (define (list? x) (or (null? x) (and (pair? x) (list? (cdr x)))))