2009-09-28 08:57:29 +00:00
|
|
|
;; p l a n t e y e s [ copyright (c) 2009 foam vzw : gpl v3 ]
|
|
|
|
|
2009-07-13 11:39:34 +00:00
|
|
|
#lang scheme/base
|
|
|
|
(provide (all-defined-out))
|
|
|
|
|
2009-07-13 15:01:20 +00:00
|
|
|
; just some stuff which is probably defined in standard schemish somewhere
|
|
|
|
|
2009-07-13 11:39:34 +00:00
|
|
|
(define (assoc-remove k l)
|
|
|
|
(cond
|
|
|
|
((null? l) '())
|
|
|
|
((eq? (car (car l)) k)
|
|
|
|
(assoc-remove k (cdr l)))
|
|
|
|
(else
|
|
|
|
(cons (car l) (assoc-remove k (cdr l))))))
|
|
|
|
|
|
|
|
(define (choose l)
|
|
|
|
(list-ref l (random (length l))))
|
|
|
|
|
|
|
|
(define (list-contains k l)
|
|
|
|
(cond
|
|
|
|
((null? l) #f)
|
|
|
|
((eq? (car l) k) #t)
|
|
|
|
(else (list-contains k (cdr l)))))
|
|
|
|
|
2009-07-21 16:33:26 +00:00
|
|
|
(define (string-split s c)
|
|
|
|
(define (_ sl tl cl)
|
|
|
|
(cond
|
|
|
|
((null? sl) (if (null? cl) tl (append tl (list (list->string cl)))))
|
|
|
|
((eq? (car sl) c)
|
|
|
|
(_ (cdr sl) (append tl (list (list->string cl))) '()))
|
|
|
|
(else
|
|
|
|
(_ (cdr sl) tl (append cl (list (car sl)))))))
|
|
|
|
(_ (string->list s) '() '()))
|
|
|
|
|
|
|
|
(define (list-string-concat l t)
|
|
|
|
(cond
|
|
|
|
((null? l) "")
|
|
|
|
(else
|
2009-07-22 15:35:15 +00:00
|
|
|
(string-append (car l) t (list-string-concat (cdr l) t)))))
|
|
|
|
|
|
|
|
; returns a list of items in a but not in b
|
|
|
|
(define (list-remainder a b)
|
|
|
|
(cond
|
|
|
|
((null? a) '())
|
|
|
|
((not (list-contains (car a) b)) (cons (car a) (list-remainder (cdr a) b)))
|
2009-07-24 19:02:49 +00:00
|
|
|
(else (list-remainder (cdr a) b))))
|
|
|
|
|
|
|
|
(define (which-element k l n)
|
|
|
|
(cond
|
|
|
|
((null? l) #f)
|
|
|
|
((eq? (car l) k) n)
|
2009-09-28 08:57:29 +00:00
|
|
|
(else (which-element k (cdr l) (+ n 1)))))
|
2009-10-26 15:00:45 +00:00
|
|
|
|
|
|
|
(define (last l)
|
|
|
|
(cond ((null? (cdr l)) (car l))
|
|
|
|
(else
|
|
|
|
(last (cdr l)))))
|