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

#1
newLISP in the real world / Lazy lists
November 07, 2009, 11:46:54 AM
I want work in newLISP with lazy data structures like that:
(define fibs
    (lazy-cat '(0 1) (map + fibs (rest fibs))))
(fibs 10) ; ==> 55

How to do this?
#2
This is suitable for me.

Many thanks!
#3
Sorry, misprint:

instead

"newLispEval("(+ 'x 4)");"

must be

"newLispEval("(+ x 4)");"
#4
Sorry for long silent.



I create file "eval.cgi":

#!/usr/bin/newlisp

(define (url-translate str)
   (replace "%([0-9A-F][0-9A-F])" str (format "%c" (int (append "0x" $1))) 1))

(print "Content-type: text/htmlrnrn")
(print (eval-string (url-translate (env "QUERY_STRING"))))
(exit)

# end of file


and file "test1.html":

<html>
<body>
<h3>newLISP server and JS demo</h3>

<script type="text/javascript" language="javascript">

if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

function newLispEval(expr) {
  xmlHttp.open("GET", "eval.cgi?" + expr, false);
  try {
    xmlHttp.send(null);
  } catch (e) { alert(e.message); }
  return xmlHttp.responseText;
}

var answer;
answer = newLispEval("(+ 3 4)");
document.write(answer);
document.write("<BR>ok.");
</script>
</body>
</html>
<!-- end of file -->


then I run
newlisp.exe -c -d 1235
and open browser for location:
http://localhost:1235//tmp/1/test1.html
and... it's work!

Thanks you.



But I still have some small problems:

1. Newlisp session not saved between requests:

after newLispEval("(set 'x 3)");
evaluation of newLispEval("(+ 'x 4)");
give me error "ERR: value expected in function + : x".

It is possible work form Javascript with one newlisp session?



2. Newlisp in server mode not support names with spaces?

Location like:
Quotehttp://localhost:1235//my">http://localhost:1235//my projects/q1/test1.html

not work for me.



3. It is possible explicit specify Windows drive letter in location?

Location like:
Quotehttp://localhost:1235//D/tmp/1/test1.html">http://localhost:1235//D/tmp/1/test1.html

not work for me.
#5
Sorry again :)

newlisp.exe -c -d 8080
#6
Sorry, misprint:

I run newLISP with line:

newlisp.exe -c -d
#7
Thanks you for reply.

I am beginner in newLisp and Javascritp.

Please, give me an example.

I try run newlisp:

  newlisp.exe. -c -d 8080

and open in browser this document:

 

<html>
<body>
<h3>newLISP server and JS demo</h3>

<script type="text/javascript" language="javascript">

if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

function newLispEval(expr) {
  xmlHttp.open("GET", "http://localhost:8080", false);
  try {
    xmlHttp.send(expr);
  } catch (e) { alert(e.message); }
  return xmlHttp.responseText;
}

var answer = newLispEval("(+ 3 4)n");

document.write(answer);
document.write("<BR>ok.");
</script>
</body>
</html>
<!-- end of file -->


but get NS_ERROR_FAILURE for "xmlHttp.send(expr);"
#8
newLISP and the O.S. / Calling newlisp from Javascript
November 03, 2009, 12:44:53 PM
I use newLISP as local http server on Windows platform:

  newlisp.exe -c -d 1235



It is possible send some string (like "(+ 2 3)") from Javascript to newLISP session

for evaluate and get back answer?