online help

Pondering the philosophy behind the language
Locked
jamesqiu
Posts: 9
Joined: Thu Oct 13, 2011 7:53 am

online help

Post by jamesqiu »

Does newlisp have online function's document in REPL like clojure's (doc map) or (find-doc "map")

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: online help

Post by Lutz »

Find out everything about newLISP's REPL here:

http://www.newlisp.org/downloads/newlis ... .html#REPL

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: online help

Post by cormullion »

If you're looking for a way to search the manual for information about a function, I think people usually write something themselves, to suit their editing style. Since I use BBEdit, I've got all the function syntax organized into snippets. (pictured here) There has also been a TextMate solution using the HTML popup window. Sublime Text clippings are easy too.

If you don't mind a quick regex hack, this is quite useful to put in your init.lsp file:

Code: Select all

(define-macro (?? func-name)
  (let ((func-name (string func-name)))
      (set 'f (read-file {/usr/share/doc/newlisp/newlisp_manual.html}))
      (when (and 
                (starts-with func-name "[a-z]" 0)
                (set 'html-text (find-all (string "<h4>syntax(.*?)" func-name "(.*?)</h4>") f)))
          (set 'html-text (join html-text "\n"))
          (replace "<.*?>" html-text "" 0)
          (replace "<"  html-text "<")
          (replace ">"  html-text ">")
          (replace "&" html-text "&"))
      (silent (println html-text))))
Reading the entire manual each time seems a bit daft, but it only takes a couple of milliseconds.

jamesqiu
Posts: 9
Joined: Thu Oct 13, 2011 7:53 am

Re: online help

Post by jamesqiu »

Thanks cormullion for your solution, great! and I add another macro base on your code:

Code: Select all

(define-macro (doc func-name)
  (let ((func-name (string func-name)))
      (set 'f (read-file {/e:/newlisp/newlisp_manual.html}))
	  (set 'r (regex (string "<a name=\"" func-name "\"></a>") f))
	  (set 'n0 (r 1))
	  (set 'n1 ((regex "<a name=" f 0 (+ n0 (r 2))) 1))
	  (set 'html-text (slice f n0 (- n1 n0)))
	  (replace "<.*?>" html-text "" 0)
	  (replace "<"  html-text "<")
	  (replace ">"  html-text ">")
	  (replace "&" html-text "&")
	  (replace "&nbsp;" html-text " ")
	  (replace "&mdash" html-text "...")
	  (replace "\n\n+" html-text "\n\n" 1)
	  (replace "^\n+|\n+$" html-text "" 1)
      (println "--------------------------")
	  (println html-text)
	  (println "--------------------------") 
	  'end))
Can use as below:

> (doc println)
--------------------------
println
syntax: (println exp-1 [exp-2 ... ])

Evaluates and prints exp-1...;
to the current I/O device,
which defaults to the console window.
A line-feed is printed at the end.
See the built-in function device for details on how to specify a different I/O device.
println works exactly like print but emits a line-feed character at the end.

See also the write-line and print functions.
--------------------------
end
>

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: online help

Post by cormullion »

That's good. You may also want to add

Code: Select all

 (replace "&rarr;" html-text { ->})
since it occurs everywhere in the manual. :)

If you wanted to get every single function, you'd have to make allowances for the punctuation mark functions (!, $, and so on.) Or stick an null? check after the regex.

denis
Posts: 20
Joined: Wed Apr 27, 2011 12:19 pm
Location: Petsamo, Murmansk, RU

Re: online help

Post by denis »

to jamesqiu's code I have added

Code: Select all

(replace "?" func-name "p")
before regexping, to be able to detect also such functions as zero? or null?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: online help

Post by Lutz »

There is also newlisp-10.4.0/util/nls, a script which merges the Bash shell with the newLISP REPL. You enter a shell command or a newLISP expression starting with a parenthesis '(' or a space for symbols. It works well on OSX and other Unix but is not working right on Windows. It has a short help, only showing syntax:

Code: Select all

MAIN:/Users/lutz> help append
syntax: (append list-1 [list-2 ... ])
syntax: (append array-1 [array-2 ... ])
syntax: (append str-1 [str-2 ... ])
syntax: (append-file str-filename str-buffer)
MAIN:/Users/lutz> help fil
syntax: (file-info str-name [int-index [bool-flag]])
syntax: (file? str-path-name [bool])
syntax: (filter exp-predicate exp-list)
MAIN:/Users/lutz> (set 'x 123)
123
MAIN:/Users/lutz>  x
123
MAIN:/Users/lutz> ls *.lsp
plot.lsp	spawn.lsp
MAIN:/Users/lutz> 
If you enter 'help' on its own, you get a list of all syntax patterns. This script is also a nice example on how to use 'prompt-event' and 'command-event'.

Ps: a fix for Windows here: http://www.newlisp.org/syntax.cgi?code/nls.txt

Locked