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

#31
I`m going to create a small program, which will synchronize contents of two folders via TCP-IP.



Now I have an idea to start two newLISP servers and communicate via (net-eval) command. Something like



(net-eval "192.168.1.94" 4711 '(write-file "test.txt" (get-file "http://192.168.1.7/test.txt">http://192.168.1.7/test.txt")))



But this method seems to be unsafe: any villain can make my server to evaluate something evil.



May be there is some other way to send remote commands?
#32
Thank you. I`ll try these variants now.
#33
I`m trying to find some easy way to cut lists to the limited size.


(0 100 '("Some" "long" "list")) returns me first 100 dwellers of the list.



(By the way, expression (-100 100 '("Some" "long" "list")) says: "ERR: list index out of bounds" if the list is not long enough. But same expression works ok with strings).



Then I have tried to create a function, that will push an item to the list and cut it to the size I need.


(define (push-cut what where how-long)
  (push what where)
  (if (> (length where) how-long)
    (set 'where (0 how-long where)))
  0)


And... it won`t work. I have found some method in "Code Patterns": make a context and transfer variables like db:db.



But I`m pretty sure, there should be some other way to expain to the function, which variable I want to be pushed.
#34
newLISP in the real world / Re: define-macro and curry
November 12, 2009, 11:09:39 AM
Thanx, lambdas cleared for me a bit. I was surprised by timing: 0,031 ms for eval-string method and 0,0015 ms for the cons ones.



Btw, why is there 40E3BF in the expression?


(define (curry-all f)
  (append (lambda (z)) (list (cons f (append (args) '(z))))))

(curry-all + 1)
=> (lambda (z) (+ <40E3BF> 1 z))
#35
newLISP in the real world / define-macro and curry
November 12, 2009, 04:55:08 AM
I`m trying to make function curry-all, and my macro works, but... looks too ugly to be correct.


(define-macro (curry-all f)
  (letex (f1 f lst (map string (args)))
    (fn (z) (eval-string (append "(" (name 'f1) " " (join 'lst " ") " " (name 'z) ")")))))

((curry-all + 1 2 3 4) 5)

> 15


I think, there should be some easier way to ask LISP to expand args, right?
#36
newLISP in the real world / Re: (amb 'list)
October 31, 2009, 03:00:33 PM
Oh, thanx!
#37
newLISP in the real world / (amb 'list)
October 31, 2009, 01:52:05 PM
Trying to select a random value from the list.


(set 'mylist '((0 0) '(0 1) '(0 2)))
(amb mylist)


Result: ((0 0) (0 1) (0 2))



Different combinations of expand, eval, map and apply wont work in my hands. Only working method I have found is the monstercode with eval-string:


(eval-string (append "(amb '" (join (map string mylist) " '") ")"))

But there should be some simple solution, right?
#38
Quote from: "cormullion"Missing font, perhaps?


Aha, I`ll try tomorrow to change it.
#39
newLISP Graphics & Sound / Gui-Server: "sunked" letters
October 29, 2009, 06:09:42 AM
I have problems with "find" menu in GUI-server (letters are hidden somewhere below the fields, on screenshot I have a word "zulo" typed in the find-field):



http://img7.imageshost.ru/imgs/091029/52f65993ca/d437a.png">



System: Ubuntu 8. On Windows everything is ok.
#40
Thanks for a reading of my article, though. I was very surprised to find a link to it here.



After that Moscow elections I got some letters from readers, who asked to comment result and evaluate their cheating degree. So I decided to give them an instrument to convert raw-html-election to Excel format (and let them to think about it). It took about 60 minutes for me to make working crawler, and I was impressed with it: other programming languages I use are not so comfortable.



About utf8... yes, I had some problems with encoding, on Linux and Windows. As well as one guy with German Windows XP. But all my encoding problems are successfully solved already with special functions.



PS: One more "port" to other language:

http://fritzmorgen.livejournal.com/248335.html?thread=46957839#t46957839">http://fritzmorgen.livejournal.com/2483 ... #t46957839">http://fritzmorgen.livejournal.com/248335.html?thread=46957839#t46957839
#41
non-UTF upper- and low-case just do nothing with russian letters. (lower-case "A") -> "A", (upper-case "a") -> "a".



But that is really not too important: newLISP is comfortable enough to create any encoding function in coffee-cup time. Anyway I had to write my own functions to decode russian letters in URL, in POST-queries, in RTF-files etc.


(set 'cyr-alphabet (list "а" "б" "в" "г" "д" "е" "ё" "ж" "з" "и" "й" "к" "л" "м" "н" "о" "п" "р" "с" "т" "у" "ф" "х" "ц" "ч" "ш" "щ" "ъ" "ы" "ь" "э" "ю" "я" "А" "Б" "В" "Г" "Д" "Е" "Ё" "Ж" "З" "И" "Й" "К" "Л" "М" "Н" "О" "П" "Р" "С" "Т" "У" "Ф" "Х" "Ц" "Ч" "Ш" "Щ" "Ъ" "Ы" "Ь" "Э" "Ю" "Я"))

(define (cyr-low linea)
  (let (menudo "" letra "")
    (while (!= (set 'letra (pop linea)) "")
      (if (and (find letra cyr-alphabet) (> (find letra cyr-alphabet) 32))
        (push (cyr-alphabet (- (find letra cyr-alphabet) 33)) menudo -1)
        (push letra menudo -1)))
    menudo))


Screenshot:

http://img7.imageshost.ru/imgs/091027/6515c1b902/812d6.jpg">http://img7.imageshost.ru/imgs/091027/6 ... /812d6.jpg">http://img7.imageshost.ru/imgs/091027/6515c1b902/812d6.jpg
#42
I have a russian Windows with native Win-1251 and DOS-CP866 encoding. For some strange reason "upper-case" operator want not work:


(println (upper-case "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"))

Result:


"ࡢ㤥¸槨骫쭮ﰱ㴵縹콾"

Expected:


"АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"

Screenshots:

http://img7.imageshost.ru/imgs/091025/a6a681a191/e2e93.png">http://img7.imageshost.ru/imgs/091025/a ... /e2e93.png">http://img7.imageshost.ru/imgs/091025/a6a681a191/e2e93.png

http://img7.imageshost.ru/imgs/091025/b357b8e2bc/44605.jpg">http://img7.imageshost.ru/imgs/091025/b ... /44605.jpg">http://img7.imageshost.ru/imgs/091025/b357b8e2bc/44605.jpg



Version: newLISP v.10.1.5 on Win32 IPv4 UTF-8



Btw, in Ubuntu "upper-case" works allright:

http://img7.imageshost.ru/imgs/091025/35fb59f3ce/31ca8.png">http://img7.imageshost.ru/imgs/091025/3 ... /31ca8.png">http://img7.imageshost.ru/imgs/091025/35fb59f3ce/31ca8.png
#43
newLISP in the real world /
October 14, 2009, 10:23:26 AM
Thank you, now it is a bit shorter


(define (parse-html texto)
  (map (fn (x) (map (fn (y)
    (find-all "(?si)(<t[dh])(.*?)(</t[dh]>)" y
      (replace "(?si)</?t[dh](.*?)>" (copy $it) "")))
    (find-all "(?si)(<tr)(.*?)(</tr>)" x)))
  (find-all "(?si)(<table)(.*?)(</table>)" texto)))
#44
newLISP in the real world / Find-all + Replace = Crash
October 14, 2009, 07:16:27 AM
I meet some problems during attepts to create (html-parse) function. Here are two functions, which do the same: both function suppose to extract data from "td" tags.


(define (sacar-td linea)
  (set 'alveolos (find-all "(<td)(.*?)(</td>)" linea $0 1))
  (map (fn (x) (replace "</?td(.*?)>" x "" 1)) alveolos))

(define (crash-td linea)
    (find-all "(<td)(.*?)(</td>)" linea (replace "</?td(.*?)>" $0 "" 1) 1))

(set 'testrow "<tr><td class='kin'>Alpha</td><td>Gamma</td></tr>")


Longer one, "(sacar-td testrow)" works ok. Shorter one, "(crash-td testrow)", crashes the shell:



> (sacar-td testrow)

("Alpha" "Gamma")

> (crash-td testrow)

*** glibc detected *** /usr/bin/newlisp: double free or corruption (fasttop): 0x080cc808 ***

======= Backtrace: =========

/lib/tls/i686/cmov/libc.so.6[0xb7e31a85]

/lib/tls/i686/cmov/libc.so.6(cfree+0x90)[0xb7e354f0]

...



It is the first strange thing.



Second problem -- my repexps works ok only if I replace all "n" to " " before searching.



Update: accidentaly found solution for the second problem, it is "(?s)" key. Now my "parse-html" function works:


; Usage (parse-html (get-url "http://www.newlisp.org/downloads/newlisp_manual.html"))
(define (parse-html texto)
  (map sacar-table (find-all "(?s)(<table)(.*?)(</table>)" texto $0 1)))

(define (sacar-td linea)
  (set 'alveolos (find-all "(<t[dh])(.*?)(</t[dh]>)" linea $0 1))
  (map (fn (x) (replace "</?t[dh](.*?)>" x "" 1)) alveolos))

(define (sacar-table linea)
  (map sacar-td (find-all "(?s)(<tr)(.*?)(</tr>)" linea $0 1)))
#45
newLISP in the real world /
October 13, 2009, 08:55:51 AM
Thanx! Now it works.



Btw, Spanish is very useful for me to name functions. I can define something like "buscar", "cargar" or "destripar" and be sure, that these symbols are not protected.