define renamed to def, defun renamed to defn

This commit is contained in:
vaclavt
2022-01-25 19:50:59 +01:00
parent 62015c2ff8
commit e6f61c9d9f
14 changed files with 189 additions and 189 deletions

View File

@@ -1,17 +1,17 @@
(include "/usr/local/var/mlisp/terminal.lsp")
(defun doc::strip-backticks (s)
(defn doc::strip-backticks (s)
(if (and (> (string-len s) 2)
(= (string-substr s 0 1) "`")
(= (string-substr s -1 1) "`"))
(string-substr s 1 (- (string-len s) 2))
s))
(defun doc::read-doc-file (filename)
(do (define parse-line (lambda (ln)
(defn doc::read-doc-file (filename)
(do (def parse-line (lambda (ln)
(if (string-regex? ln "^|.*|")
(do (define tokens (tail (string-split (string-rltrim ln " \n\r\t" "trim") "\|"))) ; first element is ""
(do (def tokens (tail (string-split (string-rltrim ln " \n\r\t" "trim") "\|"))) ; first element is ""
(if (= (len tokens) 4)
(insert tokens 0 (string-replace-re (first (string-split (first tokens) "\s+|\)")) "`|\(" ""))
nil)
@@ -19,19 +19,19 @@
nil)
))
(define lines (string-split (read-file filename) "\n") )
(define lines (map (lambda (ln) (parse-line ln)) lines))
(define lines (filter (lambda (e) (!= e nil)) lines))
(def lines (string-split (read-file filename) "\n") )
(def lines (map (lambda (ln) (parse-line ln)) lines))
(def lines (filter (lambda (e) (!= e nil)) lines))
(set! doc::doc_entries lines)
'loaded
))
(defun doc::print (entry)
(defn doc::print (entry)
(do (print (term-green (doc::strip-backticks (second entry))) "-" (third entry))
; (print (last entry) "\n") ; doc section
(if (> (string-len (fourth entry)) 2)
(do (define examp (doc::strip-backticks (fourth entry)))
(define pos (string-find examp "=>" 0))
(do (def examp (doc::strip-backticks (fourth entry)))
(def pos (string-find examp "=>" 0))
(if (and pos (> pos 0))
(print (term-magenta
(+ (string-substr examp 0 (- pos 1))
@@ -43,21 +43,21 @@
nil
))
(defun doc::man (what)
(do (define man (filter (lambda (x) (= (first x) what)) doc::doc_entries))
(defn doc::man (what)
(do (def man (filter (lambda (x) (= (first x) what)) doc::doc_entries))
(if man
(doc::print (first man))
(print (term-red (+ "No entry for " what)))
)
))
(defun doc::look (what)
(do (define what_list (string-split (string-downcase what) "\s+"))
(define scores '()) ; ((score entry)..)
(defn doc::look (what)
(do (def what_list (string-split (string-downcase what) "\s+"))
(def scores '()) ; ((score entry)..)
(for entry doc::doc_entries
; ("throw-exception" "`(throw-exception exp_desc)`" "Throws an exception with exp_desc describing what happened " "" "Exceptions"
(define entry_score 0)
(def entry_score 0)
(for kw what_list
; name matches
(if (= (string-downcase (first entry)) kw)
@@ -73,23 +73,23 @@
(set! scores (push scores (list entry_score entry))))
)
(define sorted (quick-sort-by scores (lambda (a b) (< (first a) (first b)))))
(def sorted (quick-sort-by scores (lambda (a b) (< (first a) (first b)))))
(for e (take sorted 10)
(define entry (second e))
(define call (doc::strip-backticks (second entry)))
(define desc (doc::strip-backticks (third entry)))
(def entry (second e))
(def call (doc::strip-backticks (second entry)))
(def desc (doc::strip-backticks (third entry)))
(print (term-red (first entry)) "-" (term-green (doc::strip-backticks (second entry))) "-" (third entry))
)
(if (> (len sorted) 10) (print "..."))
))
(defun doc::appropos (which)
(defn doc::appropos (which)
(doc::look which))
;(defun doc::section (which)
;(defn doc::section (which)
; (print (term-red "implement me!")))
(define doc::doc_entries '()) ; must be here
(def doc::doc_entries '()) ; must be here
; read doc into memory
(doc::read-doc-file "/usr/local/var/mlisp/Doc.md")