You should be automatically redirected . If not, visit
http://newlisper.wordpress.com
and update your bookmarks.

27/06/2008

Simple help for newLISP

An interesting discussion about an online help facility for newLISP threw up lots of interesting ideas and useful suggestions. One advantage to not having certain facilities built in is that it gives you scope for making them yourself. This version I threw together is simple enough:

(define (help func-name)
   (if (find func-name "|+*-") (push "\\" func-name))
   (set 'html-text (join (find-all (format {(syntax: \(%s.*?)} func-name) 
      (read-file "/usr/share/doc/newlisp/newlisp_manual.html")) "\n"))
  (println (replace "<.*?>" html-text "" 0))
  (silent))

> (help "date")
syntax: (date)
syntax: (date int-secs [int-offset])
syntax: (date int-secs int-offset str-format)
syntax: (date-value int-year int-month int-day [int-hour int-min int-sec])

The first line of the function was a temporary fix for a puzzling bug, and it also offered a nice surprise. The bug was that it was impossible to get help on functions with names like | or + without listing way too much. I eventually realized (duh) that some newLISP symbols were also significant in regular expressions and needed to be escaped. Because no symbols use the period (.), I hadn't bothered to escape it. But it then becomes a useful option for searching for functions:

> (help "fi.")
syntax: (file-info str_name [int-index])
syntax: (file? str-name)
syntax: (filter exp-predicate exp-list)
syntax: (find exp-key list [func-compare | int-option])
syntax: (find str-key str-data [int-option])
syntax: (find-all str-pattern str-text [expr [int-option]])
syntax: (find-all list-pattern list-lists [expr])
syntax: (find-all expr-key list expr func-compare)
syntax: (first list)
syntax: (first array)
syntax: (first str)

The only thing left to do now is to work out how to avoid using silent. Although I want to suppress the value returned by println, I don't want the prompt to disappear as well. Unfortunately, silent does both. I bet there's a way, though!

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home