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

#16
I have suddenly noticed, that newLISP directory operator returns his data in UTF8 codepage, while native Windows XP codepage (in Russia) is windows-1251 (and newlisp-edit.lsp module has windows-1251 encoding too).



That is not an important problem, becouse I always can use construction like


(map decode-utf8-to-cp1251 (directory "."))

Fortunately, russian alphabet is 33 letters only, so decoding is easy. I just want to ask about future politics: will newLISP in the future have an operator like *nix iconv?
#17
Whither newLISP? / Prime numbers
March 23, 2010, 02:46:24 PM
Found today a story about a boy, who was said by a teacher to print all prime numbers from 2 to 100. He had 2 hours to make a program on Basic. Boy had a working code in ten minutes:


10 CLS
20 PRINT "2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97"
30 END


I have tried to translate this program to newLISP:


(define (prime? x) (= (first (factor x)) x))
(println (filter prime? (sequence 2 100)))


My code is as short as Basic one, but it is still 20% slower than a sample code from newLISP manual:


(define (primes n , p)
  (dotimes (e n)
    (if (= (length (factor e)) 1)
      (push e p -1))) p)
#18
Quote from: "HPW"How about... source


Thanx, "source" looks promising for me. Only problem: source + sym dislike lists for some reason:


> (set 'test '(("a" '(1 2 3 4 5)) ("b" 52) ("c" "something")))
(("a" '(1 2 3 4 5)) ("b" 52) ("c" "something"))
> (source (sym (test 1 1)))
"(set  (sym "52" MAIN:MAIN)  nil)nn"
> (source (sym (test 0 1)))

ERR: number or string expected in function sym : (test 0 1)
#19
I have a variable, which contains some text with special symbols:


> {some symbols /""}
"some symbols \/"""


I want to save contents of this variable to the text file, with all that backslashes before quotes et cetera. Now I use function


(define (gnirts-lave x)
  (1 -1 (string (list x))))


But, may be, there exists more direct way to get "texted" value of a variable?
#20
Aha, I see now. I will span now intervals from 50ms and longer in Windows. 68 years should be enough for me too :)
#21
I have tested today some scripts operating with some millions files, and I have noticed two strange things about (time) function.



1. Big intervals.


> (time (sleep 3600000))
1,844674407e+016


1,8e+016ms = 595 000 years, hehe.



2. Small intervals.


> (time (read-file "100_13.txt") 70)
0
> (time (read-file "100_13.txt") 80)
0
> (time (read-file "100_13.txt") 90)
15,625
> (time (read-file "100_13.txt") 90)
0
> (time (read-file "100_13.txt") 90)
15,625


15,625 = 1/64 second. So, I think, 15,625 ms — is a minimal quant, that can be measured with (time) command. But today I have seen results like 0,010 ms and so on... Only idea I have, there is some difference between Windows and Linux: «15,625 limit» exists in Windows only.



Anyway, I use (time) very often, so it would be really useful for me to know, how (time) function works on small intervals.
#22
newLISP and the O.S. / Re: (+ newLISP Windows RS232)
March 08, 2010, 08:27:46 PM
Quote from: "itistoday"Couldn't you use the "import" function to import the necessary C functions from some windows DLL?


Well, I'll try. I'm not too familiar with C, but it is a good reason to learn it closer.
#23
I have found a solution. In "newlisp-edit" script there is a function "(openFindDialog)", which sets size of the "Find" window.



After changing width to 500 I can see all my letters:


(gs:dialog 'FindDialog 'TheEditor "Find text" 500 200 nil nil)
#24
newLISP and the O.S. / Re: get-url with redirection?
March 07, 2010, 11:00:58 AM
You can also look into the text "get-url" returns to you. I believe, inside you will find a correct address of the file.



First get-url:
(get-url "http://lenta.ru/info")

Result:
"<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">n<html><head>n<title>302 Found</title>n</head><body>n<h1>Found</h1>n<p>The document has moved <a href="http://lenta.ru/info/">here</a>.</p>n<hr>n<address>Apache Server at lenta.ru Port 80</address>n</body></html>n"

Parsing correct address:
(first (regex {(?<=href=")[^"]+} (get-url "http://lenta.ru/info")))

Result:
"http://lenta.ru/info/"

Final get-url:
(get-url (first (regex {(?<=href=")[^"]+} (get-url "http://lenta.ru/info"))))
#25
Thank you very much! I just realized, that I can open newlisp-edit.lsp and add there regexp search, parameters save, higher search fields and other functions I miss so!
#26
newLISP and the O.S. / (+ newLISP Windows RS232)
March 07, 2010, 10:47:46 AM
I need to communicate with standart rs-232 serial port on PC.



Is it possible to write on newLISP something like (read-port "COM1" 20)?
#27
Quote from: "Lutz"You could use 'base64-enc' and 'base64-dec' instead, they are fast.


They are fast, but they use "+" in some circumstances (russian letters):


(base64-enc " " remote-file?: Нет ответа о")
"ICIgcmVtb3RlLWZpbGU/OiDQndC10YIg0L7RgtCy0LXRgtCwINC+"


This "+" is not good for POST-URL.



Update: solved this with replace


(define (base62-enc text)
  (replace "=" (replace "+" (replace "/" (base64-enc text) "_s") "_p") "_e"))

(define (base62-dec text)
  (base64-dec (replace "_e" (replace "_p" (replace "_s" text "/") "+") "=")))


It is twice as slow as base64 ones, but still ten times faster, than my home Internet connection.
#28
I failed to expain Apache2 "Script PUT" directive. So I have solved it this way (on pure newLISP):



upload.cgi:
#!/usr/bin/newlisp
#
# Recieves and stores remote file
#
(module "cgi.lsp")
(module "crypto.lsp")

(set 'upload-dir "tmp/")

(print "Content-Type: text/htmlnn")

(if-not (= (CGI:get "password") (crypto:md5 "password"))
  (begin (print "Access denied.") (exit)))

(set 'flnm (append upload-dir (CGI:get "filename")))

(write-file flnm (hex-unpack (CGI:get "data")))

(if (= (crypto:md5 (read-file flnm)) (CGI:get "md5"))
  (print "Success.")
  (print "Fail."))

(exit)


Remote code:
; Usage: (put-remote "/tmp/" "test.doc")
(define (put-remote pth flnm)
  (post-url "http://localhost/cgi-bin/upload.cgi" (append
    "password=" (crypto:md5 "password") "&"
    "filename=" flnm "&"
    "data=" (hex-pack (read-file (append pth flnm))) "&"
    "md5=" (crypto:md5 (read-file (append pth flnm))))))

; Sample file transfer
(put-remote "/tmp/" "fridl.7z")


Hex packing functions:
; Usage: (hex-pack (read-file "test.7z")) => "377ABCAF271C0002292C1..."
(define (hex-pack linea)
  (join (map (fn (x) (format "%02X" x)) (unpack (dup "b" (length linea)) linea))))

; Usage: (write-file "test.7z" (hex-unpack "377ABCAF271C0002292C1..."))
(define (hex-unpack linea)
  (join (map (fn (x) (pack "c" (int (append "0x" x)))) (explode linea 2))))


This combination works. My hex-packing functions are extremely slow but on files below 10Mb it is not important.
#29
May be it will be more safer then to transfer data via http, .cgi and POST.
#30
Quote from: "Lutz"You could set up a SSH tunnel for 'net-eval' (only on UNIX like OSs)


Yep, one of PC's has the Windows OS. But I think SSH will work on Windows too.