Author Topic: Rob's Lisp Adventures  (Read 15129 times)

0 Members and 3 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures
« Reply #30 on: March 06, 2015, 04:46:14 AM »
Charles,

Your Sierpinski is absolutely fantastic! Can you upload a compiled 32-bit executable here?



Rob,

I'm having problems with your latest exes here. The controls and windows (including the console) are almost unresponsive, OpenGL fails to update the draw lists according to the level chosen, and I can't exit cleanly because the console [X] button is almost always disabled while Ctrl+C crashes the app. And the applications do leak memory in chunks of approx. 8 to 12 kilobytes per second when in rotation mode.

Quote
I replaced (sleep/yield 0) (DoEvents equivalent ) with a "straight" sleep for 10mSec

You may not do it. MS Windows Sleep() is not a substitute for DoEvents. It simply suspends all activity including window message processing (roughly) for a specified number of milliseconds in the caller thread. In Windows, this would be the application's main thread where message processing is simply hidden from you in the accompanying third-party GUI libraries that utilize native Windows forms and controls.

You cannot write platform-independent code in tight endless loops like your rotation/rendering loop not taking due account of target system specifics. Platform independence in GUI applications is a fairy tale, a conspiracy and a chimera nurtured by Windows haters like Linus Torwalds and his ilk.

You absolutely must find a way to code a Lisp equivalent to the following (FBSL) BASIC code and call this sub in each iteration of a tight loop. Unhindered message processing must have top priority over everything else in your Windows GUI applications and especially in the loops that take more than just a few milliseconds to execute before bailout.

Code: OxygenBasic
  1. Type MSG
  2.     hwnd As Long
  3.     message As Long
  4.     wParam As Long
  5.     lParam As Long
  6.     time As Long
  7.     x As Long
  8.     y As Long
  9. End Type
  10.  
  11. Const PM_REMOVE = 1
  12.  
  13. Sub DoEvents()
  14.     Dim message As MSG
  15.  
  16.     While PeekMessage(@message, hWnd, 0, 0, PM_REMOVE) ' Don't change this to If!
  17.        TranslateMessage(@message)                     ' All pending messages, if any,
  18.        DispatchMessage(@message)                      ' must be processed before the sub exits!
  19.    Wend
  20. End Sub

where hWnd is the handle to the application's main window and the three functions are imported from user32.dll.

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #31 on: March 06, 2015, 05:57:42 AM »
Hi Mike ,

It's a Scheme (sleep 0)

        (sleep [secs]) → void?

      secs : (>=/c 0) = 0

Causes the current thread to sleep until at least secs seconds have passed after it starts sleeping. A zero value for secs simply acts as a hint to allow other threads to execute. The value of secs can be a non-integer to request a sleep duration to any precision; the precision of the actual sleep time is unspecified.

&

        (sleep/yield secs) → void?

      secs : (and/c real? (not/c negative?))

Blocks for at least the specified number of seconds, handling events meanwhile if the current thread is the current eventspace’s handler thread (otherwise, sleep/yield is equivalent to sleep).

your latest exes ...    yes, I lowered the interval in the timer loop ,otherwise it will not run under windows (well, it does run but it builds no new glLists )  these problems do not (at all) exist under Linux -- here (Win32) I have to set up a flag if the glList has to be replaced with a new one -- this is bad technique , surely ..  somehow  ,  somewhere  "things turn square"

  -- i do know that Mr Müller from newLISP , just removed semaphores , sync and i do think (almost sure) the timer events functions for the Win versions (probably he converted from Linux too)    there *is* certainly something wrong here

sigh -- once again , not a "write once - compile everywhere" piece of code  :(

thanks, for showing these facts -- it's important to me

best, Rob

Charles Pegge

  • Guest
Re: Rob's Lisp Adventures
« Reply #32 on: March 06, 2015, 06:09:34 AM »
Hi Mike,

Submitted with trepidation, since I am using shaders!

It is animated by a simple tumbler. You can take snapshots using ctrl-p

I also include the main source for Rob, where you can see the geometry and glCompiled lists used in construction. As you can see, the recursion could be compacted a little further.


.

Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures
« Reply #33 on: March 06, 2015, 07:05:13 AM »
Excellent! :D

Maximized window: CPU usage 10.8%, GPU memory usage 12%, GPU usage 25%. And if my eyesight doesn't fail me, your shaders are anti-aliased?

Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures
« Reply #34 on: March 06, 2015, 07:37:06 AM »
Rob,

For what it's worth, all this bla-bla may be applicable under Linux but I don't see how they could in fact implement a sleep/yield in Windows that would block the caller thread in everything except window message processing. MS Windows Sleep() is a kernel function that has fixed functionality you can't change in any way. Sleep(0) will yield immediately the remaining portion of current time slice to other threads even if there are window messages pending in the app message queue. Sleep(n) will block all activity in the thread, again including window message processing, for roughly 16 * Floor(n / 16) milliseconds unless special measures are taken to increase its resolution.

The unresponsiveness that I'm seeing is exactly what it would look like if their sleep/yield were implemented based off of MS Windows' blocking Sleep() that I described above. Again those Linux guys are claiming things that aren't there. Oftentimes it is very irritating to see how they can spit at an operating system that they turn out to know nothing about.

I still insist that you arm your GUI Lisp creations with DoEvents() that I described in my earlier message. Then you will be able to use Lispish define/defined? for conditional compilation of your code similar to how it is done with C preprocessor directives in the C language programs that can rightfully claim a certain degree of multi-platformness:

Code: C
  1. #if defined(WIN32)
  2.     DoEvents();
  3. #else
  4.     sleepyield(0); // or whatever it is for Linux
  5. #endif // WIN32
« Last Edit: March 06, 2015, 07:43:49 AM by Mike Lobanovsky »

Aurel

  • Guest
Re: Rob's Lisp Adventures
« Reply #35 on: March 06, 2015, 11:25:25 AM »
Mike
Just one small question..if is not a problem.
You suggest to use While loop for message processing ...
why i ask..i think that i made mess in my crappy interpreter using IF
so do i must use while instead of if

thanks...

Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures
« Reply #36 on: March 06, 2015, 12:11:07 PM »
Yes Aurel,

You should use While/Wend because many events in an MS Windows window (pun is unavoidable here) generate a batch of several window messages rather than just one message. So, While/Wend will ensure that all concurrent and interrelated messages are processed together until PeekMessage(PM_REMOVE) returns zero (i.e. logical FALSE) to indicate that there are no more messages left unattended in the message queue.

If you used If here, PeekMessage(PM_REMOVE) would only process just the first one of the messages that might be waiting in the message queue, which would be effectively the same as if no messages were processed at all, because an event is considered complete only after all of its relevant window messages have been processed either in the user-defined callback, or by DefWindowProc(), or both, and the corresponding message return codes have been transmitted back to the system.

MS Windows agrees to wait till it gets a due response from the user to the window message it has sent only for a very short time period, and that period gets visibly shorter and shorter with every new version of Windows. So, what may still work for you in your XP Sp2 might not work at all under the user's Win 7 that would simply kill your application as "not responding".

Aurel

  • Guest
Re: Rob's Lisp Adventures
« Reply #37 on: March 06, 2015, 01:46:23 PM »
Thanks Mike
Great explanation and i will do that way.
Well ..so far it seems that my XP progs work on win7(32bit) without problem..
anyway ..good to know
 :)

RobbeK

  • Guest
Re: Rob's Lisp Adventures -- the ENDLOESUNG
« Reply #38 on: March 08, 2015, 05:01:29 AM »
thanks Charles , Mike

...   the final solution then
when identical code runs fine under Linux and erroneous under Win, then there's something wrong not (?)

the combination thinBasic , Oxygen and newLISP does solve all problems and fulfills my needs.
newLISP get a lot of critique for its dynamic scope - but as I do not use many globals and in case functions can be declared in a statical name space (context) , this should give no problem at all. 
Furthermore , it has superb FFI (which makes it possible to communicate with a tB O² environment via on the fly generated oxygen dll ' s)
Unlike other Lisps it hat (address   ) and can access (read/write) physical memory.

As an example (need to replace the use of the arrow keys for navigation -- what ure the usual keys ??  --  I'm working on a (mainly) French AZERTY keyboard )  , pro demo a short console based prog , calculating a Fibo number,  then the pseudo 3D L-systems.   (use arrow keys and PgUP , PgDn (zooming)

best ,   Rob

 

All the experiments stop here (for Linux , i'll keep using Racket , under Win as above mentioned )

.

Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures -- the ENDLOESUNG
« Reply #39 on: March 08, 2015, 09:33:52 AM »
Hi Rob,

... when identical code runs fine under Linux and erroneous under Win, then there's something wrong not (?) ...

For me, it is absolutely clear what's wrong with it: the instruments are/were developed by the Linuxoids and for Linux, and then carelessly/ignorantly "ported" to hateful Windows because absolutely no application can claim, and aspire for, multi-platformness if it is/was not originally targeted for/has gained recognition under Windows as the most widespread and fundamental operating system of today.

Other people may have other standpoints about this phenomenon but mine is, and will continue to be, exactly as I stated above.

Quote
the combination thinBasic , Oxygen and newLISP does solve all problems and fulfills my needs.

I respect your choice. Personally, I think I know only one combination that can potentially be better than this but here I will keep my preferences to myself. :)

Quote
need to replace the use of the arrow keys for navigation -- what ure the usual keys ??  --  I'm working on a (mainly) French AZERTY keyboard

This problem is not uncommon to me either; all my co-developers are Frenchmen. :) The UP, LEFT, DOWN, RIGHT arrow functionality should be duplicated with the QUERTY buttons W, A, S, D, and/or the AZERTY buttons Z, Q, S, D, respectively. Zooming in/out with PgUp, PgDn buttons should be duplicated with mouse wheel rotation.

Toggling between the keyboard layouts should be preferably automated based on the OS locale actually running.

Duplication is desirable because:
  • It enables the right-handed user (75% of the user base) to utilize their left hand for app navigation with the keyboard, and their right one, for mouse-assisted navigation about the desktop/app zooming, without clustering their hands on one side of the keyboard only and without letting go of their mouse;
  • Some PC keyboards have no arrow buttons or number pads at all, which makes the use of your apps problematic because the other OEM keys that are often used to emulate the thus missing functionality would have different, incompatible OEM scancodes; and
  • This is how the absolute majority of gamers (millions of them) would expect comfortable navigation to be implemented. In fact, arrow keys are still used for graphics screen navigation only by the aging BASIC devs/game writers... :)

Quote
... for Linux , i'll keep using Racket ...

... I presume, only if you actually happen to prefer to stay on that platform at all. :D

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #40 on: March 09, 2015, 06:55:08 AM »
HI Mike,

"For me, it is absolutely clear what's wrong with it: the instruments are/were developed by the Linuxoids and for Linux, and then carelessly/ignorantly "ported" to hateful Window"   - yes , (more than) probably --  Corman Lisp is the only Lisp "born" on a Windows platform , all the others are Linux.
But someone could have told me / mentioning on the web etc ...  the potential problems :   
 either by an honest warning (SteelBank CL)
  WARNING: the Windows port is fragile, particularly for multithreaded
code.  Unfortunately, the development team currently lacks the time
and resources this platform demands.
*


or removing semaphores , sync and timers (newLISP)  ***

or making no distribution at all  (picoLisp)

(could have saved me some time )

"I think I know only one combination that can potentially be better than this "  i even don't have to guess  ;)
"only if you actually happen to prefer to stay on that platform"  time will tell - the use may fade away depending on people asking to do something with it.

The included fast Fibonacci is just included by reason of propaganda  8)  En France, on dit : "on n'attrape pas les mouches avec du vinaigre "
(you don't catch flies with vinegar  8)  )

best Rob

--  *** be aware , newLISP seems to be in a way the favorite "urinoir" corner (that's also French, but the meaning is obvious) for the Lisp "academici" (honestly I think most of them are pretenders ).

no compiler :  the choral :  " he can't do it , he can't do it ....."
dynamic scope i.o. lexical  :  the choral :  " he can't do it , he can't do it ..... he's too stupid"
semaphores , syncs :   the choral :  " he can't do it , he can't do it ..... he's an idiot"

imo newLISP is closest to the original concept of Lisp (it borrows a lot from Scheme too )  -- maybe it is too simple for some  people ???
« Last Edit: March 09, 2015, 07:12:28 AM by RobbeK »

RobbeK

  • Guest
Dynamic Classification of Escape Time Sierpinski Curve Julia Sets ;-)
« Reply #41 on: May 05, 2015, 03:21:37 AM »
Hi all,

I'm back to windows ... (and be very careful if you have a dual OS on your machine -- the Linux GRUB is very hard to remove, I needed a boot CD to fix the MBR to start up in Windows again ).

OK, found something interesting that may be of interest (on http://math.bu.edu )

I wrote it first in PLT Scheme and found there is no difference in operation time between an iterative and recursive definition of the fractal.

goes like this :

(define (juliaR x y rg ig it maxit orb)
  (if (or (> orb 4.0) (= it maxit )) it
      (juliaR
       (- (* x x) (* y y) (/ (+ (* 2 ig x y) (* rg x x) (- (* rg y y))) (+ (* 4 x x y y) (sq (- (* x x) (* y y))))))
       (- (* 2 x y) (/ (- (* ig x x) (* ig y y) (* 2 x y rg)) (+ (* 4 x x y y) (sq (- (* x x) (* y y))))))
       rg ig (add1 it) maxit (+ (* x x) (* y y)))))


As this is only f(z)=z²-C/z² and these already need some pen and paper to convert into f(x,y) I switched to complex numbers.
To my surprise and working in Clozure Common Lisp unexpectedly there is almost no loss in processing time between real numbers and complex.   !!!!

the complete formula simplifies into :


(defun juliaC (z c it maxit orb)
   (if (or (> orb 4.0) (= it maxit )) it
     (juliaC (-  (sq z) (/ c (sq z))) c (1+ it) maxit (abs (* (realpart z) (imagpart z))))))

(where sq is definied as   (defun sq (x) (* x x))


you can see I replaced (at the end) the usual |z| for testing the orbit escape limit with an hyperbolic criterium (gives nicer images  ;)   )

As there 're some poles in the formula it's even possible to ignore these by telling the compiler :

(set-fpu-mode :overflow nil :invalid nil )
it's very easy to expand the definition into any power of z -- prototyping can be done in minutes.

best Rob

.
« Last Edit: May 05, 2015, 04:28:15 AM by RobbeK »

JRS

  • Guest
Re: Rob's Lisp Adventures
« Reply #42 on: May 05, 2015, 12:26:42 PM »
Quote from: Rob
I'm back to windows ...

 :o :'( :-X ::)

Mike Lobanovsky

  • Guest
Re: Rob's Lisp Adventures
« Reply #43 on: May 06, 2015, 08:00:25 AM »
Hi Rob,

Welcome home. Long time no see. :)

This Julia looks cool. The fractal seems symmetrical; would it be reasonable to calc just one quadrant and then flip the image to the other ones, do you think?

RobbeK

  • Guest
Re: Rob's Lisp Adventures
« Reply #44 on: May 06, 2015, 10:48:03 AM »
Hi John, Mike ..

John, it's not a question of better or worse ..

Mike, yes 4 symmetry axis's  -- an "octant" (if this is the correct word already would be enough ).
BTW I could solve that problem with glLists under Windows for PLT Scheme -- it's rather weird, but the list can only be build inside the main gl loop.  In this case a flag does the trick (if true the list is not compiled once again ).
Attached an example -- a start of a 3D presentation of the Newton-Raphson method for finding roots of equations.  It's based on a seed and this guess is iterated till the result is acceptable.  However for numbers (complex) that are at about the same distance of the roots, it starts to generate fractals --  easier to understand when you see it.
It are a heap of calculations, the canvas will be blank for some seconds , but then if you push the rotate button , you can see the glLists work , nothing is recalculated again  :)

This is a representation of the z³-1

ps : the iterations is a'=a - f(a)/f ' (a)
(this is only a quick start to see maths are correct --   (define (newton ...      are only a few lines in lisp (see image)  )

best & thanks   Rob   

.
« Last Edit: May 06, 2015, 12:32:47 PM by RobbeK »