(archive 'newLISPer)

June 27, 2008

Simple help for newLISP

Filed under: newLISP — newlisper @ 17:33

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

> (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!


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at WordPress.com.

%d bloggers like this: