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

#1
Hi Gregor,

For similar purpose I start a server with something like:
newlisp.exe -c -d 4780 -w ..MyProjectsToWeb
(on Windows OS)



In  ..MyProjectsToWeb I've put index.cgi which might look like (minimalistic):



#!/usr/bin/newlisp

(print "Content-type: text/htmlrnrn")
(module "cgi.lsp")

(define (my-hubert) (println "<h3>Hello World!</h3>"))

(apply (read-expr  (CGI:params 0 0)))

(exit)


Then I open in a browser http://localhost:4780/?my-hubert">http://localhost:4780/?my-hubert



:) Not the absolute elegance, but it works...



PS notes:

- I don't remember why I left -c parameter when starting the server. May be it's not important and -http will be fine too

- The first line of index.cgi is important for Linux. I use the same code on both Windows and Linux machines at home.

- In index.cgi you can use (load "path-to-some-newlisp-file") to load more functions and/or data, of course.

- I'm using this for a very simplistic implementation of Wiki combined with Markdown-like coding ... it's great fun to see it working with so small code :)



Good Luck and please, share how Your experiments go.



PPS. I'm sorry, I didn't pay enough attention to httpd-conf.lsp. It's obvious, that the command-event function could transform a nicer "outside" url like http://localhost:4780/my-hubert">http://localhost:4780/my-hubert to the "inner" for my approach url, i.e. http://localhost:4780/?my-hubert">http://localhost:4780/?my-hubert
#2
newLISP in the real world / Re: set - setf - setq woes
August 23, 2017, 05:38:24 AM
Hi,



Shortly, set is a "classical" function - it evaluates its arguments. That's why you quoted vowels - to prevent evaluation.



setq and setf are synonyms in NewLisp. The names are inherited from other (Common) Lisps.

They are "special forms".

If the first argument is a symbol, the value of the evaluated second argument is assigned directly to that symbol, without evaluating the first argument.

Otherwise, the first argument is evaluated and if the result is a valid reference, the second argument value is destructively assigned to the place, where the reference points.



s.v.
#3
Hi,



I'm still on a previous version and there's no problem ...

newLISP v.10.6.2 32-bit on Win32 IPv4/6 UTF-8 libffi, options: newlisp -h

> (setq str (dup "00" 32))
"0000000000000000000000000000000000000000000000000000000000000000"
> (trim str)
""
> (setq str (dup "00" 52))
"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
> (trim str)
""
>


Yours,

s.v.
#4
Hi guys,



Sorry for posting on a solved task, but I just can't resist temptation to show my context version. :) No regular expresions, no (explicit) search/replace. :)

(define *people*
      '((("name" "John")
         ("age"  37)
         ("city" "NY"))
        (("name" "Giorgos")
         ("age"  25)
         ("city" "Athens"))
        (("name" "Elena")
         ("age"  43)
         ("city" "Amsterdam"))))

(define *template* ":name: lives in :city: and is :age: years old.")

(setq parsed-template (parse *template* ":"))

(define data:data)     ; defines context to hold one person data

(dolist (p *people*)
(data p)
(dolist (str parsed-template)
(print (or (data str) str)))
(println))


Yours,

s.v.
#5
Hi,



Try

(define cities:cities)         ; creates the default functor
(cities '(("ny" "new york") ("sf" "san francisco")))        ; the functor adds the data
(cities)


s.v.
#6
Just for fun, Your definition rewritten ... :)
(define (lipsum2 (what "paras") (amount 3) (start "true"))
     ((xml-parse (get-url (format "http://www.lipsum.com/feed/xml?what=%s&amount=%d&start=%s" what amount start)) 7)
       0 2 0 2 0 1))

(lipsum2)