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

#1
newLISP in the real world / unless bug?
June 01, 2018, 07:20:02 AM
Quotesyntax: (unless exp-condition body)

The statements in body are only evaluated if exp-condition evaluates to nil or the empty list (). The result of the last expression in body is returned or nil or the empty list () if body was not executed.


newLISP v.10.7.3 32-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h
> (unless (file? "hello") (make-dir "hello"))
true
> (unless (file? "hello") (make-dir "hello"))
true
> (unless (file? "hello") (make-dir "hello"))
true


newLISP v.10.7.3 32-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h
> (when (not(file? "hello")) (make-dir "hello"))
true
> (when (not(file? "hello")) (make-dir "hello"))
nil
> (when (not(file? "hello")) (make-dir "hello"))
nil
#2
newLISP in the real world / It makes me a bit confused
November 09, 2017, 03:21:27 AM
> (struct 'A "char*")
A
> (pack A "HELLO")
"176154d00"
> (unpack A (pack A "HELLO"))
("HELLO")
> (setq a (pack A "HELLO"))
"0154d00"
> (unpack A a)
("06") ; <------------
> (setq b "HELLO")
"HELLO"
> (setq a (pack A b))
"p154d00"
> (unpack A a)
("HELLO")
#3
newLISP v.10.7.3 32-bit on Windows IPv4/6 libffi, options: newlisp -h
; 33 "char"
(struct 'abc "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char" "char")
abc
> (pack abc)
"000000000000000000000000000000000000000
0000000000000000000000000"
> (length (pack abc))
32
> (length (pack abc (sequence 1 33)))
32


newLISP v.10.7.3 32-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h
> (apply struct (cons 'a  (flat (dup (list "char") 16))))
a
> (length (pack a))
16
> (apply struct (cons 'b  (flat (dup (list "char") 32))))
b
> (length (pack b))
32
> (apply struct (cons 'c  (flat (dup (list "char") 64))))
c
> (length (pack c))
32     ; <-------- why is not 64?
> (apply struct (cons 'd  (flat (dup (list "char") 128))))
d
> (length (pack d))
32     ; <-------- why is not 128?


> (apply struct (cons 'A  (flat (dup (list "unsigned short int") 16))))
A
> (length (pack A))
32
> (apply struct (cons 'B  (flat (dup (list "unsigned short int") 32))))
B
> (length (pack B))
64
> (apply struct (cons 'C  (flat (dup (list "unsigned short int") 64))))
C
> (length (pack C))
64     ; <-------- why is not 128?
> (apply struct (cons 'D  (flat (dup (list "unsigned short int") 128))))
D
> (length (pack D))
64     ; <-------- why is not 256?


> (apply struct (cons 'AA  (flat (dup (list "unsigned int") 16))))
AA
> (length (pack AA))
64
> (apply struct (cons 'BB  (flat (dup (list "unsigned int") 32))))
BB
> (length (pack BB))
128
> (apply struct (cons 'CC  (flat (dup (list "unsigned int") 64))))
CC
> (length (pack CC))
128     ; <-------- why is not 256?
> (apply struct (cons 'DD  (flat (dup (list "unsigned int") 128))))
DD
> (length (pack DD))
128     ; <-------- why is not 512?
#4
newLISP v.10.7.1 32-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h

> (setq str (dup "00" 10))
"00000000000000000000"
> (trim str)
""
> (setq str (dup "00" 31))
"000000000000000000000000000000000000000
00000000000000000000000"
> (trim str)
""
> (setq str (dup "00" 32))
"000000000000000000000000000000000000000
0000000000000000000000000"
> (trim str)

ERR: not enough memory in function trim
#5
newLISP in the real world / Is this newLISP's bug?
August 11, 2017, 05:50:30 AM
I created an edit window using following code:


(define (import-list library flist)
    (dolist (fname flist) (import library (string fname))))

(define-macro (@setq %var %value)
    (set %var (eval %value))
    (println %var " " (eval %var)))

; Constants
(define IDC_TEXTBOX   1000)
(define IDC_ARROW 0x7F00)
(define COLOR_WINDOW 5)

; Window Messages
(define WM_CREATE  1)
(define WM_DESTROY 2)
(define WM_SIZE    5)

; Window Styles
(define WS_CHILD            0x40000000)
(define WS_VISIBLE          0x10000000)
(define WS_VSCROLL          0x00200000)
(define WS_OVERLAPPEDWINDOW 0xCF0000)

; Class styles
(define CS_VREDRAW          0x0001)
(define CS_HREDRAW          0x0002)

; ShowWindow constant
(define SW_SHOWDEFAULT 10)
(define SW_HIDE 0)
(define SW_SHOW 5)

; Edit control
(define ES_MULTILINE        0x0004)
(define ES_AUTOVSCROLL      0x0040)

; CreateWindowEx
(define CW_USEDEFAULT       0x80000000)

(import-list "kernel32" '(GetModuleHandleA))
(import-list "user32" '(PostQuitMessage DefWindowProcA))
(import-list "user32" '(RegisterClassA CreateWindowExA))
(import-list "user32" '(ShowWindow UpdateWindow MoveWindow DestroyWindow))
(import-list "user32" '(GetMessageA TranslateMessage DispatchMessageA))
(import-list "user32" '(LoadCursorA GetClientRect))


(@setq hInstance (GetModuleHandleA 0))
(@setq hTextbox nil)
(@setq hCursor (LoadCursorA 0 IDC_ARROW))

(struct 'RECT "long" "long" "long" "long")

(define (CreateTextBox hWnd)
(let (r (pack RECT))
(GetClientRect hWnd r)
(setq r (unpack RECT r))
(CreateWindowExA
0
"Edit"
""
(| WS_VISIBLE WS_CHILD WS_VSCROLL ES_MULTILINE ES_AUTOVSCROLL)
50 50 (r 2) (r 3)
hWnd
IDC_TEXTBOX
hInstance
0
))
)

(define (OnCreate hwnd wparam lparam)
(setq hTextbox (CreateTextBox hwnd))
)
(define (OnSize hwnd wparam lparam)
(let (rc (pack RECT))
(GetClientRect hwnd rc)
(setq rc (unpack RECT rc))
(MoveWindow hTextbox (rc 0) (rc 1) (rc 2) (rc 3) 1)
)
)

(define (OnDestroy)
(println "destroyed")
(PostQuitMessage 0)
)

(define (window-callback-function hwnd message wparam lparam)
(cond
((= message WM_CREATE) (OnCreate hwnd wparam lparam) 0)
((= message WM_SIZE)        (OnSize hwnd wparam lparam)   0)
((= message WM_DESTROY)     (OnDestroy)                   0)
(true (DefWindowProcA hwnd message wparam lparam))))

(setq wndproc (callback 0 'window-callback-function))
(setq classname "newlisp class")

(setq wc (pack (dup "ld" 10)
(| CS_HREDRAW CS_VREDRAW)   ; style
wndproc                     ; lpfnWndProc
0                           ; cbClsExtra
0                           ; cbWndExtra
hInstance                   ; hInstance
0                           ; hIcon
hCursor                     ; hCursor
(+ COLOR_WINDOW 1)          ; hbrBackground
0                           ; lpszMenuName
classname                   ; lpszClassName
))

(@setq hwc (RegisterClassA wc))
(@setq hwnd (CreateWindowExA
0                       ; dwExStyle
"newlisp class"         ; lpClassName
"newlisp Edit Control Test"        ; lpWindowName
WS_OVERLAPPEDWINDOW     ; dwStyle
CW_USEDEFAULT CW_USEDEFAULT CW_USEDEFAULT CW_USEDEFAULT           ; x y w h
0                       ; hwndParent
0                       ; hMenu
hInstance               ; hInstance
0                       ; hParam
  ))

(ShowWindow hwnd SW_SHOWDEFAULT)
(UpdateWindow hwnd)

(setq msg (pack "n28"))

(until (member (GetMessageA msg hwnd 0 0) '(0 -1))
(TranslateMessage msg)
(DispatchMessageA msg))

(println "the end")

(exit)


It's no probrem when typing english text, but when i press CTRL + SPACE switch to Chinese IME, and typing something,

appears three window: a IME status bar at bottom left corner of the screen, a small IME input window and an IME candidate window that following the caret.



The small IME input window and the IME status bar is blank. (It's not the right situation)



The candidate window shows what it should display, but when i choose one from the candidate list by clicked it, it's caused newlisp hangs.



In addition, you can not use CTRL + SHIFT to switch between different input methods.



My test environment is Windows 7 Ultimate 64 bit.



It's also has this issues on Windows XP SP3 32bit.



I guess this problem also exists in the Japanese IME case.



I captured the picture and recorded to video, hoping to describe the problem clearly.



The behaviors of edit window with IME, in normal case.

snapshot: http://upgrade99.byethost7.com/newlisp/normal.png">http://upgrade99.byethost7.com/newlisp/normal.png

demo: http://upgrade99.byethost7.com/newlisp/good.wmv">http://upgrade99.byethost7.com/newlisp/good.wmv



In the case that the edit window created from newlisp.

snapshots: http://upgrade99.byethost7.com/newlisp/hangs.png">http://upgrade99.byethost7.com/newlisp/hangs.png

demo: http://upgrade99.byethost7.com/newlisp/hangs.wmv">http://upgrade99.byethost7.com/newlisp/hangs.wmv



I found a link that describes the fault that is very similar to this. at https://bugs.chromium.org/p/chromium/issues/detail?id=402782">//https://bugs.chromium.org/p/chromium/issues/detail?id=402782
#6
Whither newLISP? / why setf don't work?
August 01, 2017, 08:03:04 AM

newLISP v.10.7.1 32-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h

> (struct 'RECT "long" "long" "long" "long")
RECT
> (unpack RECT (pack RECT 1 2 3 4))
(1 2 3 4)
> ((unpack RECT (pack RECT 1 2 3 4)) 0)
1
> (setf ((unpack RECT (pack RECT 1 2 3 4)) 0) 5)

ERR: symbol is protected : RECT
> (setq r (unpack RECT (pack RECT 1 2 3 4)))
(1 2 3 4)
> (setf (r 0) 5)
5
> r
(5 2 3 4)


why setf do in-place modifying don't work?

but

> (setf ('(1 2 3 4) 0) 5)
5
> (setf ((list 1 2 3 4) 0) 5)
5
#7
I want convert big float point number to integer.

> (int 999999999999999999999999999999999999999999.99)
9223372036854775807


I tried

> (bigint 999999999999999999999999999999999999999999.99)
1000000000000000045259160000000000000000000L


because of
Quote
When converting from floating point, rounding errors occur going back and forth between decimal and binary arithmetic.


And



> (bigint "1234567890123456789012345678901234567890.123456789")
1234567890123456789012345678901234567890L


this is what i expected



it means that needs to be converted to a string first



But,

> (bigint (string 1234567890123456789012345678901234567890.123456789))
1L

> (string 1234567890123456789012345678901234567890.123456789)
"1.23456789012346e+039123456789"


not "1234567890123456789012345678901234567890.123456789"



and also, the result is incorrect!



Distinctly, literal 1234567890123456789012345678901234567890.123456789 to be parsed as two parts "1234567890123456789012345678901234567890." and "123456789"



> 1234567890123456789012345678901234567890.123456789
1.23456789012346e+039
123456789


More tests

> (setq d 1234567890123456789012345678901234567890.123456789)

ERR: missing argument in function setf




> 100000000000000000.9876543210123456789
1e+017
456789

> (length "100000000000000000.9876543210123")
32

> 1000000000000000000.9876543210123456789
1e+018
3456789
> 10000000000000000000.9876543210123456789
1e+019
23456789
> 100000000000000000000.9876543210123456789
1e+020
123456789
> 1000000000000000000000.9876543210123456789
1e+021
342391             <----- Where it comes
89
> 10000000000000000000000.9876543210123456789
1e+022
10123456789
> 100000000000000000000000.9876543210123456789
1e+023
210123456789
> 1000000000000000000000000.9876543210123456789
1e+024
3210123456789
> 10000000000000000000000000.9876543210123456789
1e+025
43210123456789
> 100000000000000000000000000.9876543210123456789
1e+026
543210123456789
> 1000000000000000000000000000.9876543210123456789
1e+027
6543210123456789
> 10000000000000000000000000000.9876543210123456789
1e+028
76543210123456789
> 100000000000000000000000000000.9876543210123456789
1e+029
876543210123456789
> 1000000000000000000000000000000.9876543210123456789
1e+030
9876543210123456789L

> 10.1234567890123456789012345678901234567890
10.1234567890123
342391                  <----- Where it comes
890


Does considered support bigdecimal feature?
#8
(setq a 2) => 2

(setq 'a 3) => 3

(eval a) => 2

(eval 'a) => 2

(eval ''a) => a



(setq a 2) equivalent to (set 'a 2)

(setq 'a 3) equivalent to (set ''a 3)?

but result is:

(set ''a 3) =>

ERR: symbol expected in function set : ''a
#9
when a xml document has been converted to SXML, and how to remove all attribute-list of it? these attribute-lists inside diference level of SXML.