Migrated (filter) to the util module

Relocated as this function is required by the transform and library modules. Also rewrote it to use letrec instead of named let, as the latter is not support yet by cyclone.
This commit is contained in:
Justin Ethier 2015-06-25 21:14:06 -04:00
parent b94fc646fb
commit 5cf4481604
3 changed files with 23 additions and 13 deletions

View file

@ -2,6 +2,7 @@
(import (scheme base)
(scheme char))
(export
filter
tagged-list?
mangle
mangle-global)

View file

@ -273,19 +273,6 @@
env
(assq-remove-keys (assq-remove-key env (car keys)) (cdr keys))))
;; Simplified version of filter from SRFI 1
(define (filter pred lis)
(let recur ((lis lis))
(if (null? lis)
lis
(let ((head (car lis))
(tail (cdr lis)))
(if (pred head)
(let ((new-tail (recur tail)))
(if (eq? tail new-tail) lis
(cons head new-tail)))
(recur tail))))))
;; Data type predicates and accessors.

View file

@ -1,3 +1,10 @@
;;
;; Cyclone Scheme
;; Copyright (c) 2015, Justin Ethier
;; All rights reserved.
;;
;; This module contains various utility functions.
;;
(define (tagged-list? tag exp)
(if (pair? exp)
@ -15,6 +22,21 @@
(define (integer->char-list n)
(string->list (number->string n)))
;; Simplified version of filter from SRFI 1
(define (filter pred lis)
(letrec ((recur (lambda (lis)
(if (null? lis)
lis
(let ((head (car lis))
(tail (cdr lis)))
(if (pred head)
(let ((new-tail (recur tail)))
(if (eq? tail new-tail) lis
(cons head new-tail)))
(recur tail)))))))
(recur lis)))
;; Name-mangling.
;; We have to "mangle" Scheme identifiers into