Menu

Show posts

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

Messages - Kazimir Majorinc

#31
It works for local variables



> (let((x 1))(setf x 7)(* 2 x))

14


> (local(x)(setf x 8)(+ x 1))

9




What exactly do you dislike?
#32
In Common Lisp? Something like that:


(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))
#33
Whither newLISP? / (setf)
April 21, 2011, 07:35:06 PM
Currently:


> (setf)

ERR: missing argument in function setf

It would be consistent with existing possibility of (setf x 1 y 2 ...) and analogous to (let()...) and (expand '(x y) '()) to allow (setf) as legal. I didn't seen implementation of setf, but I guess that it might result in very small size and speed improvement as well. Same for (set) and (setq).
#34
newLISP in the real world / Re: Loop without Loops
April 20, 2011, 12:57:02 PM
(eval (setf code '(when (< counter 40)
                    (inc counter)
                    (println counter)
                    (eval code))))


or even better, "crawler-tractor"

                 
(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)


This last is particularly charmy because it doesn't use recursion and Lutz actually made some change so it doesn't result in stack overflow at all.



I tried to do same with map,


(setf L '(1 2))
(map (lambda(x)(when (< x 10)
                     (push (+ x 2) L -1))
               (println L))
     L)


but it doesn't work, i.e. original version of L is used, not modified version, perhaps some optimization. I guess that other functions are optimized on the same way. One can always use (sequence 1 50), but it looks too trivial, I think.



Finally, Lutz implemented Y-combinator from lambda-calculus in Newlisp:



http://www.newlisp.org/index.cgi?Y_Function">http://www.newlisp.org/index.cgi?Y_Function
#35
I'm enjoying it!

But I have a feeling that my wife will put the veto in few minutes.
#36
Whither newLISP? / Re: Least common multiple?
March 31, 2011, 09:53:22 PM
Intelligence agency informed me that kosh implemented one lcm : https://gist.github.com/897015">//https://gist.github.com/897015
#37
Additionally, if you insist on minimal syntax, you can play with fexprs (macros).


(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"))

Output:
(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;
#38
Yes it is even better.

I have 1900x1200.
#39
I like the concept, It seems very practical.

This is http://www.instprog.com//various/nl-manual-layout.png">how it looks on my computer.

Perhaps you can pack upper part even denser.
#40
Whither newLISP? / Re: Two small design issues
March 23, 2011, 04:15:17 PM
Yes, it was that.

If it was turned off because of efficiency issues, OK, since it is really minor issue.
#41
Whither newLISP? / Two small design issues
March 23, 2011, 01:42:05 PM
I see two possibilities for small design improvement, worth only if implementation is simple and there is little loss of speed.



First - extending constant so it works on local bindings as well. It is less probable that one need it, however, it is not completely impossible (especially because local binding is dynamic as well) and it would make the feature more orthogonal. Constant already works in form (constant '<variable name>).



Second - extending set so it can be applied on "implicit indexing". If



(set 'X 5) = (setf X 5)



then why not



(set '(L 1) 5) = (setf (L 1) 5)?
#42
(eval (extend '(map append) (map quote '(("one" "two")("for" "you")))))

(map (fn(x)(apply append x)) (transpose '(("one" "two")("for" "you"))))
#43
Whither newLISP? / Least common multiple?
March 11, 2011, 12:15:21 PM
It appears that Newlisp doesn't have least common multiple, right? If not, I propose the addition (with name lcm), at least because of symmetry: its "pair", gcd is already here - alone.



Btw, support for real numbers is impressive: beta, gamma, erf, Fourier's transformation. How these functions found their way to Newlisp?
#44
I remember that Ted once proposed it, but I do not remember if it was implemented on any way.
#45
Currently, user defined eval is limited on explicit occurences:


(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


Although this example only show need for such eval on top level, it is simplified example; redefined eval should replace all implicit calls of eval. Why not using explicit eval everywhere where it is needed? Because code would explode to something like


((eval 'setf) (eval 'f) (eval '(lambda(x)((eval '+) (eval 'x) (eval '2))))
((eval 'f) (eval '4)).


Not impossible, but troublesome.