mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
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:
parent
b94fc646fb
commit
5cf4481604
3 changed files with 23 additions and 13 deletions
|
@ -2,6 +2,7 @@
|
|||
(import (scheme base)
|
||||
(scheme char))
|
||||
(export
|
||||
filter
|
||||
tagged-list?
|
||||
mangle
|
||||
mangle-global)
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
22
util.scm
22
util.scm
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue