;;; -*-scheme-*- ;;; Mes --- Maxwell Equations of Software ;;; Copyright © 2016 Jan Nieuwenhuizen ;;; ;;; base.mes: This file is part of Mes. ;;; ;;; Mes is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; Mes is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Mes. If not, see . (define (identity x) x) (define else #t) ;; IF based (define-macro (or . x) (if (null? x) #f ;; IF (if (null? (cdr x)) (car x) ;; IF (list 'if (car x) (car x) (cons* 'or (cdr x)))))) (define-macro (and . x) (if (null? x) #t ;; IF (if (null? (cdr x)) (car x) ;; IF (list 'if (car x) (cons 'and (cdr x)) ;; IF #f)))) (define (not x) (if x #f #t)) (define (equal? a b) ;; FIXME: only 2 arg (if (and (null? a) (null? b)) #t ;; IF (if (and (pair? a) (pair? b)) (and (equal? (car a) (car b)) (equal? (cdr a) (cdr b))) (if (and (string? a) (string? b)) ;; IF (eq? (string->symbol a) (string->symbol b)) (if (and (vector? a) (vector? b)) ;; IF (equal? (vector->list a) (vector->list b)) (eq? a b)))))) (define (memq x lst) (if (null? lst) #f ;; IF (if (eq? x (car lst)) lst ;; IF (memq x (cdr lst))))) (define guile? (not (pair? (current-module)))) (define (map f l . r) (if (null? l) '() ;; IF (if (null? r) (cons (f (car l)) (map f (cdr l))) ;; IF (if (null? (cdr r)) ;; IF (cons (f (car l) (caar r)) (map f (cdr l) (cdar r))))))) (define-macro (simple-let bindings . rest) (cons (cons 'lambda (cons (map car bindings) rest)) (map cadr bindings))) (define-macro (let bindings . rest) (cons* 'simple-let bindings rest))