switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
; -*- scheme -*-
|
|
|
|
|
2008-06-30 21:54:22 -04:00
|
|
|
; make label self-evaluating, but evaluating the lambda in the process
|
|
|
|
;(defmacro labl (name f)
|
|
|
|
; (list list ''labl (list 'quote name) f))
|
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (labl name f)
|
|
|
|
`(let (,name) (set! ,name ,f)))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
;(define (reverse lst)
|
|
|
|
; ((label rev-help (lambda (lst result)
|
2009-01-31 20:53:58 -05:00
|
|
|
; (if (null? lst) result
|
2008-06-30 21:54:22 -04:00
|
|
|
; (rev-help (cdr lst) (cons (car lst) result)))))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
; lst ()))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
(define (append- . lsts)
|
|
|
|
((label append-h
|
|
|
|
(lambda (lsts)
|
2009-01-31 20:53:58 -05:00
|
|
|
(cond ((null? lsts) ())
|
|
|
|
((null? (cdr lsts)) (car lsts))
|
|
|
|
(#t ((label append2 (lambda (l d)
|
|
|
|
(if (null? l) d
|
|
|
|
(cons (car l)
|
|
|
|
(append2 (cdr l) d)))))
|
|
|
|
(car lsts) (append-h (cdr lsts)))))))
|
2008-06-30 21:54:22 -04:00
|
|
|
lsts))
|
|
|
|
|
|
|
|
;(princ 'Hello '| | 'world! "\n")
|
|
|
|
;(filter (lambda (x) (not (< x 0))) '(1 -1 -2 5 10 -8 0))
|
|
|
|
(define (fib n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))
|
|
|
|
;(princ (time (fib 34)) "\n")
|
|
|
|
;(dotimes (i 20000) (map-int (lambda (x) (list 'quote x)) 8))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
;(dotimes (i 40000) (append '(a b) '(1 2 3 4) () '(c) () '(5 6)))
|
2008-06-30 21:54:22 -04:00
|
|
|
;(dotimes (i 80000) (list 1 2 3 4 5))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
;(set! a (map-int identity 10000))
|
|
|
|
;(dotimes (i 200) (rfoldl cons () a))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define (sort l)
|
2009-01-31 20:53:58 -05:00
|
|
|
(if (or (null? l) (null? (cdr l))) l
|
2008-11-05 23:04:04 -05:00
|
|
|
(let* ((piv (car l))
|
|
|
|
(halves (separate (lambda (x) (< x piv)) (cdr l))))
|
|
|
|
(nconc (sort (car halves))
|
2008-06-30 21:54:22 -04:00
|
|
|
(list piv)
|
2008-11-05 23:04:04 -05:00
|
|
|
(sort (cdr halves))))))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
2009-05-29 00:38:50 -04:00
|
|
|
#|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (dotimes var . body)
|
2008-06-30 21:54:22 -04:00
|
|
|
(let ((v (car var))
|
|
|
|
(cnt (cadr var)))
|
|
|
|
`(let ((,v 0))
|
|
|
|
(while (< ,v ,cnt)
|
|
|
|
(prog1
|
2009-05-29 00:38:50 -04:00
|
|
|
,(cons 'begin body)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(set! ,v (+ ,v 1)))))))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define (map-int f n)
|
2008-07-26 18:04:02 -04:00
|
|
|
(if (<= n 0)
|
|
|
|
()
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(let ((first (cons (f 0) ())))
|
|
|
|
((label map-int-
|
|
|
|
(lambda (acc i n)
|
|
|
|
(if (= i n)
|
|
|
|
first
|
2009-03-01 23:26:16 -05:00
|
|
|
(begin (set-cdr! acc (cons (f i) ()))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(map-int- (cdr acc) (+ i 1) n)))))
|
|
|
|
first 1 n))))
|
2009-05-29 00:38:50 -04:00
|
|
|
|#
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
|
|
|
|
(define-macro (labl name fn)
|
|
|
|
`((lambda (,name) (set! ,name ,fn)) ()))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
(define (square x) (* x x))
|
|
|
|
(define (expt b p)
|
|
|
|
(cond ((= p 0) 1)
|
|
|
|
((= b 0) 0)
|
2009-05-19 23:39:20 -04:00
|
|
|
((even? p) (square (expt b (div0 p 2))))
|
2009-01-31 20:53:58 -05:00
|
|
|
(#t (* b (expt b (- p 1))))))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
(define (gcd a b)
|
|
|
|
(cond ((= a 0) b)
|
|
|
|
((= b 0) a)
|
|
|
|
((< a b) (gcd a (- b a)))
|
2009-01-31 20:53:58 -05:00
|
|
|
(#t (gcd b (- a b)))))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
; like eval-when-compile
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (literal expr)
|
2008-06-30 21:54:22 -04:00
|
|
|
(let ((v (eval expr)))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(if (self-evaluating? v) v (list quote v))))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define (cardepth l)
|
2009-01-31 20:53:58 -05:00
|
|
|
(if (atom? l) 0
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(+ 1 (cardepth (car l)))))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define (nestlist f zero n)
|
2008-06-30 21:54:22 -04:00
|
|
|
(if (<= n 0) ()
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(cons zero (nestlist f (f zero) (- n 1)))))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define (mapl f . lsts)
|
2008-06-30 21:54:22 -04:00
|
|
|
((label mapl-
|
|
|
|
(lambda (lsts)
|
2009-01-31 20:53:58 -05:00
|
|
|
(if (null? (car lsts)) ()
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(begin (apply f lsts) (mapl- (map cdr lsts))))))
|
2008-06-30 21:54:22 -04:00
|
|
|
lsts))
|
|
|
|
|
|
|
|
; test to see if a symbol begins with :
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define (keywordp s)
|
2008-06-30 21:54:22 -04:00
|
|
|
(and (>= s '|:|) (<= s '|:~|)))
|
|
|
|
|
|
|
|
; swap the cars and cdrs of every cons in a structure
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define (swapad c)
|
2009-01-31 20:53:58 -05:00
|
|
|
(if (atom? c) c
|
2009-03-01 23:26:16 -05:00
|
|
|
(set-cdr! c (K (swapad (car c))
|
|
|
|
(set-car! c (swapad (cdr c)))))))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define (without x l)
|
2008-06-30 21:54:22 -04:00
|
|
|
(filter (lambda (e) (not (eq e x))) l))
|
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define (conscount c)
|
2009-01-31 20:53:58 -05:00
|
|
|
(if (pair? c) (+ 1
|
2008-06-30 21:54:22 -04:00
|
|
|
(conscount (car c))
|
|
|
|
(conscount (cdr c)))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
0))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
; _ Welcome to
|
|
|
|
; (_ _ _ |_ _ | . _ _ 2
|
|
|
|
; | (-||||_(_)|__|_)|_)
|
|
|
|
; ==================|==
|
|
|
|
|
|
|
|
;[` _ ,_ |- | . _ 2
|
|
|
|
;| (/_||||_()|_|_\|)
|
|
|
|
; |
|
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (while- test . forms)
|
2008-06-30 21:54:22 -04:00
|
|
|
`((label -loop- (lambda ()
|
|
|
|
(if ,test
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(begin ,@forms
|
2008-06-30 21:54:22 -04:00
|
|
|
(-loop-))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
())))))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
; this would be a cool use of thunking to handle 'finally' clauses, but
|
|
|
|
; this code doesn't work in the case where the user manually re-raises
|
|
|
|
; inside a catch block. one way to handle it would be to replace all
|
|
|
|
; their uses of 'raise' with '*_try_finally_raise_*' which calls the thunk.
|
|
|
|
; (try expr
|
|
|
|
; (catch (TypeError e) . exprs)
|
|
|
|
; (catch (IOError e) . exprs)
|
|
|
|
; (finally . exprs))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (try expr . forms)
|
|
|
|
(let ((final (f-body (cdr (or (assq 'finally forms) '(())))))
|
2008-06-30 21:54:22 -04:00
|
|
|
(body (foldr
|
|
|
|
; create a function to check for and handle one exception
|
|
|
|
; type, and pass off control to the next when no match
|
|
|
|
(lambda (catc next)
|
|
|
|
(let ((var (cadr (cadr catc)))
|
|
|
|
(extype (caadr catc))
|
|
|
|
(todo (f-body (cddr catc))))
|
|
|
|
`(lambda (,var)
|
|
|
|
(if (or (eq ,var ',extype)
|
2009-01-31 20:53:58 -05:00
|
|
|
(and (pair? ,var)
|
2008-06-30 21:54:22 -04:00
|
|
|
(eq (car ,var) ',extype)))
|
|
|
|
,todo
|
|
|
|
(,next ,var)))))
|
|
|
|
|
|
|
|
; default function; no matches so re-raise
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
'(lambda (e) (begin (*_try_finally_thunk_*) (raise e)))
|
2008-06-30 21:54:22 -04:00
|
|
|
|
|
|
|
; make list of catch forms
|
|
|
|
(filter (lambda (f) (eq (car f) 'catch)) forms))))
|
|
|
|
`(let ((*_try_finally_thunk_* (lambda () ,final)))
|
|
|
|
(prog1 (attempt ,expr ,body)
|
|
|
|
(*_try_finally_thunk_*)))))
|
|
|
|
|
|
|
|
(define Y
|
|
|
|
(lambda (f)
|
|
|
|
((lambda (h)
|
|
|
|
(f (lambda (x) ((h h) x))))
|
|
|
|
(lambda (h)
|
|
|
|
(f (lambda (x) ((h h) x)))))))
|
|
|
|
|
2008-07-14 20:06:42 -04:00
|
|
|
(define yfib
|
|
|
|
(Y (lambda (fib)
|
|
|
|
(lambda (n)
|
|
|
|
(if (< n 2) n (+ (fib (- n 1)) (fib (- n 2))))))))
|
|
|
|
|
|
|
|
;(defun tt () (time (dotimes (i 500000) (* 0x1fffffff 1) )))
|
|
|
|
;(tt)
|
|
|
|
;(tt)
|
|
|
|
;(tt)
|
2008-09-06 18:19:51 -04:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (accumulate-while cnd what . body)
|
2009-06-14 22:25:21 -04:00
|
|
|
(let ((acc (gensym)))
|
|
|
|
`(let ((,acc (list ())))
|
|
|
|
(cdr
|
|
|
|
(prog1 ,acc
|
|
|
|
(while ,cnd
|
|
|
|
(begin (set! ,acc
|
|
|
|
(cdr (set-cdr! ,acc (cons ,what ()))))
|
|
|
|
,@body)))))))
|
2008-09-10 22:37:38 -04:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (accumulate-for var lo hi what . body)
|
2009-06-14 22:25:21 -04:00
|
|
|
(let ((acc (gensym)))
|
|
|
|
`(let ((,acc (list ())))
|
|
|
|
(cdr
|
|
|
|
(prog1 ,acc
|
|
|
|
(for ,lo ,hi
|
|
|
|
(lambda (,var)
|
|
|
|
(begin (set! ,acc
|
|
|
|
(cdr (set-cdr! ,acc (cons ,what ()))))
|
|
|
|
,@body))))))))
|
2008-09-06 18:19:51 -04:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define (map-indexed f lst)
|
2009-01-31 20:53:58 -05:00
|
|
|
(if (atom? lst) lst
|
2008-09-06 18:19:51 -04:00
|
|
|
(let ((i 0))
|
2009-01-31 20:53:58 -05:00
|
|
|
(accumulate-while (pair? lst) (f (car lst) i)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(begin (set! lst (cdr lst))
|
|
|
|
(set! i (1+ i)))))))
|
2009-05-31 18:09:26 -04:00
|
|
|
|
|
|
|
(define (string.findall haystack needle . offs)
|
|
|
|
(define (sub h n offs lst)
|
|
|
|
(let ((i (string.find h n offs)))
|
|
|
|
(if i
|
|
|
|
(sub h n (string.inc h i) (cons i lst))
|
|
|
|
(reverse! lst))))
|
|
|
|
(sub haystack needle (if (null? offs) 0 (car offs)) ()))
|
2009-06-10 20:34:50 -04:00
|
|
|
|
|
|
|
(let ((*profiles* (table)))
|
|
|
|
(set! profile
|
|
|
|
(lambda (s)
|
|
|
|
(let ((f (top-level-value s)))
|
2009-06-14 22:25:21 -04:00
|
|
|
(put! *profiles* s (cons 0 0))
|
2009-06-10 20:34:50 -04:00
|
|
|
(set-top-level-value! s
|
|
|
|
(lambda args
|
2009-06-14 22:25:21 -04:00
|
|
|
(define tt (get *profiles* s))
|
|
|
|
(define count (car tt))
|
|
|
|
(define time (cdr tt))
|
2009-06-10 20:34:50 -04:00
|
|
|
(define t0 (time.now))
|
|
|
|
(define v (apply f args))
|
2009-06-14 22:25:21 -04:00
|
|
|
(set-cdr! tt (+ time (- (time.now) t0)))
|
|
|
|
(set-car! tt (+ count 1))
|
2009-06-10 20:34:50 -04:00
|
|
|
v)))))
|
|
|
|
(set! show-profiles
|
|
|
|
(lambda ()
|
2009-06-14 22:25:21 -04:00
|
|
|
(define pr (filter (lambda (x) (> (cadr x) 0))
|
|
|
|
(table.pairs *profiles*)))
|
|
|
|
(define width (+ 4
|
2009-07-08 15:07:56 -04:00
|
|
|
(apply max
|
2009-06-14 22:25:21 -04:00
|
|
|
(map (lambda (x)
|
|
|
|
(length (string x)))
|
|
|
|
(cons 'Function
|
|
|
|
(map car pr))))))
|
|
|
|
(princ (string.rpad "Function" width #\ )
|
|
|
|
"#Calls Time (seconds)")
|
|
|
|
(newline)
|
|
|
|
(princ (string.rpad "--------" width #\ )
|
|
|
|
"------ --------------")
|
|
|
|
(newline)
|
|
|
|
(for-each
|
|
|
|
(lambda (p)
|
|
|
|
(princ (string.rpad (string (caddr p)) width #\ )
|
|
|
|
(string.rpad (string (cadr p)) 11 #\ )
|
|
|
|
(car p))
|
|
|
|
(newline))
|
|
|
|
(simple-sort (map (lambda (l) (reverse (to-proper l)))
|
|
|
|
pr)))))
|
|
|
|
(set! clear-profiles
|
|
|
|
(lambda ()
|
|
|
|
(for-each (lambda (k)
|
|
|
|
(put! *profiles* k (cons 0 0)))
|
|
|
|
(table.keys *profiles*)))))
|
2009-06-10 20:34:50 -04:00
|
|
|
|
|
|
|
#;(for-each profile
|
|
|
|
'(emit encode-byte-code const-to-idx-vec
|
2009-06-14 22:25:21 -04:00
|
|
|
index-of lookup-sym in-env? any every
|
2009-06-10 20:34:50 -04:00
|
|
|
compile-sym compile-if compile-begin
|
2009-08-12 00:56:32 -04:00
|
|
|
compile-arglist expand builtin->instruction
|
|
|
|
compile-app separate nconc get-defined-vars
|
|
|
|
compile-in compile compile-f delete-duplicates
|
2009-06-10 20:34:50 -04:00
|
|
|
map length> length= count filter append
|
|
|
|
lastcdr to-proper reverse reverse! list->vector
|
|
|
|
table.foreach list-head list-tail assq memq assoc member
|
|
|
|
assv memv nreconc bq-process))
|
2009-07-28 00:16:20 -04:00
|
|
|
|
|
|
|
(define (filt1 pred lst)
|
|
|
|
(define (filt1- pred lst accum)
|
|
|
|
(if (null? lst) accum
|
|
|
|
(if (pred (car lst))
|
|
|
|
(filt1- pred (cdr lst) (cons (car lst) accum))
|
|
|
|
(filt1- pred (cdr lst) accum))))
|
|
|
|
(filt1- pred lst ()))
|
|
|
|
|
|
|
|
(define (filto pred lst (accum ()))
|
|
|
|
(if (atom? lst) accum
|
|
|
|
(if (pred (car lst))
|
|
|
|
(filto pred (cdr lst) (cons (car lst) accum))
|
|
|
|
(filto pred (cdr lst) accum))))
|
2009-08-12 00:56:32 -04:00
|
|
|
|
|
|
|
; (pairwise? p a b c d) == (and (p a b) (p b c) (p c d))
|
|
|
|
(define (pairwise? pred . args)
|
|
|
|
(or (null? args)
|
|
|
|
(let f ((a (car args)) (d (cdr args)))
|
|
|
|
(or (null? d)
|
|
|
|
(and (pred a (car d)) (f (car d) (cdr d)))))))
|