online help

Started by jamesqiu, October 13, 2011, 01:06:42 AM

Previous topic - Next topic

jamesqiu

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

Lutz

#1
Find out everything about newLISP's REPL here:



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

cormullion

#2
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. (http://newlisper.wordpress.com/2009/01/02/bits-and-pieces-2/">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:


(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

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


(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 "nn+" html-text "nn" 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

#4
That's good. You may also want to add


(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

#5
to jamesqiu's code I have added

(replace "?" func-name "p")

before regexping, to be able to detect also such functions as zero? or null?

Lutz

#6
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:


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">http://www.newlisp.org/syntax.cgi?code/nls.txt