Promoting my blog.

Notices and updates
Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Thanks.

I called them 'supernatural' because it appears that they know what happens around them very first moment they are mentioned in the program.

This is how I did it: Lutz just said that symbols are inserted into symbol table (symbol) during some preparation phase of the expression evaluation. So, symbols are already in (symbol) on the beginning of the evaluation of some block - even if subexpressions that mention these simbols for a first time weren't evaluated yet.

Only thing I needed to do is to remember list (symbol) before begin block, and then again on the beginning of the block. The difference between these two contains exactly variables used in block.

Code is for a dramatic effect hidden in the function self-conscious-symbols. But in essence, it is:

Code: Select all

(set 'symbols-initially (symbols))

(begin (dolist(x (difference (symbols)           ;this list contains
                             symbols-initially)) ;Sri ... and x only
                             
              (set x (string "Hi. My name is " x ". Ohm...")))
               
       (println Sri-Aurobindo))
       
; Hi. My name is Sri-Aurobindo. Ohm...
Did I adressed the issue that interested you?

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

very nice kazimir ! -> http://www.instprog.com/Instprog.default-library.lsp

perhpas 'nice' is an understatement here ;-)
-- (define? (Cornflakes))

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Thanks. It is perpetually in "experimental" phase, running tests etc, but in long terms I'll put it in some prettier form.

Excalibor
Posts: 47
Joined: Wed May 26, 2004 9:48 am
Location: Madrid, Spain

Post by Excalibor »

newdep wrote:very nice kazimir ! -> http://www.instprog.com/Instprog.default-library.lsp

perhpas 'nice' is an understatement here ;-)
Agreed! I already use it and abuse it, so thanks for the great work.

Now, returning to supernatural symbols, I think I get the idea... It's interesting, though, as it came to my mind this could be used to make functions that shape themselves at evaluation time depending on outside knowledge (via (symbols)) at the moment of evaluation... Maybe it's a silly idea, but it could allow not just self-mutating functions, but also evolutionary ones?

Just a quick thought...

When's your next blog entry coming? :-)

laters and thanks!

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Thanks again, Excalibor.

No, I do not think it is silly idea, quite contrary, it is interesting idea. Analogies with physical world are very promissing.

I think I'll have new post in 2-3 hours.

itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Post by itistoday »

Great blog Kazimir! I worked through your genlet function and modified it a bit to avoid some variable capture possibilities, as well as changing it to support both forms of 'let' (i.e: (let (i 0) .. ) vs. (let ((i 0)) .. )):

Code: Select all

(define-macro (genlet)
	(if (list? (args 0 0))
		; (genlet ((var1 val1) (var2 val2)) ... )		
		(letex
			( 	H1 (map (fn (x) (list (x 0) '(gensym))) (args 0))
				H2 (args 0)
			  	H3 (cons 'begin (rest (args)))
				H4 (cons 'begin	(map
									(fn (x) (list 'delete (list 'quote (x 0))))
								(args 0)))
			)
			(letex H1 (first (list (let H2 H3) H4)))
		)		
		; (genlet (var1 val1 var2 val2) ... ) => convert to other form
		(letex (H1 (cons 'genlet (cons (explode (args 0) 2) (rest (args)))))
			(eval H1)
		)
	)
)
Get your Objective newLISP groove on.

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Thanx, itistoday.

I have noted that actually letex does different thing than I though initially. I thought that

(letex((x 1))(f x))

is equivalent to

(f 1)

while local binding of x to 1 does not exist in time of evaluation. It turned it is not true, as can be seen from this code:

Code: Select all

(set 'x 100)
(letex ((x 1))
      (print (eval (sym "x")))

(exit)
It evaluates to - 1, not to 100.

It happens because

(letex((x 1))(f x something))

is actually

(let ((x 1))(eval (expand '(f x something) 'x))

and not

(eval (let ((x 1))(expand '(f x something) 'x))

as I thought to be. So, x=1 binding is actually alive in moment of eval. It might cause overshadowing of some outer x. That's why I have to replace all letex with "manual" combination of eval and expand.

Lutz, maybe letex should be replaced or supported with evlex?
Last edited by Kazimir Majorinc on Sun Apr 05, 2009 6:14 pm, edited 1 time in total.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Yes, it is the local version of 'x' which gets expanded, and the body of the 'letex' expression gets evaluated in the local scope. Like in a simple 'let', the locals shadow the outer scope.

'letex' is like a 'let' plus expansion of locals in the body before the evaluation of that body. You take out the expansion and have a normal 'let'.

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Two new items:

* On macroexpansion.
* Crawler tractor.

Image

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Hi Kazimir,

I did not see my feedback on you blog so im posting it here..

Im getting a Stack error when using your infinite loop function push/pop.
(Crawler Tractor)

ERR: call stack overflow : pop <8060DC0>
called from user defined function f

That is a little odd i think because your function is in my eyes not
consuming memory/stack... It is though hitting the 64bit barrier, but
then the newlisp error message is wrong...

btw..nice pictures..heheh Real! Enginering..
-- (define? (Cornflakes))

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Same for me, at

"Hi for the 790000. time."

(sys-info) suggests that number of Lisp cells - is growing all the time. It appears that pop doesn't release memory.

Yes, vehicle is great. Landwasserschlepper from 1936.

axtens
Posts: 28
Joined: Mon Apr 06, 2009 12:23 pm
Location: Perth, WA Australia
Contact:

Post by axtens »

While we're on the subject of blogs, I've just made my first newLISP posting on my own blog

Kind regards,
Bruce.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

The error message is misleading and will be changed, its not the call stack but the result-stack from ORO management which never gets cleared in Kazimir's self modifying function, which never returns. Under normal circumstances 'pop' will release memory.

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Lutz, is there a chance to make this normal circumstance? Or at least to add some command for manual memory release in that case?

One advantage of the ORO concept might be that functions know their reference, being it some symbol, like x, or expression like (L 1). Any chance for that? Sorry if I asked for that already, I forgot.

Very interesting blog, axtens. Impressive number of programming languages.

I encourage everyone to start writting blog because it really helps. Helps in what? To initiate or increase communication about topics you want to communicate.

axtens
Posts: 28
Joined: Mon Apr 06, 2009 12:23 pm
Location: Perth, WA Australia
Contact:

Post by axtens »

Kazimir Majorinc wrote:Very interesting blog, axtens. Impressive number of programming languages.

I encourage everyone to start writting blog because it really helps. Helps in what? To initiate or increase communication about topics you want to communicate.
Thanks for the encouragement. Yes, maintaining a weblog is good on a variety of levels, including as practice in making technical writing comprehensible.

-- Bruce.

cgs1019
Posts: 5
Joined: Wed Apr 08, 2009 8:12 pm
Location: Gainesville, FL
Contact:

Post by cgs1019 »

Kazimir Majorinc wrote:Thanx, itistoday.
Lutz, maybe letex should be replaced or supported with evlex?

Code: Select all

(eval (letex ((x 1)) '(f x)))
quoting the expr and wrapping in eval does the trick for me[/code]
-- Christopher Suter

"The only reason for time is so that everything doesn't happen at once."
Albert Einstein

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Kazimir, this is an issue with the maximum of consecutive blocks/statements in a lambda function. The same case it taken care of in all loops and many other statements which iterate in some form and regularly free memory. Introducing this mechanism to lambda and lambda-macro functions would cost too much overhead.

Keeping lambda and lambda-macro overhead at an absolute minimum is important for Lisp, as good Lisp programming style favors smaller functions. At the moment a cleanup only occurs upon leaving the function. For normal programming purpose ~4000 statements-blocks in one function are more than enough.

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Lutz wrote:Keeping lambda and lambda-macro overhead at an absolute minimum is important for Lisp, as good Lisp programming style favors smaller functions. At the moment a cleanup only occurs upon leaving the function.
OK, then maybe in future when speed will be even less critical than today.
cgs1019 wrote:

Code: Select all

(eval (letex ((x 1)) '(f x)))
Yes, you're right it is simpler than

Code: Select all

(eval (let ((x 1))
             (expand '(f x) 'x)))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

but this:

Code: Select all

(eval (letex ((x 1)) '(f x))) 
is the same as this:

Code: Select all

(letex ((x 1)) (f x))
'letex' does evaluate after expanding

itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Post by itistoday »

Lutz wrote:'letex' does evaluate after expanding
That reminds me of something I wanted to ask you. In the 'genlet' code that I gave above, why do I have to have the extra 'eval' here:

Code: Select all

      (letex (H1 (cons 'genlet (cons (explode (args 0) 2) (rest (args)))))
         (eval H1)
      )
But not here:

Code: Select all

      (letex
         (    H1 (map (fn (x) (list (x 0) '(gensym))) (args 0))
            H2 (args 0)
              H3 (cons 'begin (rest (args)))
            H4 (cons 'begin   (map
                           (fn (x) (list 'delete (list 'quote (x 0))))
                        (args 0)))
         )
         (letex H1 (first (list (let H2 H3) H4)))
      )
Get your Objective newLISP groove on.

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

There is a subtle difference - in the case of letex, in the moment of evaluation local binding is still alive, in the case of eval-letex-quote, it is not.

Code: Select all

(set 'y 'x)
(println (let ((x 2))
              (eval (letex((x 1))
                         '(+ (eval y) x))))) ;=>3 because y => outer x

(println (let ((x 2))
              (letex((x 1))
                    (+ (eval y) x)))) ;=>2 because y => inner x
                 
(exit)

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Kazimir:
yes, you are right, but it wouldn't make a difference. If the expression to expand has free variables, they would bind to the environment outside the 'letex' anyway and all locals are expanded ;-)

Also, the right side of the assignment in the 'letex' locals is always evaluated in the parent environment:

Code: Select all

> (set 'y 1) 
(letex ((x y) (y 2)) '(x y)) => (1 2)
Itistoday:
'letex', 'unify' and 'expand' (which is used by the first two) do not make expansion on the top level. So this:

Code: Select all

> (letex (expr '(+ 1 2 3)) expr) => (+ 1 2 3)
is just the same as this:

Code: Select all

(let (expr '(+ 1 2 3)) expr) => (+ 1 2 3)
to avoid 'expr' beeing the top level do:

Code: Select all

> (letex (expr '(+ 1 2 3)) (begin expr))
6
> 

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Well, maybe eval-let-expand has a bit more sense than let-eval-expand, maybe both have sense, but it is not really that important as long as one knows what can he expect.

However, I noted one thing that could be significant problem, and maybe one that is smaller problem:

Code: Select all

(println (letex ((x 'y)) x))      ; => y 
(println (letex ((x 'y)) 'x))     ; => y 




(set 'x 4)
(expand 'x 'x)  ;=> error
(exit)

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Yes, 'letex' and 'expand' don't expand on the top level. 'expand' will throw and error on this and 'letext' doesn't.

So probably 'letex' should throw an error too, when trying to expand a symbol on the top level. Starting with 10.0.4 'letex' will throw an error in this case.

Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Post by Kazimir Majorinc »

Lutz wrote:Yes, 'letex' and 'expand' don't expand on the top level. 'expand' will throw and error on this and 'letext' doesn't.

So probably 'letex' should throw an error too, when trying to expand a symbol on the top level. Starting with 10.0.4 'letex' will throw an error in this case.
If some nonformal semantics is substitution, then evaluation, then such trivial cases -- I think mathematical notation is f(x|y) -- have sense. It is one of those things like x-x, x/x, trivial, but simplifies calculations.

> (letex((x ''y))'x)
'y
> (letex((x ''y))x)
'y ; -- why not just y?
>


for letex and evletex, I don't know, maybe you can define evletex "just in case," I think it is marginally more useful, whatever it is, it doesn't hurt. Finally, cos(x) is barely sin(x+1.57). But really not a big deal.



Itistoday:

I think it is simplified situation in your example:

Code: Select all

(println (letex ((H1 '(let ((x ''y)) x)))
            (eval H1))) ; =>y, without eval it is (let ((x ''y)) x)

             ; is equivalent to

(println (letex ((H1 '((x ''y))))
             (letex H1 (eval 'x)))) ;=>y, without eval it is 'y
             
             ; is equivalent to
             
(println (letex ((H1 '((x ''y))))
             (letex H1 (first (list x))))) ;=> y, because (first (list x))=(eval 'x)

Locked