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

Topics - oofoe

#1
Hi!



In my quest to construct a program to derive the question to the answer of Life, the Universe and Everything (which is, as any schoolchild knows, 42), I wrote a very simple genetic algorithm solver.



I don't mean simple as in "simple to use", I mean absolute braindead simple. By some definitions, this is not really a genetic algorithm because the "genome" is the same as the data being operated on (there is no "expression"), but it's a cute toy and somebody else might find it entertaining as well:



https://bitbucket.org/oofoe/ga/src/9523e44cb284aa8e9f030610d0e84e2d922ff10c/adder/?at=default">https://bitbucket.org/oofoe/ga/src/9523 ... at=default">https://bitbucket.org/oofoe/ga/src/9523e44cb284aa8e9f030610d0e84e2d922ff10c/adder/?at=default



I am currently hard at work on a new program which will use a genetic algorithm to do lossy image compression through vector shapes, just have to teach NewLisp about reading %.png files...
#2
newLISP newS / Documentation example error for import...
September 17, 2016, 07:28:10 AM
Hi!



Hope this is the best place to post this...



The first example for import at http://www.newlisp.org/downloads/newlisp_manual.html#import">http://www.newlisp.org/downloads/newlis ... tml#import">http://www.newlisp.org/downloads/newlisp_manual.html#import is incorrect. It should have the following marked line added:

(define LIBC (lookup ostype '(
("Windows" "msvcrt.dll")
("OSX" "libc.dylib")

(import LIBC "printf") ;; This line needs to be added to make example work.

(printf "%g %s %d %cn" 1.23 "hello" 999 65)

Thanks!
#3
Hi!



I have something like this:


(gs:panel 'Panel)
(gs:check-box 'Visible 'checkboxing "visible)
(gs:add-to 'Panel 'Visible)


And it's very nice. I get events when the user changes the value to my checkboxing function and so forth.



However, what if I want to set the value from the program?



(gs:set-value 'Visible true) does not work... Any suggestions?



Thanks!
#4
Hi!



Is there anything like the Python webbrowser library to launch a file in the system specific web browser?



I'm currently using (! (string "explorer.exe " pfile) 0)
where pfile is something like "c:\temp\card-preview.html", but this is very specifically Windows...



Thanks!
#5
newLISP Graphics & Sound / Macros and guiserver?
July 04, 2016, 05:16:16 AM
Hi!



I am experimenting with macros to do more "declarative" setups in guiserver. Here is a macro that I have created to make a three button setup:

(define-macro (button3 _parent _name _buttons)
  (letn ((panel (sym (string (eval _parent) "-" (eval _name))))
   (slots '("west" "center" "east"))
   (bname nil)
   (i nil))
  (gs:panel panel)
  (gs:set-border-layout panel)
  (dotimes (i (length (eval _buttons)))
    (setq bname (sym (string panel "-" ((eval _buttons) i 0))))
  (println "Setting up " bname)
    (gs:button bname 'gs:no-action ((eval _buttons) i 1))
    (gs:add-to panel bname (slots i))
    )))


I call it like this:

 (button3 'DC 'East  '((Next "-->") (View "<o>") (Kill "X")))


This creates a panel (DC-East) that has three buttons (DC-East-Next, DC-East-View and DC-East-Kill). They're all set up and ready to go.



However, I can't figure out how to pass in an optional event handler for each button and have the macro assemble it correctly for the gs:button call. I want to do something like this

 ;; The "View" button doesn't have a handler yet, should default to gs:no-action.
  (button3 'DC 'East  '((Next "-->" 'next-card) (View "<o>") (Kill "X" 'kill-card)))


I am just getting invalid function or macro expansion problems when I try to do this. Any suggestions?



Thanks!
#6
newLISP in the real world / Using xmlrpc-client.lsp...
January 09, 2016, 05:17:43 AM
Hi!



I ran into a little problem when using %xmlrpc-client.lsp with our python/django XMLRPC server at work. It has a very strict interpretation of how many arguments it will accept for certain functions, like system.listMethods, so the default request with the single dummy argument won't work.



I wound up adding something like this to xmlrpc-client.lsp:

(define (format-request method)
  "( method /arg.../ -- XML) Compose XML request."

  (let ((xml (format
     "<?xml version="1.0"?><methodCall><methodName>%s</methodName><params>"
     method)))
    (dolist (value (args))
      (push (format "<param><value>%s</value></param>" value) xml -1))
    (push "</params></methodCall>n" xml -1)))


Then changing system.listMethods to:

(define (system.listMethods url)
    (execute url (format-request "system.listMethods")))


Technically, format-request should also determine the type of the argument values (and encode lists and dictionaries correctly), but if you're only using string arguments, it should suffice.



Maybe someone has a better format-request they could share? ; - )
#7
Hi!



I'm trying to wire up a text-area with a keyboard event so I can detect if the user presses the escape key while typing. It works fine for text-field Title (see below), but the handler never gets called for keypresses in Body. I have wired the standard handler into gs:no-action because it either only gets fired on pressing the enter key (text-field) or doesn't have any information about non-textual keys (text-area).



Can anyone point out where I'm going wrong?



Thanks!



(load (append (env "NEWLISPDIR") "/guiserver.lsp"))
(gs:init)

(define (field-key id type code modifiers)
  "( id type code modifiers --) Handler for keyboard."

  (println "Key for " id " " type ", " code " with " modifiers "."))

(define (layout)
  "( --) Layout GUI."

  (gs:text-field 'Title 'gs:no-action 64)
  (gs:key-event  'Title 'field-key)
  (gs:text-area  'Body  'gs:no-action)
  (gs:key-event  'Body  'field-key)
  (gs:frame 'F  0 0  800 600  "Text Keyboard Event Test")
  (gs:set-border-layout 'F)
  (gs:add-to 'F  'Title "north"  'Body "center")
  (gs:set-visible 'F true))

(layout)
(gs:listen)
#8
Hi!



I'd like to report a bug with canvases when used with scroll bars. If you run the following code, it creates a 2048x2048 canvas, then places it into a scrolled pane. You can scroll the canvas, but it will not repaint when you stop scrolling. Even forcing a gs:update (click on canvas) will not repaint it.



However, changing the window size will, which proves that scrollable large canvases should be doable, just maybe an event isn't getting propagated correctly on the Java side?



Thanks very much!


(load (append (env "NEWLISPDIR") "/guiserver.lsp"))
(gs:init)

(define (canvas-unclick)
  "( --) Handler for mouse button release."

  (gs:update)) ;; Note that this doesn't work.

(define (layout)
  "( --) Layout GUI."

  (gs:canvas 'Canvas)
  (gs:mouse-released 'Canvas 'canvas-unclick)

  (gs:panel 'Stretcher 2048 2048)
  (gs:set-border-layout 'Stretcher)
  (gs:add-to 'Stretcher 'Canvas "center")

  (gs:scroll-pane 'Workspace 'Stretcher)

  (gs:frame 'F  0 0  800 600  "Scrolling Canvas Test")
  (gs:add-to 'F 'Workspace)

  (gs:fill-rect 'shape   50  50  500 500  '(1 1 0))
  (gs:fill-rect 'shape  250 250  500 500  '(0 1 0))
  (gs:fill-rect 'shape  500 500  500 500  '(0 1 1))

  (gs:set-visible 'F true))

(layout)
(gs:listen)
#9
Hi!



Don't know if this is the best place to post this, but I did use this "in the real world" to compute my weight and balance for my flight yesterday...



This program makes it easy to do your weight and balance calculations so you can determine your position in the performance envelope before you take off into the wild blue yonder! Use it in conjunction with your Pilot's Operating Handbook to make sure you won't have any problems with your loading scenario.



https://bitbucket.org/oofoe/wb/overview">//https://bitbucket.org/oofoe/wb/overview



Even if you're not interested in aviation per se, it may be interesting as a demonstration of setting up a spreadsheet-like interface with recalculation every time the user presses enter.



I am planning some improvements, but right now it does do all the computations. Comments and suggestions welcome!
#10
Hi!



I'm doing a simple picture viewer using the GUI server. However, I am having an odd problem where sometimes the image loads and sometimes it doesn't. If I advance to the next image then come back to one that didn't load, it will often load then.



I am using this to clear the previous image, then load and draw a new image into the canvas:


 (gs:delete-tag 'I)
 (gs:draw-image 'I path  0 0   (psize 1) (psize 0))
 (gs:draw-text 'I path  21 25  '(0 0 0))
 (gs:draw-text 'I path  20 24  '(1 1 0)))


The images are generally about 4Kx2.5K, scaled to 625x521 (for the psize argument).



When the image load fails (?), the text draws following it fail also, so nothing is shown.



Any ideas as to what's going on -- and how I can fix it?



Thanks!
#11
Hello!



I am trying to set up a little simulation project, but I am running into some problems with FOOPS and pass by value...



I have a Plane class, which considers the engine RPM and the altitude of the airplane:

(new Class 'Plane)

(define (Plane:Plane rpm alt)
(list 'Plane rpm alt))


Now, I might have methods that change the internal state of a particular instance of the Plane object. Here is one that firewalls the engine (goes to full throttle for a climb):
(define (Plane:firewall)
(setf (self 1) 2700))


This seems to work well enough for a single named instance of Plane:
(setq aplane (Plane 1900 2000))
(println "Original: " aplane)
(:firewall aplane)
(println "Modified: " aplane)


Which produces:
Original: (Plane 1900 2000)
Modified: (Plane 2700 2000)


However, if I try to create a list of many airplanes:
(setq
planes (list
(Plane 2700 0)
(Plane 2100 1250)
(Plane 1500 900)))

(println "Original: " planes)
(dolist (p planes) (:firewall p))
(println "Modified: " planes)


This is what happens:
Original: ((Plane 2700 0) (Plane 2100 1250) (Plane 1500 900))
Modified: ((Plane 2700 0) (Plane 2100 1250) (Plane 1500 900))


As you can see, nothing is changed. Upon further investigation (printing "p" after the :firewall call) I see that the intermediate object p is changed, but not stored to the list "planes". I assume that this is happening because as dolist iterates through planes, each Plane object is copied to p.



What is the best way to handle updating an object in a list of objects like this?



Also, for what it's worth, I have considered modifying :firewall to return self so I can do this:
(dotimes (i (length planes))
(setf (planes i) (:firewall (planes i))))


But I hope you can tell me there's a better way to handle it!



Thanks!
#12
Whither newLISP? / Closure?
April 04, 2013, 05:03:24 AM
Hi!



I'm working through the early examples of the "Stratified Design" paper[1] and I've run (almost immediately!) into something that doesn't seem to work.



They describe an average-damp function that given a function, returns a new function that averages the value with the result of the function:


(define (average)
(div (apply 'add (args)) (length (args))))

(define (average-damp f)
(fn (x)
(average x (f x))))


You might use it like this: ((average-damp (fn (y) (+ 2 y))) 3)



And expect to get 4 (the average of 3 and the result of adding 2 to 3). However, instead I get this:


ERR: invalid function : (f x)
called from user defined function average


I assume that this is happening because the function f, that is passed to average-damp is not lexically closed in the new function that's returned, because NewLisp is not doing that sort of thing.



I have looked through the "Functions as Data" section of the Code Patterns and those examples didn't seem to help. I tried both "expand" and "letex" and they didn't seem to help.



So, is it possible to implement something like average-damp in NewLisp, and how would you do it?



Thanks!



[1] See http://dspace.mit.edu/bitstream/handle/1721.1/6064/AIM-986.pdf?sequence=2">http://dspace.mit.edu/bitstream/handle/ ... sequence=2">http://dspace.mit.edu/bitstream/handle/1721.1/6064/AIM-986.pdf?sequence=2
#13
As I understand it, setf can not only set a variable, it can also set a "place", in this case, a position in a list. So I can create a simple class:

(new class 'Node)

(setq n (Node "test" '(5 3)))


If want to inspect or change the Node's coordinates, I can do this:

(println "location: " (n 2))
(setf (n 2) '(9 9))
(println "new location: " (n 2))


However, if I want to encapsulate the list access into the class, it doesn't work for setting:


(define (Node:where) ((self) 2))
(println "location: " (:where n))
(setf (:where n) '(14 3))
(println "same old location: " (:where n))


Is there any way to do anything like the above without having to define a separate getter and setter?



Thanks!
#14
Whither newLISP? / Object Philosophy...
January 20, 2013, 11:43:58 AM
Hi!



Not sure if this is the best place to post this, but I wondered if anybody could tell me if I'm doing this correctly. The idea is that I want named attributes for my object, and I only want to have to specify them once.



If this isn't too crazy, is there any way to make it the default behaviour for new objects? (EDIT: To clarify, I want to create a macro or something that will let me make it the default behaviour for new objects in my program, not the NewLisp distribution itself...)



Thanks!


; h1. Node Class Test

; h2. Node Class

(new Class 'Node)

(set 'Node:parms '((title  "Untitled")
                   (where  (0 0))))

(define (Node:Node)
  (let ((parms (copy Node:parms))
        (parm  nil)
        (data  (list Node)))
    (doargs (i)
            (setq parm (pop parms))
            (if parm (push (list (parm 0) i) data -1)))
    (append data parms)
    ))

(define (Node:get key)  
  (lookup key (self)))

(define (Node:set key value)  
  (setf (assoc key (self)) (list key value)))


; h2. Tests

(define (test what pass)
  (println what "..." ('("FAILED" "OK") (if pass 1 0))))

(setq n (Node "Fantastiche"))

(test "Title set" (= "Fantastiche" (:get n 'title)))

(test "Default location" (= '(0 0) (:get n 'where)))

(:set n 'where '(10.0 14.5))
(test "New location" (= '(10.0 14.5) (:get n 'where)))
#15
Hi!



This may just be that I'm not reading the documentation closely enough, however if I understand correctly, the "border" layout style allows five sections -- north, south, east, west and center -- and they should work together.



So, this piece of code should show a red box on top, with the bottom divided evenly between a green box on the left and a blue box on the right.



Instead I get a single blue box that fills the entire frame. Any ideas? Thanks!


(load (append (env "NEWLISPDIR") "/guiserver.lsp"))

(gs:init)
(gs:set-trace true)
(gs:set-look-and-feel "javax.swing.plaf.metal.MetalLookAndFeel")

(gs:frame 'main 100 100 512 512 "Layout Test")

(gs:set-border-layout 'main)

(gs:panel 'i1 100 100)  (gs:set-color 'i1 1 0 0)
(gs:panel 'i2 100 100)  (gs:set-color 'i2 0 1 0)
(gs:panel 'i3 100 100)  (gs:set-color 'i3 0 0 1)

(gs:add-to 'main 'i1 'north  'i2 'west  'i3 'east)

(gs:set-visible 'main true)
(gs:listen)


I've tried using separate (gs:add-to) calls and putting the panels inside an inset panel with the border layout, but nothing seems to work. By the way: newLisp v10.4.4, newLISP-GS v.1.47 on Windows 7
#16
Hi!



Having some trouble with regular expressions... It seems that d and D aren't working for me:



> (find "d+" "3432" 0) $0
nil
"433"
> (find "D+" "XC3432" 0) $0
nil
"433"
> (find "[0-9]+" "3432" 0) $0
0
"3432"


I'll limp along with "[0-9]" for now, but it would be nice to know what's going on with the others. According to the PCRE manpage, they should work.



Using newLISP v.10.4.5 on Win32 IPv4/6 libffi from the most recent installer, running on XP64.



Thanks!
#17
Hi!



According to the documentation, specifying gs:mouse-released with a third argument of "true" will provide a list of tags whose member's bounding boxes intersect the mouse cursor position. However, this doesn't seem to actually work (see example code below). If the "true" argument is removed, then you will see little red circles where you click. Otherwise nada.



Any ideas what's wrong? Thanks in advance!



(load (append (env "NEWLISPDIR") "/guiserver.lsp"))

(gs:init)

(gs:frame 'main  100 100  800 800  "Demo")
(gs:set-border-layout 'main)

(gs:canvas 'main-canvas)
(gs:set-background 'main-canvas gs:gray)
(gs:add-to 'main 'main-canvas "center")
(gs:set-visible 'main true)

;; This is the affected line:
(gs:mouse-released 'main-canvas 'canvas-clicking true)

(define (canvas-clicking x y)
  (println (args))
  (gs:draw-circle 'C x y 8 gs:red)
  (gs:update)
  )

(gs:listen)
#18
Whither newLISP? / Compose for NewLISP?
January 27, 2012, 10:30:52 PM
Hi!



I realize that this is probably really easy and trivial...  However! I would like to define an associative list that uses pre-existing variables. Something like this:


(setq x 412)
(setq a '((name "Bob")
             (age    x)))


So that:


(lookup 'age a) -> 412

Of course this doesn't actually work because the "x" is quoted inside the quoted associative list, so it returns x the symbol instead of the value at associative list creation time. This will work, but it's ugly because you have to use different strategies to assemble the individual keys and values:


(setq a (list '(name "Bob")
                   (list 'age x)))


So... Is there any more elegant way to do it?



Thanks!
#19
newLISP Graphics & Sound / Drag and Drop?
August 25, 2008, 08:28:15 AM
Hi,



Is there an easy way to do simple inter-process drag and drop with the newLisp GUIserver on Windows? I would like to be able to drag and drop text snippets from other applications (like Outlook or Wordpad) onto a newLisp application, then have it process the text.



As a bonus, it would also be good to have it going in the other direction -- dragging and dropping from the newLisp program.



It does seem that drag and drop work on text fields, but I would like to extend it in a more general direction -- using an image as the drop pocket, for example.



Thanks!
#20
newLISP Graphics & Sound / Compiling guiserver...
April 25, 2008, 01:31:23 PM
Hi,



How does one re-compile the guiserver? I'm would like to tweak how list-boxes work but I don't see anything for compiling and building the .jar in the Makefiles.



I would like to be able to recompile it on Windows.



I may well have overlooked something... Pointers to the obvious would be welcome.



Thank you,



Jos'h