From: ············@gmail.com
Subject: Made an evaluator with support for infinite data, does anyone know  other implementations of this idea ?
Date: 
Message-ID: <1192973612.363782.228020@i13g2000prf.googlegroups.com>
The code works , but it's quite slow . :)

Some examples to try are:
(subseq  prime-nrs  0 7)
(subseq (remove-if (lambda (x)(= (rem x 2) 0) ) nat-nr ) 0 5 )  ;the
first five odd natural numbers
(leaf (left (left (rigth (left my-tree))))) ;my-tree is an infinite
labeled binary tree .

To start if , (lazy-start) .
It's based upon the following ideas :
1)A lazy if .
2)(car (cons x y)) is x
3) (cdr (cons x y) is y
It doesn't support cond and let yet .Use if and lambda instead .
Here is the code :

;the main functions of the lazy evaluator:
;in the lazy-evaluator , defun and setq will be  .defun and .setq .
(defvar  *data* '())
(defmacro .defun (name args body) `(setq *data* (cons (quote (,name
(lambda ,args ,body))) *data*)) )
(defmacro .setq (name body) `(setq *data* (cons  (quote (,name ,body))
*data*)))
(defun exists (arg)(assoc arg *data*))
(defun value (code) (cadr (exists code)))

(defun helpy-eval ( code) (if (atom code) code
                              (cond ((member (car code) '(car cdr) )
(apply (car code) (list (helpy-eval (cadr code)))))
                                ((eq (car code) 'quote) (cadr code))
                                ((eq (car code) 'lambda)   code )

                                ((eq (car code ) 'atom) (let ((tx
(lazy-rewrite (cadr code))))
                                                          (if (atom
tx) T (if  (eq (car tx) 'cons) 'NIL  (apply 'atom (list (helpy-eval
tx)) )))))
                                (T (apply (car code) (mapcar #'lazy-
eval (cdr code)))))))
(defun lazy-eval (code )(if (and (listp code) (member (car code)
'(.defun .setq))) (eval code) (helpy-eval (lazy-rewrite code )) ))
(defun expand (code)(if (atom code)
                        (if (exists code)(value code)code) (mapcar
#'expand code) ))
(defun lazy-rewr
ite (code )   (if (atom code) (if (exists code)
                                                  (lazy-rewrite (value
code) ) code)
                                  (let ((firs (lazy-eval (car code))))
                                    (if (atom firs)
                                        (if (eq firs 'if ) (lazy-
rewrite (if (lazy-eval (cadr code) ) (caddr code) (cadddr code)))
                                            (if (member firs '(car
cdr))
                                                (let ((stuff  (lazy-
rewrite (cadr code))))
                                                  (if (eq (car stuff)
'cons)
                                                      (lazy-rewrite
                                                       (if (eq firs
'car) (cadr stuff) (caddr stuff)))
                                                      (list firs
stuff) )) code))
                                        (lazy-rewrite (let (
                                                            (*data*
(mapcar #'list (cadr firs) (cdr code))))
                                                        (expand (caddr
firs))))
                                        ))))

;down here , some basic functions :
(defun str-eq (x y) (eq x y))
(.defun and (x y)(if x (if y T )))
(.defun eq (x y) (and (and (atom x) (atom y)) (str-eq x y)))
(.defun null(data)(eq data NIL))
(.defun remove-if (fun data)(if (null data) NIL
                                (if (fun (car data) )
                                    (remove-if fun (cdr data) )
                                    (cons (car data) (remove-if fun
(cdr data) ) ))) )

( .defun subseq (data begin end)
 (if (= begin 0)
     (if (= end 0) 'nil
         (cons (car data) (subseq (cdr data) begin (- end 1))))
     (subseq (cdr data) (- begin 1) (- end 1))))

(defun lazy-start () (loop (write (lazy-eval (read) ) ))) ;execute
(lazy-start) to

;from here  , some infinite functions :

(.defun nt (n)(cons n (nt (+ n 1))))
(.setq nat-nr (nt 0)) ; <- behold , the natural nubers  :P ;

(.defun primes (nrf) (cons (car nrf)
                           (primes (remove-if (lambda (x)  (= (rem x
(car nrf )) 0) ) (cdr nrf)))))
(.setq prime-nrs (primes (nt 2))) ;behold , the prime numbers :P ;

(.defun trex (x) (cons x (cons (trex (* x 2) ) (trex (+ (* x 2)
1) ) )))
(.defun left (tree)(car (cdr tree)))
(.defun rigth (tree)(cdr (cdr tree)))
(.defun leaf (tree) (car tree))
(.setq my-tree  (trex 1)) ;behold , an infinite labeled binary
tree :p ;

;Memoization implemented in a quick-and-dirty way . Oferrs slight
increase in performance .Memonization can be deactivated by
conveniently removing the code below  :P ;
(defun memoize (fn)
  (let ((cache (make-hash-table :test #'equal)))
    #'(lambda (&rest args)
        (multiple-value-bind (val win) (gethash args cache)
          (if win
              val
              (setf (gethash args cache)
                    (apply fn args)))))))
(setq g (memoize #'lazy-eval))
(setq h (memoize #'lazy-rewrite))
(defun lazy-eval (c)(funcall g c))
(defun lazy-rewrite (c)(funcall h c))
;this code if in case of execution :
(lazy-start)
;Well that's about it ; Feel free to modify and use this mess  ...
errr ...  code , but don't take all the credit for it , the flaws are
my fault . :))

From: ············@gmail.com
Subject: Re: Made an evaluator with support for infinite data, does anyone know other implementations of this idea ?
Date: 
Message-ID: <1192973790.332552.225620@q3g2000prf.googlegroups.com>
Posting the code appears to have un-formated it . Sorry about that .  :
(
From: Slobodan Blazeski
Subject: Re: Made an evaluator with support for infinite data, does anyone know other implementations of this idea ?
Date: 
Message-ID: <1192986622.663247.49270@k35g2000prh.googlegroups.com>
On Oct 21, 6:36 am, ············@gmail.com wrote:
> Posting the code appears to have un-formated it . Sorry about that .  :
> (

Try reposting the code at http://paste.lisp.org/ it's PITA to read.

cheers
Slobodan Blazeski