14
9
What exactly do you dislike?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
(defmacro until (test &body body)
(let ((start-tag (gensym "START"))
(end-tag (gensym "END")))
`(progn (setf $idx 0)
(tagbody ,start-tag
(when ,test (go ,end-tag))
(progn ,@body)
(incf $idx)
(go ,start-tag)
,end-tag))))
(until(= (setf x (random 10)) 0)
(format t "~d: ~d not 0 ~c" $idx x #Newline))
> (setf)
ERR: missing argument in function setf
(eval (setf code '(when (< counter 40)
(inc counter)
(println counter)
(eval code))))
(set 'f (lambda()
(if (< counter2 50)
(begin (println "Hi for the " (inc counter2) ". time. ")
(push (last f) f -1)
(if (> (length f) 3) (pop f 1))))))
(f)
(setf L '(1 2))
(map (lambda(x)(when (< x 10)
(push (+ x 2) L -1))
(println L))
L)
(setf [print.supressed] true [println.supressed] true) ; ----
(load "http://instprog.com/Instprog.default-library.lsp") ; only println= used
(setf [print.supressed] nil [println.supressed] nil) ; ----
(define-macro (flat-for-all)
(letn((L (args))
(r (cons 'and (map (lambda(x)(list (first L) x)) (rest L)))))
(print "{" r "}=")
(eval r)))
(println= (flat-for-all integer? 1 "hugo") "n")
(dolist (i '(integer? float? string? list?))
(letex((old-predicate i)
(new-predicate (sym (push "s" (string i) -2)))) ;float?->floats?
(define-macro (new-predicate)
(eval (append '(flat-for-all old-predicate)
(args))))
(println= new-predicate )))
(println= "n" (integers? 1 2 "hugo") "n"
(integers? 1 2 3 4) "n"
(floats? 1.5 6.1) "n"
(strings? "hi" "ho"))
(flat-for-all integer? 1 "hugo")={(and (integer? 1) (integer? "hugo"))}=nil;
integers?=(lambda-macro () (eval (append '(flat-for-all integer?) (args))));
floats?=(lambda-macro () (eval (append '(flat-for-all float?) (args))));
strings?=(lambda-macro () (eval (append '(flat-for-all string?) (args))));
lists?=(lambda-macro () (eval (append '(flat-for-all list?) (args))));
(integers? 1 2 "hugo")={(and (integer? 1) (integer? 2) (integer? "hugo"))}=nil;
(integers? 1 2 3 4)={(and (integer? 1) (integer? 2) (integer? 3) (integer? 4))}=true;
(floats? 1.5 6.1)={(and (float? 1.5) (float? 6.1))}=true;
(strings? "hi" "ho")={(and (string? "hi") (string? "ho"))}=true;
(setf original-eval eval)
(constant 'eval (lambda(x)(inc eval-counter)
(print eval-counter ": " x "=>")
(println (original-eval x))))
(eval '((lambda(x)(+ x 2)) 3)); works OK
; main program
(setf f (lambda(x)(+ x 2)))
(f 4) ; used original-eval, not eval
((eval 'setf) (eval 'f) (eval '(lambda(x)((eval '+) (eval 'x) (eval '2))))
((eval 'f) (eval '4)).