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

#21
When running newLisp in web mode and using the DragonFly framework, I've noticed redirection works fine, except when someone types something like:


http://server//root-file

In this case, it grabs the /root-file contents and displays them as plain text in the browser.



Am I missing some obvious setting? This is clearly a problem.
#22
newLISP newS / Artful Code
August 16, 2011, 01:32:03 PM
I have taken over maintenance and coding for all the Artful Code modules and plan some pretty significant updates to them over the next months.



The new location is at http://www.scruffythinking.com/">//http://www.ScruffyThinking.com/ under "Artful Code" heading.



The project has been permanently moved to ScruffyThinking and to github.



Please update your links accordingly.
#23
newLISP and the O.S. / newlisp OS X Lion Bus Error
August 14, 2011, 05:13:06 PM
I have a program I've been running for many months. I upgraded to newLisp 10.3.2 and to OS X Lion.



Now, running


newlisp server.lsp -c -d 8080 -w .

And loading my index.cgi (unchanged) through the "server.lsp" code (see below) causes a BUS ERROR.


Quotesh: line 1: 22042 Bus error: 10

./"index.cgi" > /tmp/nl490825a2887b33a41d



#!/usr/bin/env newlisp
(command-event (fn (s)
    (local (request)
        (if (find "?" s) ; is this a query
          (set 'request (first (parse s "?")))
          (set 'request s)
        )
      request)
))


Again, code worked on 10.6.x and newlisp 10.3.1. Is there something that changed and I missed it in the newlisp web code?
#24
What the ****?!?


(setf stopme nil)
(while (nil? stopme)
  (setf r (read-line))
  (if (find "exit" r) (setf stopme true))
  (println "Line: " r)
)


Run this. Type a few keys, hit ENTER.



Now, hit CONTROL-D



(be prepared to hit Control-Z and then kill newlisp)
#25
Whither newLISP? / Common Lisp newLisp module?
May 05, 2011, 12:11:36 AM
Just curious...



Has anyone taken the time to port the basics of ANSI Common Lisp to newLisp as a loadable module?



I am considering writing a CL inside newLisp, so I can use "normal" Common Lisp expressions and functions in my newLisp code, but use newLisp specific things when it makes sense.



Yes, Lutz, I am aware this somewhat defeats the purpose of newLisp, but I want to do it anyway. :)



Seems like it would not be that hard to do.



<famous last words>



Imagine (from Land of Lisp http://landoflisp.com">//http://landoflisp.com) inside newLisp:



(defvar *small* 1)
(defvar *big*   100)

(defun guess-my-number ()
   "Documentation for guess-my-number."
   (ash (+ *small* *big*) -1))

(defun smaller () (setf *big* (1- (guess-my-number))) (guess-my-number))
(defun bigger () (setf *small* (1+ (guess-my-number))) (guess-my-number))
(defun start-over ()
   (defparameter *small* 1) (defparameter *big* 100) (guess-my-number))
#26
newLISP in the real world / TextMate Bundles
May 04, 2011, 10:11:39 PM
It always drove me crazy that the TextMate newLisp.bundle(s) out there did not support modern keywords in newLisp and they did not support entities.



What I mean is:



(setq my-var 1)



In the regular TextMate newLisp bundles, "my-var" is not treated as an entity.



So, I've been playing with some changes to the Bundle.



If you do not have the original (and currently my favorite) Bundle, it is here]https://github.com/taoeffect/newLISP.tmbundle[/url]



1. Go into TextMate

2. Select Bundles

3. Select Bundle Editor + Languages

4. Paste the gist https://gist.github.com/956566">//https://gist.github.com/956566 contents into the Edit Language "newLisp" area.



I'm constantly improving it and will post changes to the gist.



Yes, it is 10.3+ compatible. :)
#27
I should be able to specify command-line options to be used with (main-args)
$ newlisp -word hi

ERR: no working directory found


This is a problem, because I did not specify "-w <working directory>" -- even though newLisp believes I did.



Maybe check for a space after -w?
#28
newLISP in the real world / Collatz Conjecture
April 30, 2011, 11:56:37 AM
I'm working on a New Lesson in Lisp this week and decided to tackle Collatz Conjecture.



I am going to express the code two ways. Firstly, as a 'standard' programming example and secondly as a Lisp programming example.



So, I thought I'd share the standard example and give the forums a chance to comment and optimize or convert to a more Lisp-y way of doing things.


;
; http://streamtech.nl/problemset/100.html
; aka http://en.wikipedia.org/wiki/Collatz_conjecture
;

(define (collatz)
   (println "Collatz Conjecture: low high (ENTER/RETURN to end)")
   (until (= (set 'p (read-line)) "")
      (set 'in (map int (parse p " ")) )
      (set 'low (in 0) 'high (in 1))
      (set 'max_count 0)
      (dolist (num (sequence low high))
         (set 'cnt 1)
         (while (!= num 1)
            (if (!= (mod num 2) 0)
               (set 'num (+ (* 3 num ) 1))
               (set 'num (/ num 2))
            )
            (inc cnt)
            (if (< max_count cnt) (setf max_count cnt))
         )
      )
      (println low " " high " " max_count)
   )
)

(collatz)


The results from this code are:



1 10

1 10 20

100 200

100 200 125

...
#29
newLISP in the real world / Interesting Challenge...
April 29, 2011, 06:42:27 PM
I was reading a post on Craig's List where a company was asking for resumes, but they wanted you to solve a specific problem first.



As I do a ton of work like this, I thought it would be interesting to share and talk about.



I have settled on a way to do this without building a matrix, but I want to make sure it works for all 250,000 words in the word-list (below) before I post the results.



(it's in code form so you can copy and paste into your program ;) )


;
; Two words are friends if they have a Levenshtein distance of 1.
; That is, you can add, remove, or substitute exactly one letter in
; word X to create word Y.
; A words social network consists of all of its friends, plus all of
; their friends, and all of their friends friends, and so on.
;
; Write a program to tell us how big the
; social network for the word causes is, using this word list:
; https://github.com/causes/puzzles/raw/master/word_friends/word.list
;
; http://en.wikipedia.org/wiki/Levenshtein_distance
;
; tons of implementations in several languages
; http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance
;
; a working HTML version
; http://www.miislita.com/searchito/levenshtein-edit-distance.html
;
#30
I've been [re]learning Lisp (not newLisp) a little bit over the last few weeks, while writing my Lessons in Lisp stuff and I stumbled across a Language Popularity index http://www.langpop.com/#normalized">//http://www.langpop.com/#normalized a Wikipedia page about Common Lisp http://en.wikipedia.org/wiki/Common_Lisp">//http://en.wikipedia.org/wiki/Common_Lisp.



I'd seen both before, but I was struck by something specific.



The Common Lisp (until) macro example from the Wiki entry:



(until (= (random 10) 0)
  (write-line "Hello"))


I tried to think about how I might represent both the actual value and the number of iterations in Common Lisp.



In newLisp, it's a piece of cake (there are probably even easier ways to do this).



(until (= (set 'x (rand 10)) 0)
  (println  $idx ":" x " not 0"))


Just sharing a thought or two...
#31
newLISP in the real world / Replacing HTML codes
April 17, 2011, 12:25:17 PM
I have a series of lists, which contain something like:



"Telef&#243;nica to Sell Spanish Assets"



I want to be able to quickly change all these codes to their proper ascii characters.



(set 'x "Telef&#243;nica to Sell Spanish Assets")
(find {&#(.*);} x 0)  ; reference only
(regex {&#(.*);} x)
; > ("&#243;" 5 6 "243" 7 3)
> $1
; > "243"
(char (int $1))
; > "รณ"


My question?



How can I do the above in one quick pass, where I get all the {&#(.*);} and replace them with (char (int $1)) ... without doing a loop through everything over and over until the (regex) finds nothing?



I feel like I am missing some (map) or (replace) iterative operator.
#32
I am processing tens of thousands of bits of data per minute (and, sometimes, per second).



I have information coming in as a list in the form '(0 30 55 200 0 1) and I have a reference in a similar format.



I need to match the contents of my known lists with the new list which has just arrived. And, it needs to be very fast.



Thanks to Lutz (and others), I have come up with a good solution, but I need it to be faster.



Starting with the reference lists

(dolist (s (sequence 1 100))
  (set 'n (rand 255 (rand 100)))
  (push n e -1)
)


Now we have a list of 100 reference lists, which we need to match to a new list containing one of the referenced lists.



(set 'f (rand 255 100))  ; create a new list
(push (e (rand (length e))) f) ; grab from 'e above and push into our list


Now, if we convert everything to hex and do a check...



(set 'eh (map (fn (l) (pack (dup "b" (length l)) l)) e))  ; convert to hex (much faster!)
;
(set 'hex (pack (dup "b" (length f)) f))
(clean nil? (map (fn (s) (find s hex)) eh))
;> (n) ; where n is the location found
;
(time (clean nil? (map (fn (s) (find s hex)) eh)))
;> ~ 1ms  ; this is too slow


I only care about that last bit, where I am using a (clean) and (map) to find the hex. Right now, it tops out at ~1 ms (on my laptop) and about ~4ms on my reference system. This is painfully slow for the amount of traffic I am processing.



Any thoughts would be appreciated.
#33
newLISP in the real world / (timer) fails on (fork)
April 12, 2011, 08:14:27 PM
Say you have :



;
; a define
(define (foo)
 (println "Oh Yeah.")
)
;
; and another
(define (foobar)
 (dolist (s (sequence 1 10))
   (sleep 1000)
 )
)
;
; and a timer:
(define (ImaTimer)
  (foo)
  (timer 'ImaTimer 1)
)
;
; and, some code:
(println "Setting timer...")
(ImaTimer)
(println "Forking...")
(fork (foobar))
;(foobar)
(exit)


The problem is, the timer never fires in the forked process.



But, if you do not fork, changing (fork (foobar)) to just (foobar) the timer works fine.
#34
newLISP in the real world / Faster than intersect?
April 12, 2011, 05:33:03 PM
While I am asking about speed...



I am trying to find a set of values within another, larger set of values:



(I removed some of the code formatting so bold items appear properly)



The big string is:

(set 'big '(1 1 5 10 82 222 118 135 82 222 120 79 10 235 83 241 225 229 147 140 238 0 61 97 224 64 31 205 40 134 125 48 169 148 82 132 66 51 32 246 120 99 236 162 100 96 169 220 227 31 11 99 42 103 41 161 227 204 234 48 49 137 236 124 132 152 255 89 121 201 120 199 2 105 6 126 52 120 23 157 57 90 212 125 158 47 33 57 4 200 126 118) )



The substrings are:



(set 'subs '((89 71 0 11 0 0 0 0 0 18 0 0 0 0)

 (92 0 116 0 101 0 115 0 116 0 46 0 112 0 119 0 100)

 (97 37 97 37 97 37 97 37 97 37 97 37 97 37)

 (101 32 99 108 105 101 110 116 32 105 110 102 111 114 109 97)

 (101 122 105 112 58 47 47 98 108 97 47 98 108 97 63 83 78 61 98 108 97 63 80 78 61 98 108 97 63 85 78 61 98 108 97)

 (103 0 115 0 101 0 99 0 100 0 117 0 109 0 112 0 46 0 101 0 120 0 101)

 (108 0 115 0 114 0 101 0 109 0 111 0 114 0 97)

 (133 0 0 1 0 1 0 1)

 (171 205 9 128 0 0 0 1 0 0 0 0 0 0 1 0 1)

 (186 213 25 93 134 103 213 142 127 188 208 60 110 216 226 23 22 232 58 159 207 89 184 123 246)

 (200 79 50 75 112 22 211 1 18 120 90 71 191 110 225 136)

 (201 120 199 2 105 6 126 52 120 23)

 (211 200 197 204 204 197 216 197 195 213 212 197)

 (243 232 229 236 236 229 248 229 227 245 244 229)) )



I have tried several different ways to to this:

(map (fn (c) (if (= c (intersect c big true)) true nil)) subs)
; (nil nil nil nil nil nil true nil nil nil nil nil nil nil nil nil nil true nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil true nil nil)
(find true
 (map (fn (c) (if (= c (intersect c big true)) true nil)) subs))
; 6, 17
;
; But, the time is 100 milliseconds or more...


What am I missing? There has to be a faster way.
#35
newLISP in the real world / Faster than find?
April 12, 2011, 05:13:17 PM
I have the following issue:



> (dolist (s (sequence 1 10000)) (push (rand 300 4) y -1))
> (set 'z (y -2))  
; this is the second to last {number} :)
> (time (find z y))
; 8.x ms


Why is this a problem? I need a faster search through these numbers. 8+ milliseconds is way too long.



The numbers must be in this format, or something very close. Any extra processing to convert the input (which is z in this case) could take too long.



I can happily convert the y to a better format, if it improves the search speed.



Is there a faster find I should be considering?
#36
newLISP in the real world / date + parse problems
March 25, 2011, 01:03:01 PM
I use parse all over the place in my code. I recently ran into a very strange problem with parse.



> (set 'x 1301073325)
1301073325
> (date x)
"Fri Mar 25 10:15:25 2011"
> (parse (date x))
("Fri" "Mar" "25" "10" ":" "15" ":" "25" "2011")


Looks good. Parses correctly, but when the time changes...



> (set 'x 1301071976)
1301071976
> (date x)
"Fri Mar 25 09:52:56 2011"
> (parse (date x))
("Fri" "Mar" "25" "0" "9" ":" "52" ":" "56" "2011")


Notice "09:52" is being parsed as "0" "9" ":" "52" instead of "09" ":" "52"



I am running newLisp 10.3.0
#37
newLISP in the real world / Simple pid file check
February 23, 2011, 11:49:00 AM
Hello all,



I am interested in testing for a running process and, if it is not running, restarting it.



Right now, I'm writing /tmp/app.pid files for everything I run. If I need to stop a running app, I call:


(destroy-pid (int (read-file "/tmp/app.pid")))

Which works, of course.



But, I want to test to see if the pid is actually running. Is there a clean, easy way to do this (something I am missing in unix.lsp, for example?)



Thanks.
#38
newLISP in the real world / PHP Redirect unless site down
February 12, 2011, 12:39:44 PM
(for those who have been asking)



I created this because I am redirecting all traffic from port 80 to port 8080. Port 8080 runs a newLisp web server and DragonFly, but it could be running anything.



Sometimes, for whatever reason, my ISP decides to kill the newLisp process.



So, this redirects people to a "maint.html" page when that happens.



I hope this is as useful for everyone else as it has been for me.



Plus, it's super fast and simple PHP code.


<?php
        $site 
"www.mysite.com";
        
$port 8080;
        
$fp fsockopen($site,$port,$errno,$errstr,10);
        if(!
$fp)
        {
                
$fd fopen("maint.html"r);
                
$content fread($fdfilesize("maint.html"));
                
fclose($fd);
                echo 
$content;
        }
        else{
                
header("Location: http://www.mysite.com:8080");
                
//echo "Connect was successful - no errors on Port ".$port." at ".$site;
                
fclose($fp);
                exit;
        }
        
//
?>

#39
newLISP in the real world / (lookup nil x) -> 1st item?
January 28, 2011, 06:02:02 PM
Try this:

> (set 'tr '( (1 "foo") (2 "bar") (3 "baz")))
((1 "foo") (2 "bar") (3 "baz"))
> (lookup nil tr)
"foo"


Unless I'm missing something, shouldn't (lookup) return nil?



By the way, I got here because I'm actually doing:
(lookup x tr)
And x can be nil.
#40
I have dozens of newLisp modules. Each of these modules needs to be reviewed and cleaned up by someone who knows newLisp (and JSON and networking, hopefully). Some of the modules are small, some are large.



It pays, via Paypal, based on small set pieces of code that need to be cleaned up.



Each module is between $50 and $100 for a code review and cleanup. If a bunch of new code needs to be written, we'd negotiate that as a new project.



It's pretty straightforward, I'm just looking for more eyes on the code and trying to help the newLisp community make a little extra cash for the holidays (and, of course, fix my code!).



Here's a terrible, quickly written example with comments:
;; @syntax Util:Interfaces
;; @return <list of interfaces>
;; @param NA
;;
(define (Interfaces)
(set 'iface (exec "ifconfig -a"))
(set 'final-iface nil)
(dolist (x iface)
(set 'curline (trim x "tt"))  
; (println "Current line" $idx " : '" curline "'")
;; Get the interface, if it exists
(when (find "0: flags" curline )
(set 'myface ((parse curline) 0)) )
(when (starts-with curline "status: ")
(when (= "active"((parse curline) 1))
;(Log:Print "Result"  "Adding interface: " myface)
(push myface final-iface -1)
)
)
;(println $idx "|" (trim x "tt"))
;; hold it
;; check for status: active
;; save the interface (which is active) to the list
;; return active interface list
(set 'return-interfaces final-iface)
)
)