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

Messages - kosh

#61
Hi, Lutz.



I want to read a file in the "/proc" directory.

however `read-file' function returns empty string...


newLISP v.10.1.12 on Linux IPv4 UTF-8, execute 'newlisp -h' for more info.

> (read-file "/proc/cpuinfo")
""
> !cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 13
...
>


Parhaps, this problem is occurd in readFile(nl-filesys.c).

That function checks the filesize, and read by filesize.



But most /proc/* file looks empty file. therefore readFile() reads 0 byte in buffer without sys-error.


> !stat /proc/cpuinfo
  File: `/proc/cpuinfo'
  Size: 0         Blocks: 0          IO Block: 1024   regular empty file
Device: 3h/3d Inode: 4026531982  Links: 1
Access: (0444/-r--r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2010-04-24 04:09:15.028358255 +0900
Modify: 2010-04-24 04:09:15.028358255 +0900
Change: 2010-04-24 04:09:15.028358255 +0900


Therefoere, I think readFile() to use malloc/realloc method is better...



--- kosh
#62
newLISP and the O.S. / some HTTP functions error
April 10, 2010, 02:54:07 PM
## 1. Cannot restore context in (load "http://...")



for example...


newLISP v.10.2.1 on Win32 IPv4 UTF-8, execute 'newlisp -h' for more info.

> (print (get-url "http://gist.github.com/362201.txt"))
;; ...
(context 'MAIN)

> (context 'Foo)
Foo> (load "http://gist.github.com/362201.txt")
> (println "Context: " (context))
Context: MAIN                                 ; context changed!
>

> (reset true)

> (write-file "/tmp/test.lsp" (get-url "http://gist.github.com/362201.txt"))
> (context 'Foo)
Foo> (load "/tmp/test.lsp")
Foo> (println "Context: " (context))
Context: Foo                                    ; restore context
Foo>




## 2. (read-file "file:///C:/...") => "No such file or directory"


> (read-file "file:///C:/Program Files/newlisp/COPYING")
nil
> (sys-error)
(2 "No such file or directory")
> (read-file "file://C:/Program Files/newlisp/COPYING")
[text]
Copyright information...
[/text]


File URI scheme - http://en.wikipedia.org/wiki/File_URI_scheme#Windows_2">http://en.wikipedia.org/wiki/File_URI_scheme#Windows_2
QuoteOr for a local file, the hostname is omitted, but the slash is not (Note the third slash):



   file:///c:/path/to/the%20file.txt
#63
QuoteI've tried to create new process with the code below:

Code:
(process "newlisp.exe my-proc.lsp")


Prease try the following code:


(import "shell32.dll" "ShellExecuteA")
;; Open notepad.exe
;(ShellExecuteA 0 "open" "notepad.exe" "" 0 1)

(ShellExecuteA 0 "open" "newlisp.exe" "my-proc.lsp" 0 1)
;(ShellExecuteA 0 "open" "newlisp.exe" "my-proc.lsp" 0 0) ; with hidden console


On win32, ShellExecute function craetes a new process without waiting.

See also: http://msdn.microsoft.com/en-us/library/bb762153%28VS.85%29.aspx">//http://msdn.microsoft.com/en-us/library/bb762153%28VS.85%29.aspx



--- kosh
#64
In newlisp_manual.html, some lines that have a unbalanced double quotes(") are found.



Please see diff file below:


--- newlisp_manual-10.2.1-rev2.orig.html Tue Mar 30 02:59:58 2010
+++ newlisp_manual-10.2.1-rev2.html Tue Mar 30 03:12:13 2010
@@ -2099,7 +2099,7 @@
 
 ; strings
 
-(set 's "NewLISP)
+(set 's "NewLISP")
 
 (setf (s 0) "n") <span class='arw'>&rarr;</span> "n"
 
@@ -2590,7 +2590,7 @@
 </pre>
 
 <p>The <a href="#symbols">symbols</a> function is used to show all symbols
-belonging to a context"</p>
+belonging to a "context"</p>
 
 <pre>
 (symbols FOO) <span class='arw'>&rarr;</span> (FOO:func FOO:var FOO:x FOO:y FOO:z)
@@ -2896,7 +2896,7 @@
 ;; Variables used throughout this namespace
 
 (define db:handle)
-(define db:host "http://localhost)
+(define db:host "http://localhost")
 
 ;; Constants
#65
Thanks Lutz. I'm looking forward to next version release.



On another note the report added about illegal symbol.


> (legal? (uuid))
nil
> (define (gensym) (sym (uuid)))          ; make unique symbol use `uuid'
> (letex (s (gensym) v (gensym))
    (define-macro (my-setq s v)
      (set s (eval v))))
> (print (source 'my-setq))
(define-macro (my-setq 40DD3B92-C5D0-4E3D-BF2C-E63B963DD69B 4596AFF8-31F8-487B-B302-5149CD44AEED)
  (set 40DD3B92-C5D0-4E3D-BF2C-E63B963DD69B (eval 4596AFF8-31F8-487B-B302-5149CD44AEED)))

> (read-expr (source 'my-setq))
; symbol name separated!
(define-macro (my-setq 40 DD3B92-C5D0-4E3D-BF2C-E63B963DD69B 4596 AFF8-31F8-487B-B302-5149CD44AEED)
 (set 40 DD3B92-C5D0-4E3D-BF2C-E63B963DD69B (eval 4596 AFF8-31F8-487B-B302-5149CD44AEED)))


But, to resolve this problem in several ways.


;; 1. use legal symbol
(define (gensym)
  (sym (string "g-" (uuid))))           ; 'g-*** will be legal symbol

;; 2. use context
(context 'gensym)
(define (gensym:gensym)
  (inc *counter*)
  (sym (string "g-" *counter*)))        ; MAIN:g-***,gensym:g-*** will NOT conflict namespace
(context MAIN)

;; 3. use `args' function
(define-macro (my-setq )
  (set (args 0) (eval (args 1))))


--- kosh
#66
newLISP v.10.1.12 on Linux IPv4 UTF-8, execute 'newlisp -h' for more info.

> (legal? "#")
nil
> (new Tree (sym "#"))                  ; make context `#'
> (set (sym "one" (sym "#")) 1)         ; `#:one' = 1
> (set (sym "two" (sym "#")) 2)         ; `#:two' = 2
> (source (sym "#"))
"n(context '#)nn(set 'one 1)nn(set 'two 2)nnn(context MAIN)nn"
> (eval-string (source (sym "#")))
ERR: missing parenthesis : "...'one 1)nn(set 'two 2)nnn(context MAI"


Therefore, `save/load' function cannot use illegal symbol too.


(save "_hash.lsp" (sym "#"))
(load "_hash.lsp")                     ;-> ERR: missing parenthesis


--- kosh
#67
hello kukma.

I tried to make the newLISP.chm, and this is it.



http://cloud.github.com/downloads/kosh04/newlisp-files/newLISP.chm">http://cloud.github.com/downloads/kosh0 ... ewLISP.chm">http://cloud.github.com/downloads/kosh04/newlisp-files/newLISP.chm



But its simply comvert *.html to chm file,

so cannot use keyword-search and so on...



---

kosh
#68
newLISP and the O.S. / Re: format bugs, etc.
December 12, 2009, 03:12:07 PM
Quote(rand 0)'s different behaviour is well-documented...

mmm... I should check the documents.

sorry for misread the situation.
#69
newLISP and the O.S. / format bugs, etc.
December 12, 2009, 01:40:25 PM
## 1. `format' function returns a value different from `printf()'


(format "%#05x" 10)
;-> ERR: problem in format string in function format : "%#05x"

(import "libc.so.6" "printf")
(printf "%#05x" 10)
;-> 0x00a
;=> 5

(format "%c" 0)
; => "" (empty string)

(printf "%c" 0)
;-> ^@ ("00")
;=> 1


## 2. `(rand 0)' returns not integer value.
(rand 0)
;=> true


---

kosh
#70
You mean like this?


(define (mapflat f lst)
  (let ((visitor (lambda (x)    ; define internal function
                   (cond ((atom? x) x)
                         ("else" (apply f (map visitor x)))))))
    (visitor lst)))

(mapflat + '(1 2 3 (4 5 6 (7 8 9) 10)))
;=> 55

visitor
;=> nil


---

kosh
#71
Current for macro does same behavior


(for (i 3 0 +1) (println i))            ; print 3,2,1,0
(for (i 3 0 -1) (println i))            ; print 3,2,1,0

I think it will be work more better like this,


;; If `for' argument [num-step] no given, variable will increase by default.
(for (i 3 0) (println i))           ; <no output>
(for (i 3 0 +1) (println i))        ; print 3,4,5,... (not reached 0)
(for (i 3 0 -1) (println i))        ; print 3,2,1,0


---

kosh (not good at english...)
#72
Hello, Lutz. This is bug reports. (and first post)



`net-error' function occasionally returns a strange value when

the function given a number outside the range.


(net-error 12)                          ;=> (12 "Listen failed")
(net-error -1)                          ;=> (-1 "(null)")

(net-error 75)                          ;=> (75 "application/pdf")
(net-error 100)                         ;-> Segmentation fault


and `(sys-error 0)' return value is different from the manual.



newLISP-Manual wrote:
(sys-error 0)                           ;=> (0 "Unknown error: 0")
but program returns:
(sys-error 0)                           ;=> nil

---

kosh