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

#1
Anything else we might add? /
April 23, 2009, 01:15:30 PM
This is great. Thanks a lot!
#2
Anything else we might add? /
April 22, 2009, 05:29:33 PM
Marc



I am also new to newlisp. When I first found it I browsed the newlisp source and found that the http connection code is single threaded and blocks on more than one connection.



In order to use newlisp in a more robust server setting I'm playing with apache/cgi. Simply set up a webfolder, enable cgi in your apache server, and create an index.cgi script (with executable permissions) and you're in. Writing code to parse HTTP requests is an excellent exercise to familiarize yourself with newlisp :)



I use apache mod_rewrite to map arbitrary path requests through index.cgi and into handler code which enables me to model a RESTful(ish) sytle service. mod_rewrite should be present in any recent-ish apache dist, but might not be enabled by default in apache.conf (or httpd.conf, depending on dist), and there are lots of tutorials online. (Make sure you add AllowOverride to the Options statement in your apache configuration for the web directory in which you're using rewrite -- this has tripped me up a couple times and is tough to debug).



Anyway, I'm quite interested in the possibility of using newlisp's spawn, net-listen, net-accept, etc. to whip up a nice multi-threaded server with child threads spawning per connection and inheriting the parent symbol space. This would make for a very interesting and powerful dynamic system, customizable on the fly.



If you decide to try the apache stuff, feel free to post back here and I'll walk you through whatever you might have trouble with.



Cheers
#3
newLISP newS /
April 09, 2009, 12:56:14 PM
Quote from: "Kazimir Majorinc"Thanx, itistoday.

Lutz, maybe letex should be replaced or supported with evlex?



(eval (letex ((x 1)) '(f x)))


quoting the expr and wrapping in eval does the trick for me[/code]
#4
Quote from: "Kazimir Majorinc"So you used nested function call to transfer arguments in nested function so you do not have to use any variable at all. As (arg n) are always local, accidental overshadowing is impossible. Very interesting idea.  



Welcome to the forum.


Thanks! While this particular problem is unlikely to arise in any real-life work (after all, we have 'or), I think the basic underlying idea is potentially quite useful.
#5

(define-macro (my-or)
  (
    (lambda ()
      (if (args 0)
        (args 0)
         (eval (args 1))
      )
    )
    (eval (args 0))
    (args 1)
  )
)


This solution uses a lambda to store the eval'ed first arg to the macro and defer evaluation of the second. It's not as fast as the solution presented by lutz, which has an execution time about 65% of mine, probably because mine entails an extra function call. But it does, at least, avoid the need for creating a new context just for one simple macro. This was a fun and surprisingly challenging problem. Thanks, itistoday!