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 - Dmi

#1
newLISP newS / Shared memory proposal
November 11, 2008, 04:31:58 AM
Hi, Lutz!



Last time I study Erlang and I found a useful thing that, imho, can significant simplify the newlisp asynchronous tasks when we need to fork and to use semaphores/shared memory.



I think it would be cool to have some engine over shared memory when one process can issue
(send-message Pid message)
to send a regular newlisp value to the shared-memory queue of forked process Pid.

and other process can issue
(receive-message) -> (Sender_Pid Message)
to receive next message from it's queue.



Probably, some blocking/non-blocking options etc. may be applicable here



The Erlang's version of this is much more powerful, but highly related to Erlang features.

But I think, that even this level of messaging will be more user-friendly and human-error free than concurent access to shared memory.
#2
newLISP newS / parse-date %Y
June 30, 2008, 03:57:33 PM
> (date (parse-date "2008" "%Y") 0 )
"Sun Dec 31 08:05:04 8676"

Year is 8676 instead of 2008 expected.



newlisp 9.3.12, Debian Linux
#3
newLISP and the O.S. / mysql5.lsp
May 01, 2008, 02:21:45 PM
Here is a diff for mysql5.lsp to run on amd64/Debian



I think it should go in other 64 bit systems. There is a two places in original file, where sizeof(int)=4 was assumed. They are changed to 8.

Enjoy ;-)


--- /usr/share/newlisp/modules/mysql5.lsp       2008-03-23 02:37:50.000000000 +0300
+++ mysql5-64.lsp       2008-05-02 01:16:28.000000000 +0400
@@ -122,11 +122,12 @@
 ; check endianess of the host CPU
 (set 'big-endian (= (pack ">ld" 1) (pack "ld" 1)))

+(constant 'INT_SIZE 8) ; 4 for 32 bit, 8 for 64 bit
 (constant 'NUM_ROWS_OFFSET (if big-endian 4 0))
-(constant 'NUM_FIELDS_OFFSET 60)
-(constant 'ERROR_OFFSET 85)
-(constant 'INSERT_ID_OFFSET (if big-endian 708 704))
-(constant 'AFFECTED_ROWS_OFFSET (if big-endian 700 696))
+(constant 'NUM_FIELDS_OFFSET 96)
+(constant 'ERROR_OFFSET 141)
+(constant 'INSERT_ID_OFFSET (if big-endian 708 832))
+(constant 'AFFECTED_ROWS_OFFSET (if big-endian 700 824))

 ;; @syntax (MySQL:init)
 ;; @return 'true' on success, 'nil' on failure.
@@ -185,7 +186,7 @@
   ; The field type is the 20th field of the MySQL_FIELD structure
   ; since fields 1-19 are all 4 byte fields we get the enum value
   ; like so
-  (set 'data (get-int (int (+ type_ptr (* 19 4)))))
+  (set 'data (get-int (int (+ type_ptr (* 19 INT_SIZE)))))
   ; Consult 'enum_field_types' in mysql_com.h for values
   (if (= data 1) ;; boolean
         (get-string field_addr)
@@ -215,7 +216,7 @@
     (begin
       (set 'row '())
       (dotimes (field (num-fields))
-            (set 'field_addr (get-int (int (+ rdata (* field 4)))))
+            (set 'field_addr (get-int (int (+ rdata (* field INT_SIZE)))))
             (if (= field_addr 0)
               (push nil row -1) ;; what to do when the field contains NULL
               (push (keep-type MYSQL_RES field_addr field) row -1)))
#4
newLISP newS / pop-assoc
March 21, 2008, 08:10:27 AM
Hi, Lutz!



I found a segfault:
dmi@stone:~$ newlisp
newLISP v.9.3.1 on Linux, execute 'newlisp -h' for more info.

> (set 'l '((1 2) (3 4) (5 (6 7))))
((1 2) (3 4) (5 (6 7)))
> (pop-assoc ('l 3))
Segmentation fault


I know that l must not be quoted, but this typo causes failure.



And a question: what for the extra parenthesis are in the syntax?



Oh! and another question:

Is there a non-destructive version for pop-assoc?
#5
newLISP newS / (column num lst)
March 18, 2008, 12:17:23 AM
Hi, All!



Testing with new function:
(define (column n lst)
  (map (fn(x) (x n)) lst))

> (set 'lst '((a 1 q)(b 2 w)(c 3 e)))
((a 1 q) (b 2 w) (c 3 e))
> (column 1 lst)
(1 2 3)
#6
newLISP newS / TCP/IP server suite
March 12, 2008, 05:43:43 AM
Recently found that frequently I need a tcp server in newlisp to serve simple data requests.

But net-select etc. is a low-level stuff which needs many workarounds in a real usage.



So, once I'v decide to made a such one. Here is it:

http://en.feautec.pp.ru/store/libs/doc/net-do.lsp.html">//http://en.feautec.pp.ru/store/libs/doc/net-do.lsp.html
#7
newLISP newS / buffering of (print)
March 12, 2008, 03:11:51 AM
Hi, Lutz!



Just discover that
(while true (print ".") (sleep 1000))
started in command prompt shows all the output only after execution is finished.

Often this is not useful.

If this is a new behavior, then something like (flush), or, better, the output buffer configuration for particular handle, like in perl,  will be a good addition.
#8
newLISP and the O.S. / Fresh Ubuntu package
February 23, 2008, 12:18:10 PM
Hello, guys!



Now I got an Ubuntu (gusty gibbon) installation on one of my stations.

So now U may add
deb http://en.feautec.pp.ru/debian/ gusty main
deb-src http://en.feautec.pp.ru/debian/ etch main

into your /etc/apt/sources.list and enjoy with debianized newlisp-9.3.1



PS. guiserver is checked at least with sun-java6-jre
#9
newLISP in the real world / detecting symbolic links
January 14, 2008, 12:01:37 AM
$ ln -s "." test
$ newlisp
> (directory "test")
true

So I can make a file symlinks, which will cycle the file tree iterators, or will go through mounted filesystems which is not always attended.



But in most other cases following symlinks is very useful because it is a regular Unix convention.



Can we have an option for (directory?) which will trigger symlink detection?
#10
Can the new GS window be drawed on the top of the screen, but not focused?



I.e. as "background process" that not interrupts the user's current work with other applications and keyboard.
#11
newLISP Graphics & Sound / CPU usage
November 24, 2007, 02:15:25 PM
I using gs:check-event with the (gs:get-bounds) call every 100 millisecs to know if canvas has resized.



In my system (AMD Turion 64, Debian 64 bit) newlisp, runned with guiserver uses ~55% CPU for newlisp and ~45% CPU for java.

The CPU's adaptive fan is trying to fly away from the box :-)



Can this be optimized?



sample code:
(load (append (env "NEWLISPDIR") "/guiserver.lsp"))
(gs:init)
;;;; describe the GUI
(gs:frame 'PFrame  100 100 600 600 "Frame")
(gs:set-border-layout 'PFrame)
(gs:canvas 'Picture)
(gs:set-background 'Picture gs:white)
(gs:add-to 'PFrame 'Picture "center")

(gs:set-visible 'PFrame true)

(define (bounds)
  (2 (gs:get-bounds 'Picture)))

(define (handle-resize)
  (set 'new-bounds (bounds)))

(while (gs:check-event 100000) ; check for 10 milli seconds
       (handle-resize))
#12
newLISP Graphics & Sound / Display image
November 21, 2007, 03:10:29 PM
What is the proper way to do that:



- display a jpeg image, scaled to fit to window, but with preserving of aspect ratio.

- resize image when window is resized.

?



...Possible there is a way to know original image size before drawing?

...Or there is an another way...
#13
newLISP Graphics & Sound / text-pane control
October 28, 2007, 03:27:58 PM
Hello, guys!



Recently I have a look into newlisp-edit.



I'd like to improve some things (such as completion and indenting) from my nlc project.



But I didn't found some control tricks. Point me please...



Can I set thee position of the caret for the text area (for example, after set-text)?



I can get event for any regular character typed, but can I prevent it from appearing in the text area?
#14
newLISP newS / net-accept additional info
August 16, 2007, 08:38:14 AM
Hi!



How can I get IP and port of the originatior of incoming tcp/ip connection?

(net-sessions) seems to only provide numerical descriptor now.
#15
newLISP Graphics & Sound / Tables and trees
August 14, 2007, 12:24:22 PM
Are tables and trees planning in guiserver?



Unfortunately, only system and end-user applications are possible without them.

But serious corporate business apps mostly has database/transactional nature which is difficult to deal with w/o table interfaces.



Trees are also very attended data representation method.
#16
newLISP newS / puss in a string bug?
July 09, 2007, 06:59:19 AM
dmi@stone:~$ newlisp
newLISP v.9.1.7 on Linux, execute 'newlisp -h' for more info.

> (set 'a "abc")
"abc"
> (push "-" a -1)
"-"
> a
"abc-"                       ;right
> (set 'a "abc")
"abc"
> (push "-" a -2)
"-"
> a
"ab-c"                      ;right
> (set 'a "abc")
"abc"
> (push "-" a -3)
"-"
> (set 'a "abc")
"abc"                       ;wrong
> (set 'a "abcd")
"abcd"
> (push "-" a -3)
"-"
> a
"ab-cd"                    ;right
> > (set 'a "abc")
"abc"
> (push "-" a -4)
"-"
> a
"-abc"                     ;right
>

Locale is ru_RU.KOI8-R (single byte).



I suspect that that this is something like unicode tricks...
#17
newLISP newS / library store
June 27, 2007, 04:19:19 PM
Welcome to http://en.feautec.pp.ru/store/libs/doc/index.html">//http://en.feautec.pp.ru/store/libs/doc/index.html

All that I have, reworked for new newlispdoc.



As I've promised early - jabber, ldap etc.

Also "doif" macro is introduced in funlib.lsp: http://en.feautec.pp.ru/store/libs/doc/funlib.lsp.html#_doif">//http://en.feautec.pp.ru/store/libs/doc/funlib.lsp.html#_doif
#18
newLISP newS / Useful function proposal: doif
June 15, 2007, 04:28:13 AM
doif macro:
Quotesyntax: (doif (sym expr) expr-yes expr-no))



expr is evaluated and assigned to sym

If then sym is not nil or (), then expr-yes is evaluated while sym is defined and can be used.

Otherwise expr-no is evaluated sym is still defined and can be used to distinguish between nil or ().

(context 'doif)
(define-macro (doif:doif test do-yes do-no)
              (eval
                (list let test (list 'if (first test) do-yes do-no))))
(context MAIN)


Frequently I using something like this:
(let (l (function-can-return-nil))
  (if l do-something-if-found
        do-something-if-not))

From the point of task logic this usually looks cryptic.

Real world example:

Find a tag or an attribute in xml s-expression
(define (xml-data tag xml)
  (let (r (assoc 0 (map reverse (ref-all tag xml))))
        (if r (xml (chop (reverse r))))))

I would like to propose the new form to write this:
(doif (l (function-can-return-nil))
  do-something-if-found
  do-something-if-not))

Or for real example:
(define (xml-data tag xml)
  (doif (r (assoc 0 (map reverse (ref-all tag xml))))
        (xml (chop (reverse r)))))
#19
newLISP newS / unify and lists
June 01, 2007, 07:46:52 AM
Is there a way to implement something like:

(unify (f A B TAIL) (f g h i j k)) => ((A g) (B h) (TAIL (i j k l))
#20
newLISP newS / newlispdoc proposal
May 29, 2007, 11:06:48 PM
Hi, Lutz!



It would be cool to have some trick to emphase function names (differently from arguments). Possible to represent them as links:

@func name => <a href=#name>name</a>

@libfunc lib name => <a href=lib.html#name>name</a>



@func context:name => <a href=#name>context:name</a>

@libfunc lib context:name => <a href=lib.html#name>context:name</a>



I can propose a patch if U think this will be useful.