mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +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)
|
(import (scheme base)
|
||||||
(scheme char))
|
(scheme char))
|
||||||
(export
|
(export
|
||||||
|
filter
|
||||||
tagged-list?
|
tagged-list?
|
||||||
mangle
|
mangle
|
||||||
mangle-global)
|
mangle-global)
|
||||||
|
|
|
@ -273,19 +273,6 @@
|
||||||
env
|
env
|
||||||
(assq-remove-keys (assq-remove-key env (car keys)) (cdr keys))))
|
(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.
|
;; 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)
|
(define (tagged-list? tag exp)
|
||||||
(if (pair? exp)
|
(if (pair? exp)
|
||||||
|
@ -15,6 +22,21 @@
|
||||||
(define (integer->char-list n)
|
(define (integer->char-list n)
|
||||||
(string->list (number->string 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.
|
;; Name-mangling.
|
||||||
|
|
||||||
;; We have to "mangle" Scheme identifiers into
|
;; We have to "mangle" Scheme identifiers into
|
||||||
|
|
Loading…
Add table
Reference in a new issue