online help
online help
Does newlisp have online function's document in REPL like clojure's (doc map) or (find-doc "map")
Re: online help
Find out everything about newLISP's REPL here:
http://www.newlisp.org/downloads/newlis ... .html#REPL
http://www.newlisp.org/downloads/newlis ... .html#REPL
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Re: online help
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:
Reading the entire manual each time seems a bit daft, but it only takes a couple of milliseconds.
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))))
Re: online help
Thanks cormullion for your solution, great! and I add another macro base on your code:
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
>
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 " " 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))
> (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
>
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Re: online help
That's good. You may also want to add
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.
Code: Select all
(replace "→" html-text { ->})
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.
Re: online help
to jamesqiu's code I have added
before regexping, to be able to detect also such functions as zero? or null?
Code: Select all
(replace "?" func-name "p")
Re: online help
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:
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
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>
Ps: a fix for Windows here: http://www.newlisp.org/syntax.cgi?code/nls.txt