diff --git a/doc/Doc.html b/doc/Doc.html new file mode 100644 index 0000000..0e9c435 --- /dev/null +++ b/doc/Doc.html @@ -0,0 +1,1082 @@ +

Command line options

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
optionDescription
-hPrints help
-bSkips loading of std lib
-c codeRuns passed code
-f source_file ..Executes code in files
-run source_file ..Executes code in file, if first line of file is sheebang, it is skipped
-iRuns REPL
-dTurns on better stacktrace
-pPrints profile info at the end
-vPrints version string
+

REPL commands

+ + + + + + + + + + + + + + + + + + + + + +
CommandDescription
!q, !quitQuit REPL
!e, !envDisplay environment
!x, !exportExports command from this session. Asks for filename to save
+

Syntax and Special Forms

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Special FormArgument EvaluationsPurposeSection
(if cond a b)if only evaluates its cond argument. If cond is truthy, then a is evaluated. Otherwise, b is evaluated.This special form is the main method of control flow.Language
(cond (test1 action1 ..) (test2 action2 ..) ... (testn ..))The first clause whose test evaluates to non-nil is selected; all other clauses are ignored, and the consequents of the selected clause are evaluated in order. If none of the test conditions are evaluated to be true, then the cond statement returns nil.This special form is method of control flow.Language
(do a b c ...)do takes a list of s-expressions and evaluates them in the order they were given (in the current scope), and then returns the result of the last s-expression.This special form allows lambda functions to have multi-step bodies.Language
(scope a b c ...)scope takes a list of s-expressions and evaluates them in the order they were given in a new scope, and then returns the result of the last s-expression.This special form allows the user to evaluate blocks of code in new scopes.Language
(defn name params body)defn evaluates none of its arguments.This special form allows the user to conveniently define functions.Language
(defmacro name params body)defmacro evaluates none of its arguments.This special form allows the user to conveniently define macros.Language
(def name value)def evaluates the value argument, which is then assigned to name in the current scope.This special form allows the user to bind atoms to values in a scope.Language
(lambda params body)lambda evaluates none of its arguments.This special form allows the user to define anonymous functions.Language
(quote x)quote evaluates none of its arguments.This is equivalent to the 'expr syntactic sugar.Language
(for x list ...)for evaluates only its list argument.for iterates through the list storing each element in x, and then evaluating all of the rest of the values in the for body. It then returns the last value evaluated.Language
(while cond ...)while evaluates only its cond argument.while evaluates its condition expression every iteration before running. If it is true, it continues to evaluate every expression in the while body. It then returns the last value evaluated.Language
(and ...)and evaluates logical and on its list argument.and evaluates only until its true, it stops when becomes false.Language
(or ...)or evaluates logical or on its list argument.or evaluates while its false, it stops when becomes true.Language
(benchmark msg_string ...)benchmark takes a list of s-expressions and evaluates them in the order they were given (in the current scope), and then returns the result of the last s-expression and prints msg_string and timing info.Language
(set! x)set! .......Language
+

Macros

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SignatureDescriptionReturn valuesSection
(unles cond body)unless only evaluates its cond argument. If cond is not truthy, then body is evaluated.>>> (unless #t (print "it is #f")) => nilLanguage
(dotimes v n body)Iterates over v from 0 below n and evaluated body. Returns the last value of v>>> (dotimes i 5 i) => 4Language
(until cond body)Evaluated body as long as cond is not truthy>>> (def i 0)(until (> i 3) (set! i (inc i))) => 4Language
+

Library

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SignatureDescriptionReturn valuesSection
(= a b)Test whether two values are equal1 when equal otherwise nilLanguage
(!= a b)Test whether two values are not equal1 when not equal otherwise nilLanguage
(> a b)Test whether one value is greater to another1 when greater otherwise nilLanguage
(< a b)Test whether one value is less to another1 when less otherwise nilLanguage
(>= a b)Test whether one value is greater or equal to another1 when greater or equal otherwise nilLanguage
(<= a b)Test whether one value is less or equal to another1 when less or equal otherwise nilLanguage
(+ a b ..)Sum multiple valuessum of valuesLanguage
(- a b)Substract two valuesresult of substractionLanguage
(* a b ..)Multiply several valuesresult of multiplicationLanguage
(/ a b)Divide two valuesresult of divisionLanguage
(% a b)Remainder of divisionresult of operationLanguage
(list ..)Create a list of valuesList manipulation
(insert list index element)Insert an element into a list. Indexed from 0new list with value insertedList manipulation
(index list index)Return element at index in list. First element is at index 0Element at indexList manipulation
(remove list index)Remove a value at an index from a listList with element removedList manipulation
(len list)Get the length of a listlist lengthList manipulation
(push list element)Add an item to the end of a listnew list with element addedList manipulation
(pop list)Returns last element of listLast elementList manipulation
(head list)Returns first element of a list>>> (head '(1 2 3)) => 1List manipulation
(tail list)Return all elements of list except first one>>> (tail '(1 2 3)) => (2 3)List manipulation
(first list)Returns first element of a list>>> (first '(1 2 3)) => 1List manipulation
(last list)Returns last element of list>>> (last '(1 2 3)) => 2List manipulation
(range low high)Returns list with elements in range low .. high(range 1 5) => (1 2 3 4)List manipulation
(member lst item)Returns #t when item is inluded in lst otherwise nil>>> (member '(1 2 3) 1) => #tList manipulation
(uniq list)Filter out any duplicates from list>>> (uniq '(1 2 2 3 4 5 2 2)) => (1 2 3 4 5)List manipulation
(flatten list)Flattens a list to single level>>> (flatten '(1 (2 2) 3)) => (1 2 2 3)List manipulation
(take list count)Returns sublist with count element of list>>> (take '(1 2 3 4) 3) => (1 2 3)List manipulation
(make-list len)Return list with len nil elements(make-list 3) => (nil nil nil)List manipulation
(make-list-of size value)Makes list with size elements of values>>> (make-list-of 5 0) => (0 0 0 0 0)List manipulation
(concat-lists seq1 seq2)Appends all elements from seq2 to seq1>>> (concat-lists '(1 2 3) '(4 5 6)) => (1 2 3 4 5 6)List manipulation
(take lst size)Makes sublist of a lst with size length>>> (take '(1 2 3 4 5 6) 3) => (1 2 3)List manipulation
(find-val-in-list lst name)Returns tail od sublist which first element is name>>> (find-val-in-list '(("a" ("av" "avv")) ("b" "bv") (31 32 33) (41 42 43)) "b") => "bv" >>>List manipulation
(map ..)Returns list that is the result of executing lambda on its elements(map (lambda (x) (+ x 10)) '(1 2 3 4 5 6)) => (11 12 13 14 15 16)List manipulation
(filter lambda list)Returns list with elements for which passed lambda returns true(filter (lambda (x) (> x 2)) '(1 2 3 4 5)) => (3 4 5)List manipulation
(reduce lambda acumulator list)Reduces list>>> (reduce (lambda (acc e) (+ (* acc 10) e)) 0 '(1 2 3 4)) => 1234List manipulation
(exit code)Exit the program with an integer codeSystem
(quit code)Same as (exit ..)System
(print ..)Print one or several values separated by space and return the last one>>> (print "pi" "is" 3.14)\npi is 3.140000 => 3.140000IO
(random low high)Get a random number between two numbers inclusively>>> (random 1 6) => 5System
(include file)Read a file and execute its codeIO
(input [prompt])Get user input with an optional promptIO
(input2 [prompt])Get user input using libnoise with an optional promptIO
(read)Reads in the printed representation of a Lisp object from input-stream, builds a corresponding Lisp object, and returns the objectIO
(read-file filename)Get the contents of a file>>> (read-file "/tmp/a.txt") => "test"IO
(read-file-lines filename lambda)Reads file and for each line call lambda with passing the line as a parameter(read-file-lines "/tmp/f.txt" (lambda (ln) (print ln))IO
(write-file filename content-str)Write a string to a file>>> (write-file "/tmp/a.txt" "test") => #tIO
(read-url url [headers] [body] [method])Reads URL. Returns list (status-code content)IO
(system-cmd command_str)Execute system command>>> (system-cmd-fork "ml" "-c" "(print 123) (sleep 1) (print \"aaa\")") => (0 "") >>> 123\n aaaSystem
(system-cmd-fork cmd [par ..])Execute system command as an independent process>>> (system-cmd "date") => (0 "Fri Feb 25 12:35:28 CET 2022\n")System
(ls-dir dir)List a dirList of directory entries>>> (ls-dir "/tmp") => ("." ".." "vscode-ipc-cccbe1dd-8c71-4028-a863-df975ad5887b.sock" "vscode-ipc-1163bb52-d088-41dc-80a5-81b6a7c7fa36.sock" "vscode-ipc-630f21df-26b5-43d4-8b2e-5175d53ce317.sock")IO
(is-file? filename)Returns true if passed filename is a file>>> (is-file? "/tmp") => nilIO
(is-dir? filename)Returns true if passed filename is a directory>>> (is-dir? "/tmp") => #tIO
(mk-dir dirname)Creates directory wirh dirname. Does not create missing parent directories. Returns true if creation successfull>>> (mk-dir "/tmp/testdir") => #tIO
(rm-dir dirname)Removes directory wirh dirname. Does not create missing parent directories. Returns true if removal successfull>>> (rm-dir "/tmp/testdir") => #tIO
(tcp-server port handler)Starts listening on port and when request comes calls passed lambda and writes its returned value back to client. Lambda must return either string or two element list where first element is boolean and second string.When first element is true it closes listening socker.(tcp-server 7777 (lambda (str) (list #t (string-upcase str))))IO
(tcp-client address port data)Opens connection to server on port, writes there data and returns response.(print (tcp-client "127.0.0.1" 7777 "abcd"))IO
(parse-csv string)Parse CSV string>>> (parse-csv "A,B\n1,1\n2,2") => ((1 1) (2 2))String manipulation
(parse-json json_string)Parse JSON string>>> (parse-json "{\"k1\":\"v1\", \"k2\":42, \"k3\":[\"a\",123,true,false,null]}") => (("k1" "v1") ("k2" 42) ("k3" ("a" 123 #t nil nil)))String manipulation
(make-csv ..)Returns list as csv string>>> (make-csv '(("A" "B")(1 1)(2 2))) => "A,B\n1,1\n2,2"String manipulation
(get-universal-time)Get current time as number of seconds from epoch>>> (get-universal-time) => 1642152733Date and time
(get-universal-time-ms)Get current time as number of miliseconds from epoch>>> (get-universal-time-ms) => 1653575251097Date and time
(get-localtime-offset)Offset in seconds between local time and gmt time>>> (get-localtime-offset) => 3600Date and time
(date-to-str date format)Converts date to formated string. Format is strftime format (https://www.tutorialspoint.com/c_standard_library/c_function_strftime.htm)>>> (date-to-str (get-universal-time) "%Y-%m-%d %H:%M:%S") => "2021-03-13 19:53:01"Date and time
(str-to-date string format)Converst string to time of secs since epoch.>>> (str-to-date "2021-03-13 19:53:01" "%Y-%m-%d %H:%M:%S") => 1615665181Date and time
(date-add date amount unit)Add number of units to date. A unit is one of 'year', 'month', 'day', 'hour', 'minute' or 'second'>>> (date-to-str (date-add (str-to-date "2021-03-13 19:53:01" "%Y-%m-%d %H:%M:%S") 10 "day") "%Y-%m-%d %H:%M:%S") => "2021-03-23 20:53:01"Date and time
(start-of-day datetime)Returns epoch time of start of a day>>> (start-of-day (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1620864000Date and time
(end-of-day datetime)Returns epoch time of end of day>>> (end-of-day (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1620950399Date and time
(start-of-month datetime)Returns epoch time of start of month>>> (start-of-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1619827200Date and time
(start-of-next-month datetime)Returns epoch time of start of following month>>> (start-of-next-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1622505599Date and time
(end-of-next-month datetime)Returns epoch time of end of following month>>> (end-of-next-month datetime (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1622505600Date and time
(end-of-month datetime)Returns epoch time of end of month>>> (end-of-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1625097599Date and time
(start-of-prev-month datetime)Returns epoch time of start of previous month>>> (start-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1617235200Date and time
(end-of-prev-month datetime)Returns epoch time of end of previous month>>> (end-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1619827199Date and time
(start-of-year datetime)Returns epoch time of start of year>>> (start-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1609459200Date and time
(end-of-year datetime)Returns epoch time of end of year>>> (end-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1640995199Date and time
(decode-universal-time datetime)Returns the decoded time represented by the given universal time. Returns list with (second, minute, hour, day, month, year, day-of-the-week)>>> (decode-universal-time 0) => (0 0 0 1 1 1970 4)Date and time
(debug ..)Returns string representation of passed params>>> (debug '(1 2 3)) => "(1 2 3)"IO
(display ..)Displays passed parameters>>> (display '(1 2 3)) => "(1 2 3)"IO
(string-replace source substr replacement)Replace a substring with a replacement string in a source string>>> (string-replace "abcdefg" "de" "DE") => "abcDEfg"String manipulation
(string-replace-re source substr replacement)Replace a substring regex with a replacement string in a source string>>> (string-replace-re "there is a subsequence in the string" "\\b(sub)([^ ]*)" "sub-$2") => "there is a sub-sequence in the string"String manipulation
(string-regex? where regex)Returns true if where contains regex, else nil>>> (string-regex? "aba123cdefg" "[0-9]+") => #tRegex
(string-regex-list where regex [mode] [ignorecase])Returns list of substring from where captured by regex in mode match or tokens>>> (string-regex-list "<td class=\"xyz\">1</td><td>2</td>" "<td.*?>(.*?)</td>" "match" "ignore") => (("<td class=\"xyz\">1</td>" "<td>2</td>")) >>> (string-regex-list "<td class=\"xyz\">1</td><td>2</td>" "<td.*?>(.*?)</td>" "token") => (("1") ("2"))Regex
(string-pad str len char rpad_lpad)Pad string from start or to end with char to lengthString manipulation
(string-lpad str len char)Pad string from start with char to length len>>> (string-lpad "0" 10 "x") => "xxxxxxxxx0"String manipulation
(string-rpad str len char)Pad string from righ with char to length len>>> (string-rpad "0" 10 "x") => "0xxxxxxxxx"String manipulation
(string-split str separator)Splits string into list by regexp>>> (string-split "split me by space" "\s+") => ("split" "me" "by" "space")String manipulation
(string-rltrim str len RKRRKR)Removes " \n\r\t" from the begininfg or end or both ends of strRegex
(string-ltrim str)Removes " \n\r\t" from the begininfg of str>>> (string-ltrim " *** ") => "*** "String manipulation
(string-rtrim str)Removes " \n\r\t" from the end of str>>> (string-rtrim " *** ") => " ***"String manipulation
(string-trim str)Removes " \n\r\t" from the both strart and end of str>>> (string-trim " *** ") => "***"String manipulation
(string-case str UPLO)Returns up or down cased string based on second parameter (upper/lower)>>> (string-case "abc" "upper") => "ABC"String manipulation
(string-upcase str)Returns up cased string>>> (string-upcase "abcdefghchijklmn") => "ABCDEFGHCHIJKLMN"String manipulation
(string-downcase str)Returns down cased string>>> (string-downcase "ABCDefghchijklmn") => "abcdefghchijklmn"String manipulation
(string-join lst sep)Returns string created as elements of concatenation of lst elements separated by sep>>> (string-join ("A" "B" "C" "D") ",") => "A,B,C,D"String manipulation
(string-len str)Returns string length>>> (string-len "abcdef") => 6String manipulation
(string-substr str pos len)Returns substring from str starting at pos with len. If pos is negative returns substring from the end of string. First character is on pos 0>>> (string-substr "ABCD" -2 2) => "CD"String manipulation
(string-find str lookup pos)Returns position of lookup in str starting on position. First char index is 0. If not found returns nil>>> (string-find " long long int;" "long" 2) => 6String manipulation
(string-cmp str1 str2)Compares two strings. Returns 0 where strangs are equal; < 0 when the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter.; >0 when the value of the first character that does not match is greater in the compared string, or all compared characters match but the compared string is longer.>>> (string-cmp "aaa" "xaa") => -23String manipulation
(string-cmp-ic str1 str2)Compares two strings ignoring case. Returns 0, < 0, > 0.>>> (string-cmp-ic "aaa" "AaA") => 0String manipulation
(int value)Cast an item to an int>>> (int 3.41) => 3Type casting
(float value)Cast item to a float>>> (int 3.41) => 3.14Type casting
(string value)Cast int or float item to a string>>> (string 3.14) => "3.14"Type casting
(eval <exp>)Eval returns the value of the second evaluation>>> (eval '(+ 1 2)) => 3Language
(type e)Returns data type of e>>> (type (+ 1 2)) => "int"Type casting
(list? e)Returns true if type of e is list>>> (list? 12) => nil >>> (list? '(1 2)) => #tType casting
(empty-list? e)Returns true if type of e is empty list>>> (empty-list? '(1 2)) => nil >>> (empty-list? '()) => #tType casting
(string? e)Returns true if type of e is string>>> (string? "str") => #tType casting
(int? e)Returns true if type of e is integer>>> (int? "str") => nil >>> (int? 9) => #tType casting
(float? e)Returns true if type of e is float>>> (float? 9) => nil >>> (float? 9.0) => #tType casting
(nil? e)Returns true if type of e is nil>>> (nil? 9.0) => nil >>> (nil? nil) => #t >>> (nil? '()) => nilType casting
(true? e)Returns true if type of e is #t>>> (true? 1) => nil >>> (true? #t) => #tType casting
(parse ..)Parses string to be evaluated>>> (eval (first (parse "(+ 1 2)"))) => 3Language
(quick-sort-by list cmp)Returns list sorted by comparsion functionLanguage
(quick-sort list)Return sorted list>>> (quick-sort '(2 4 6 1 7 3 3 9 5)) => (1 2 3 3 4 5 6 7 9)Language
(quick-sort-reverse list)Return reverse sorted list>>> (quick-sort-reverse '(2 4 6 1 7 3 3 9 5)) => (9 7 6 5 4 3 3 2 1)Language
(not c)Logical NOT of c>>> (not 1) => nilLanguage
(neg n)Negates number>>> (neg -5) => 5Language
(is-pos? n)Returns true if n is positive number>>> (is-pos? -1) => nilLanguage
(is-neg? n)Returns true if n is negative number>>> (is-neg? -1) => #tLanguage
(dec n)Return n decremented by 1>>> (dec 5) => 4Language
(inc n)Return n incremented by 1>>> (inc 5) => 6Language
(sleep time)Pauses execution for time interval of seconds. Calls system sleep command>>> (sleep 1) => (0 "")System
(function? e)Returns true if type of e is lambda, macro or builtin>>> (function? index) => #tLanguage
(unless test v)If test is not truthy then v is evaluated. This is macro.>>> (unless (> 1 2) "1 < 2") => "1 < 2"Language
(dotimes v n body)Evaluates body n-times. For each eveluation v is set to value between 0 and n minus one(dotimes i 10 (print "i :" i))Language
(doc::man "func_name")Prints short help for func_nameLanguage
(doc::appropos "string")Looks for functions to be related passed string. String can be more words separated by spaceLanguage
(doc::look "string")Alias for approposLanguage
(doc::lookup "string")Alias for approposLanguage
(get-env var)Return environment variable var>>> (get-env "HOME") => "/Users/vaclavt"System
(set-env var value)Sets environment variable var to value>>> (set-env "XXYYZZ" "haha") => "haha"System
(second list)Returns second element of list>>> (second '(1 2 3 4 5 6 7)) => 2List manipulation
(third list)Returns third element of list>>> (third '(1 2 3 4 5 6 7)) => 3List manipulation
(fourth list)Returns fourth element of list>>> (fourth '(1 2 3 4 5 6 7)) => 4List manipulation
(fifth list)Returns fifth element of list>>> (fifth '(1 2 3 4 5 6 7)) => 5List manipulation
(nth i list)Return i-th elemenet of list. First element has index 1>>> (nth 7 '(1 2 3 4 5 6 7)) => 7List manipulation
(make-csv list)creates csv string from list of lists(print (make-csv '(("r1c1" "r1c2") ("r2c1" "r2c2"))))List manipulation
(sprintf ..)Writes string pointed by format to the standard output>>> (sprintf "%s, %d, %.2f" (list "string" 1000 3.14)) => "string, 1000, 3.14"String manipulation
(thread-create code..)Creates new thread, starts evalueating code and returns immediatelly thread idThreading
(thread-under-lock lockname code)Acquire lock with lockname and eval code. "ilock" currently is only allowed locknameThreading
(thread-sleep milisecons)Sleeps thread for given amount of miliseconds>>> (thread-sleep 100) => 100Threading
(threads-join)Wait for all running threads to finishThreading
(try block catch_block [finally_block])Evaluates block and if an exception is thrown, evaluates catch_block.Eventually in both cases evals finally_block. Return evaluated last expression from block if no exception or last expression from catch_block, if exception is thrown from block. Variable ml-exception in catch block is available with astring describing exceptionExceptions
(throw exp_desc)Throws an exception with exp_desc describing what happened. exp_desc will be evaluated a returned as string>>> (throw (+ 1 2))\n3Exceptions
diff --git a/doc/readme.txt b/doc/readme.txt new file mode 100644 index 0000000..c727126 --- /dev/null +++ b/doc/readme.txt @@ -0,0 +1,22 @@ +to convert Doc.md to Doc.html use https://markdowntohtml.com/ with custom ccs style + +body { + color: black; +} +table { + border-collapse: collapse; +} +table, th, td { + border: 1px solid; +} +th { + text-align: left; +} +td { + height: 50px; + vertical-align: top; +} +code{ + background: #0003; + color: #a31515; +} \ No newline at end of file diff --git a/stdlib/doc.lsp b/stdlib/doc.lsp index d4feed5..309b381 100644 --- a/stdlib/doc.lsp +++ b/stdlib/doc.lsp @@ -43,6 +43,12 @@ nil )) +(defn doc::print-entry (entry) +(do (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)) +)) + (defn doc::man (what) (do (def man (filter (lambda (x) (= (first x) what)) doc::doc_entries)) (if man @@ -75,29 +81,54 @@ (def sorted (quick-sort-by scores (lambda (a b) (< (first a) (first b))))) (for e (take sorted 10) - (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)) - ) + (doc::print-entry (second e)))) + (if (> (len sorted) 10) (print "...")) )) +(defn doc::section (what) +(do + (def entries '()) + (for entry doc::doc_entries + ; ("throw-exception" "`(throw-exception exp_desc)`" "Throws an exception with exp_desc describing what happened " "" "Exceptions" + ; section matches + (if (= (string-downcase (fifth entry)) (string-downcase what)) + (set! entries (push entries entry))) + ) + + (for e (quick-sort-by entries (lambda (a b) (> (string-cmp (first a) (first b)) 0))) + (doc::print-entry e)) +)) + +(defn doc::all () + (for e (quick-sort-by doc::doc_entries (lambda (a b) (> (string-cmp (first a) (first b)) 0))) + (doc::print-entry e)) +) + (defn doc::appropos (which) (doc::look which)) (defn doc::lookup (which) (doc::look which)) -;(defn doc::section (which) -; (print (term-red "implement me!"))) +(defn doc::doc () +(do + (print "Usage:") + (print "\t(doc::doc) - shows this help") + (print "\t(doc::man func) - func must be a string, ie (doc::man \"for\")") + (print "\t(doc::look str) - str must be a string, ie (doc::look \"length\")") + (print "\t(doc::lookup) - alias for doc::look") + (print "\t(doc::appropos) - alias for doc::look") + (print "\t(doc::all) - show short info about all functions") + (print "\t(doc::section sec) - show help for section, sec is string one of:") + (print "\t\t\t\t\"List manipulation\" \"Language\" \"System\"") + (print "\t\t\t\t\"String manipulation\" \"Date and time\" \"IO\" \"Regex\"") + (print "\t\t\t\t\"Type casting\" \"Threading\" \"Exceptions\"") +)) + (def doc::doc_entries '()) ; must be here ; read doc into memory (doc::read-doc-file "/usr/local/var/mlisp/Doc.md") -;;example -; (doc::man "first") -; (doc::look "string pad") -; (doc::look "list flat")