1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
|
(import introspection)
(define standard-env (get-current-env))
(define (text children ...) (hash "tag" "text" "children" children))
(class code [val string?])
(class codeblock [val string?])
(class link [val symbol?])
(class proc [name string?] [sig any] [summary hash?])
(class syntax [name string?] [body string?] [summary hash?])
(class value [name string?] [sig any] [summary hash?])
(define/c (pred [name string?] [summary hash?] -> proc?)
(proc name '((v any) bool?) summary)
)
; -----------
; Doc builder
(define/c (san [v (or/c symbol? string?)] -> string?)
(when v.symbol?
(set! v v.symbol->string)
)
(replace (replace (replace v "&" "&") "<" "<") ">" ">")
)
(define/c (text->string [text hash?] -> string?)
(define s "")
(for ([c (text "children")]) (cond
[(equal? c #t) (&= s "<span class=\"palet-val\">#t</span>")]
[(equal? c #f) (&= s "<span class=\"palet-val\">#f</span>")]
[(void? c) (&= s "<span class=\"palet-val\">#<void></span>")]
[(symbol? c) (&= s (& "<span class=\"palet-var\">" (san c) "</span>"))]
[(string? c) (&= s (replace (san c) "\n" "<br/>"))]
[(link? c) (&= s (& "<a href=\"#" (symbol->string c.val) "\">" (san c.val) "</a>"))]
[(code? c) (&= s (& "<code>" (san c.val) "</code>"))]
[(codeblock? c) (&= s (& "<pre><code>" (san c.val) "</code></pre>"))]
[else (error "Unknown text value in text->string")]
))
s
)
(define/c (build-sig [mylist list?] -> string?)
(define results #())
(for ([v mylist])
(add! results (cond
[(equal? v '...) "..."]
[(equal? v.len 3) (& "<span class=\"palet-var\">[" (san (v 0)) "]</span>")]
[else (& "<span class=\"palet-var\">" (san (v 0)) "</span>")]
))
)
(join results " ")
)
(define/c (build-var [c any] -> string?)
(cond
[(equal? c #t) "<span class=\"palet-val\">#t</span>"]
[(equal? c #f) "<span class=\"palet-val\">#f</span>"]
[(void? c) "<span class=\"palet-val\">#<void></span>"]
[(and c.list? (= c.len 1) (equal? (c 0) 'void)) "<span class=\"palet-val\">#<void></span>"]
[(and c.symbol? c.var-exists?) (& "<a href=\"#" c.symbol->string "\">" (san c) "</a>")]
[(or c.string? c.symbol?) (san c)]
[(list? c) (begin
(define results #())
(for ([inner c])
(add! results (build-var inner))
)
(& "(" (join results " ") ")")
)]
[else (~v c)]
)
)
(define/c (build-var-sig [sigs list?])
(define result "")
(for ([s sigs])
(when (and s.symbol? (not (equal? s '...)))
(error "string besides ... was found")
)
(when (not (equal? s '...))
(define name (s 0))
(define sig (s 1))
(&= result (& "<p class=\"mono\"> <span class=\"palet-var\">" name.san
"</span> : " sig.build-var
(if (> s.len 2) (& " = " (build-var (s 2))) "") "</p>\n"
))
)
)
result
)
(define/c (doc-builder [file output-port?] [doc hash?] [check-env (or/c hash? #f)] -> void?)
(define special-forms 0)
(define palet-procs 0)
(define palet-vars #[])
(for-items [category somethings doc]
(displayln (& "<h2 class=\"left\">" category "</h2>") file)
(for ([some somethings])
(if (and some.hash? (equal? (some "tag") "text"))
(displayln (& "<p>" some.text->string "</p>") file)
(add! palet-vars (if some.hash? (some "name") some.name))
)
(when some.value?
(displayln (&
"<div class=\"palet-block\">\n<p class=\"mono\">" (san some.name)
"\n : <a href=\"#" some.sig "\">" some.sig
"</a> Value</p>\n</div>\n<p>" (text->string some.summary) "</p>"
) file)
)
(when some.syntax?
special-forms.incf
(displayln (&
"<div id=\"" (san some.name) "\" class=\"palet-block\">\n<p class=\"mono\">(<b>"
some.name "</b> " some.body ") Syntax</p>\n</div>\n<p>"
(text->string some.summary) "</p>"
) file)
)
(when some.proc?
palet-procs.incf
(define rname (some.sig -1)) ; result name
(define varsigs (some.sig 0 -1))
(displayln (&
"<div id=\"" (san some.name)
"\" class=\"palet-block\">\n<p class=\"mono\">(<b>" (san some.name) "</b> "
(build-sig varsigs) ") → " (build-var rname) " Procedure</p>\n"
(build-var-sig varsigs) "</div>\n<p>" (text->string some.summary) "</p>"
) file)
)
)
)
(display "</div>\n</section>\n</body>\n</html>\n\n" file)
file.close-port
(when check-env.hash?
(for-items [key item check-env]
(when (not (member key #("none" "all/e" "audio" "audio-levels" "motion" "motion-levels" "subtitle" "get-current-env" "proc-name")))
(when (not (member key palet-vars))
(error (& "`" key "` not in docs."))
)
)
)
)
(displayln (~s "built" palet-procs "variables\nbuilt" special-forms "special forms"))
)
; -----
(define edit-docs {hash
"Edit Methods" #[
(proc "audio" '((threshold threshold? 0.04) (stream (or/c nat? "'all") "'all") (mincut int? 6) (minclip int? 3) bool-array?)
(text "Auto-Editor's default. Provides a high level abstraction over "(link 'audio-levels)".")
)
(proc "motion" '((threshold threshold? 0.02) (stream nat? 0) (blur nat? 9) (width nat1? 400) bool-array?)
(text "Motion analysis. Provides a high level abstraction over "(link 'motion-levels)".")
)
(proc "subtitle" '((pattern string?) (stream nat? 0) (ignore-case bool? #f) (max-count (or/c nat? void?) (void)) bool-array?)
(text "When "'pattern", a RegEx Expression, matches a subtitle line, consider that time the line occupies as loud.")
)
]
"Level Procedures" #[
(proc "audio-levels" '((stream nat?) array?)
(text "Analysis audio volume based on samples. Using a 2-pass method where all the values are adjusted based on the highest sample value. Returns an array of float64s.")
)
(proc "motion-levels" '((stream nat?) (blur nat? 9) (width nat1? 400) array?)
(text "Scale the video to "'width" pixels, convert to grayscale, apply a Gaussian blur of "'blur" amount, then compare the difference with the previous frame. Returns an array of float64s.")
)
]
})
(define core-docs {hash
"Assignment" #[
(syntax "define" "id expr" (text "Set "'id" to the result of "'expr"."))
(syntax "set!" "id expr"
(text
"Set "'id" to the result of "'expr" if "'id
" is already defined. If "'id" is not defined, raise an error."
)
)
(syntax
"lambda" "args body"
(text
"Produces a procedure that accepts "'args" arguments and runs "
'body" when called."
)
)
(syntax "λ" "args body" (text "Clone of " (link 'lambda) "."))
(syntax
"define/c" "(proc-bind [id-binding contract]... )"
(text "Define a procedure with contracts.")
)
(syntax "let" "([id val-expr] ...) body)"
(text "Evaluates the "'val-expr"s left-to-right, creating a new location for each "
'id", and places the values into the locations. It then evaluates the "'body
"s, in which the "'id"s are bound.")
)
(syntax "let*" "([id val-expr] ...) body)"
(text "Like " (link 'let) ", but evaluates the "'val-expr
"s one by one, creating a location for each "'id
" as soon as the value is available. The "'id"s are bound in the remaining "
'val-expr"s as well as in the "'body"."
)
)
]
"Control Flow" #[
(syntax "if" "test-expr then-expr else-expr"
(text
"Evaluates "'test-expr". If "#t" then evaluate "'then-expr" else evaluate "
'else-expr". An error will be raised if evaluated "'test-expr" is not a "
(link 'bool?)"."
)
)
(syntax "when" "test-expr body"
(text
"Evaluates "'test-expr". If "#t" then evaluate "'body
" else do nothing. An error will be raised if evaluated "'test-expr
" is not a "(link 'bool?)"."
)
)
(syntax "cond" "[test-clause then-body]... [else then-body]"
(text
"Evaluate each "'cond-clause" if the clause is evaluated to "#t
" then evaluate and return "'then-body". If the clause is "#f
" continue to the next clause. If there are no clauses left return "
(void)". If the last "'test-clause" is "'else" then its evaluated "
'then-body"."
)
)
(syntax "case" "val-expr case-clause ..."
(text
"Evaluates "'val-expr" and uses the result to choose a "'case-clause
". The selected clause is the first datum whose "'quote" form is "
(link 'equal?)" to the result of "'val-expr". If no "'case-clause
" is choosen, then "(void)" is returned, unless there is an else"
" clause, in that case return its body.\n\n"
"A "'case-clause " that starts with else must be the last "'case-clause"."
)
)
(syntax "for" "([id seq-expr] ...) body"
(text
"Loop over "'seq-expr" by setting the variable "'id" to the nth item of "
'seq-expr" and evaluating "'body"."
)
)
(syntax "for-items" "[key value hash-id] body"
(text "Loop over key-value pairs of "'hash-id", which should be a hash?.")
)
(syntax "while" "condition body"
(text "Loop over body while "'condition" evalutes to "#t".")
)
]
"Equality" #[
(proc "equal?" '((v1 any) (v2 any) bool?)
(text
"Returns "#t" if "'v1" and "'v2" are the same type and have the same value, "
#f" otherwise."
)
)
(proc "eq?" '((v1 any) (v2 any) bool?)
(text
"Returns "#t" if "'v1" and "'v2" refer to the same object in memory, "
#f" otherwise."
)
)
]
"Booleans" #[
(pred "bool?" (text "Returns "#t" if "'v" is "#t" or "#f", "#f" otherwise."))
(value "true" "bool?" (text "An alias for "#t"."))
(value "false" "bool?" (text "An alias for "#f"."))
]
"Number Predicates" #[
(pred "number?" (text "Returns "#t" if "'v" is a number, "#f" otherwise."))
(pred "real?" (text "Returns "#t" if "'v" is a real number, "#f" otherwise."))
(pred "int?" (text "Returns "#t" if "'v" is an integer, "#f" otherwise."))
(pred "float?" (text "Returns "#t" if "'v" is a float, "#f" otherwise."))
(pred "frac?"
(text "Returns "#t" if "'v" is a fraction (a rational number), "#f" otherwise.")
)
(pred "complex?" (text "Returns "#t" if "'v" is an complex number, "#f" otherwise."))
(pred "nat?"
(text "Returns "#t" if "'v" is an integer and "'v" is >= 0, "#f" otherwise.")
)
(pred "nat1?"
(text "Returns "#t" if "'v" is an integer and "'v" is >= 1, "#f" otherwise.")
)
(pred "threshold?"
(text "Returns "#t" if "'v" is a float and "'v" is >= 0 and <= 1, "#f" otherwise.")
)
(proc "zero?" '((z number?) bool?) (text "Returns " (code "(= z 0)")))
(proc "positive?" '((x real?) bool?) (text "Returns " (code "(> x 0)")))
(proc "negative?" '((x real?) bool?) (text "Returns " (code "(< x 0)")))
(proc "even?" '((n int?) bool?) (text "Returns " (code "(zero? (mod n 2))")))
(proc "odd?" '((n int?) bool?) (text "Returns " (code "(not (even? n))")))
]
"Numbers" #[
(proc "+" '((z number?) ... number?)
(text
"Return the sum of "'z"s. Add from left to right. "
"If no arguments are provided the result is 0."
)
)
(proc "-" '((z number?) (w number?) ... number?)
(text
"When no "'w"s are applied return "(code "(- 0 z)")
", otherwise return the subtraction of "'w"s of "'z"."
)
)
(proc "*" '((z number?) ... number?)
(text "Return the product of "'z"s. If no "'z"s are supplied the result is 1.")
)
(proc "/" '((z number?) (w number?) ... number?)
(text
"Returns the division of "'z" by the "'w"s. If no "'w"s are given, returns "
(code "(/ 1 z)")"."
)
)
(proc "div" '((n int?) (m int?) ... int?)
(text "Returns the integer division of "'n" by the "'m"s.")
)
(proc "mod" '((n int?) (m int?) int?) (text "Return the modulo of "'n" and "'m"."))
(proc "modulo" '((n int?) (m int?) int?) (text "Clone of "(link 'mod)"."))
(proc "add1" '((z number?) number?) (text "Returns "(code "(+ z 1)")"."))
(proc "sub1" '((z number?) number?) (text "Returns "(code "(- z 1)")"."))
(syntax "incf" "id [delta 1]"
(text
"Mutate "'id" by adding the evaluated result of "'delta". If "'delta
" is not specified, then add 1 to "'id"."
)
)
(syntax "decf" "id [delta 1]"
(text
"Mutate "'id" by subtracting the evaluated result of "'delta". If "
'delta" is not specified, then subtract 1 from "'id"."
)
)
(proc "=" '((z number?) (w number?) ... bool?)
(text "Returns "#t" if all arguments are numerically equal, "#f" otherwise.")
)
(proc "<" '((x real?) (y real?) bool?)
(text "Returns "#t" if "'x" is less than "'y", "#f" otherwise.")
)
(proc "<=" '((x real?) (y real?) bool?)
(text "Returns "#t" if "'x" is less than or equal to "'y", "#f" otherwise.")
)
(proc ">" '((x real?) (y real?) bool?)
(text "Returns "#t" if "'x" is greater than "'y", "#f" otherwise.")
)
(proc ">=" '((x real?) (y real?) bool?)
(text "Returns "#t" if "'x" is greater than or equal to "'y", "#f" otherwise.")
)
(proc "abs" '((x real?) real?) (text "Returns the absolute value of "'x"."))
(proc "max" '((x real?) ... real?) (text "Returns largest value of the "'x"s."))
(proc "min" '((x real?) ... real?) (text "Returns smallest value of the "'x"s."))
(proc "real-part" '((z number?) real?) (text "Returns the real part of "'z"."))
(proc "imag-part" '((z number?) real?) (text "Returns the imaginary part of "'z"."))
(proc "round" '((x real?) int?)
(text
"Returns the closest integer to "'x" resolving ties in favor of even numbers."
)
)
(proc "pow" '((z real?) (w real?) real?)
(text "Returns "'z" raised to the "'w" power.")
)
(proc "sqrt" '((z number?) number?)
(text "Returns the square root of "'z".")
)
]
"Modules" #[
(syntax "import" "module" (text "Imports a module"))
]
"Math Module" #[
(text "Imported with " (code "(import math)") ".")
(proc "ceil" '((x real?) int?) (text "Returns the smallest integer bigger than "'x"."))
(proc "floor" '((x real?) int?) (text "Returns the largest integer less than "'x"."))
(proc "exp" '((x real?) float?)
(text "Returns Euler's number raised to the "'x" power.")
)
(proc "log" '([x (and/c real? (>/c 0))] [b real? (exp 1)] float?)
(text
"Returns the natural logarithm of "'x".\n"
"If "'b" is provided it serves as an alternative base."
)
)
(value "e" "2.718281828459045" (text "Euler's number."))
(proc "sin" '((z real?) float?) (text "Returns the sine of "'z" in radians."))
(proc "cos" '((z real?) float?) (text "Returns the cosine of "'z" in radians."))
(proc "tan" '((z real?) float?) (text "Returns the tangent of "'z" in radians."))
(proc "asin" '((z (between/c -1 1)) float?) (text "Returns the arc sine of "'z"."))
(proc "acos" '((z (between/c -1 1)) float?) (text "Returns the arc cosine of "'z"."))
(proc "atan" '((z real?) float?) (text "Returns the arc tangent of "'z"."))
(value "pi" "3.141592653589793" (text "The ratio of a circle's circumference to its diameter."))
(value "tau" "6.283185307179586" (text "The ratio of a circle's circumference to its radius."))
]
"Symbols" #[
(pred "symbol?" (text "Returns "#t" if "'v" is a symbol, "#f" otherwise."))
(proc
"symbol->string" '((sym symbol?) string?)
(text "Returns a new string whose characters are the same as in "'sym".")
)
(proc
"string->symbol" '((str string?) symbol?)
(text "Returns a symbol whose characters are the same as "'str".")
)
]
"Strings" #[
(pred "string?" (text "Returns "#t" if "'v" is a string, "#f" otherwise."))
(pred "char?" (text "Returns "#t" if "'v" is a char, "#f" otherwise."))
(proc "string" '((char char?) ... string?)
(text "Returns a new string from the given "'char"s.")
)
(proc "&" '((str string?) ... string?)
(text "Returns a new string concatenated from the given "'str"s")
)
(syntax "&=" "id delta"
(text "Mutate "'id" by concatenating the evaluated result of "'delta".")
)
(proc "upper" '((str string?) string?)
(text
"Returns a string whose characters are the upcase conversion of the "
"characters in "'str" in the C locale."
)
)
(proc "lower" '((str string?) string?)
(text "Like "(link 'upper)", but for downcase conversion.")
)
(proc "title" '((str string?) string?)
(text "Like "(link 'upper)", but for titlecase conversion.")
)
(proc "startswith" '((str string?) (w string?) bool?)
(text "Returns "#t" if "'str" starts with "'w", "#f" otherwise.")
)
(proc "endswith" '((str string?) (w string?) bool?)
(text "Returns "#t" if "'str" ends with "'w", "#f" otherwise.")
)
(proc "strip" '((str string?) string?)
(text "Returns "'str" with its leading and tailing whitespace stripped out.")
)
(proc "replace" '((str string?) (w string?) (z string?) string?)
(text "Returns "'str" will all "'w"s replaced with "'z"s.")
)
(proc "replace" '((str string?) (w string?) (z string?) (count int?) string?)
(text "Returns "'str" will all "'w"s replaced with "'z"s up until "'count".")
)
(proc "split" '((str string?) (by string? "\" \"") vector?)
(text "Returns a vector of strings split from "'str" by '"'by".")
)
(proc "str-repeat" '((str string?) (n int?) string?)
(text "Returns "'str" concatenated "'n" times.")
)
(proc "join" '((strs vector?) (sep string?) string?)
(text "Returns a new string with "'strs" joined between with "'sep".")
)
(proc "change-file-ext" '((a string?) (ext string?) string?)
(text "Returns a new string with the file extension replaced with "'ext".")
)
]
"Format" #[
(proc "char->int" '((char char?) int?)
(text "Returns the corresponding int to the given "'char".")
)
(proc "int->char" '((k int?) char?)
(text "Returns the character corresponding to "'k".")
)
(proc "number->string" '((z number?) string?) (text "Returns "'z" as a string."))
(proc "string->number" '((x string?) float?) (text "Returns "'x" as a float."))
(proc "~a" '((v any) ... string?)
(text "Converts all "'v"s to a string using display with \"\" as the joiner.")
)
(proc "~s" '((v any) ... string?)
(text "Converts all "'v"s to a string using display with \" \" as the joiner.")
)
(proc "~v" '((v any) ... string?)
(text "Converts all "'v" to a string using print with \" \" as the joiner.")
)
]
"Keywords" #[
(pred "keyword?" (text "Returns "#t" if "'v" is a keyword, "#f" otherwise."))
(proc "keyword->string" '((keyword keyword?) vector?)
(text "Returns the string from the given "'keyword", not including the leading hash colon.")
)
(proc "string->keyword" '((str string?) keyword?)
(text "Returns the keyword from the given "'str".")
)
]
"Lists" #[
(pred "list?"
(text "Return "#t" if "'v" is a list (an immutable collection of elements), "#f" otherwise.")
)
(proc "list" '((v any) ... list?)
(text "Returns a new list with the "'v"s as the elements.")
)
(proc "append" '((v list?) ... list?)
(text "Returns a new list with all the arguments appended in order.")
)
]
"Vectors" #[
(pred "vector?"
(text "Returns "#t" if "'v" is a vector (a mutable, resizable collection of elements), "#f" otherwise.")
)
(proc "vector" '((v any) ... vector?)
(text "Returns a new vector with the "'v" args filled with its slots in order.")
)
(proc "make-vector" '((size nat?) (v any 0) vector?)
(text "Returns a new vector with "'size" slots all filled with "'v"s.")
)
(proc "add!" '((vec vector?) (v any) void?)
(text "Append "'v" to the end of "'vec".")
)
(proc "pop!" '((vec vector?) any)
(text "Remove the last element of "'vec" and return it.")
)
(proc "vec-set!" '((vec vector?) (pos int?) (v any) void?)
(text "Set slot "'pos" of "'vec" to "'v".")
)
(proc "vec-append" '((vec vector?) ... vector?)
(text "Returns a new vector with all elements of "'vec"s appended in order.")
)
(proc "vec-extend!" '((vec vector?) (vec2 vector?) ... void?)
(text
"Modify "'vec" so that all elements of "'vec2"s are appended to the"
" end of "'vec" in order."
)
)
(proc "sort" '((vec vector?) vector?) (text "Returns a newly sorted vector."))
(proc "sort!" '((vec vector?) void?) (text "Modifies "'vec" by sorting in place."))
(proc "string->vector" '((str string?) vector?)
(text "Returns a new vector with characters contained in "'str".")
)
]
"Arrays" #[
(pred "array?" (text "Returns "#t" if "'v" is an array, "#f" otherwise."))
(proc "array" '((dtype symbol?) (v any) ... array?)
(text
"Returns a freshly allocated array with "'dtype
" as its datatype and the "'v" args as its values filled in order."
)
)
(proc "make-array" '((dtype symbol?) (size nat?) (v int? 0) array?)
(text
"Returns a freshly allocated array with "'dtype
" as its datatype and the value "'v" filled."
)
)
(proc "array-copy" '((arr array?) array?) (text "Returns a new copy of "'arr"."))
(proc "array-splice!"
'((arr array?) (v real?) (start int? 0) (stop int? (len arr)) array?)
(text "Modify "'arr" by setting "'start" to "'stop" into the value "'v".")
)
(proc "count-nonzero" '((arr array?) nat?)
(text "Returns the number of non-zeros in "'arr".")
)
(pred "bool-array?"
(text "Returns "#t" if "'v" is an array with 'bool as its datatype, "#f" otherwise."
)
)
(proc "bool-array" '((v nat?) ... bool-array?)
(text "Returns a new boolean array with "'v" as its values.")
)
(proc "margin"
'((arr bool-array?) (left int?) (right int? left) bool-array?)
(text
"Returns a new "(link 'bool-array?)" with "'left" and "'right" margin applied."
)
)
(syntax "and" "first-expr rest-expr ..."
(text
"Evaluate " 'first-expr " if the result is a " (link 'bool-array?)
" evaluate all " 'rest-expr "s and return the logical-and of all arrays."
" If the result is " #f " evaluate " 'rest-expr
" one at a time. Return immediately if any arg is " #f
", return " #t " if all values are " #t "."
)
)
(syntax "or" "first-expr rest-expr ..."
(text
"Evaluate "'first-expr" if the result is a "(link 'bool-array?)
" evaluate all "'rest-expr"s and return the logical-and of all arrays."
" If the result is "#t" evaluate "'rest-expr
" one at a time. Return immediately if any arg is "#t
", return "#f" if all values are "#f"."
)
)
(proc "xor"
'(
(expr1 (or/c bool? bool-array?))
(expr2 (or/c bool? bool-array?))
(or/c bool? bool-array?)
)
(text
"Returns a new boolean or boolean-array based on the exclusive-or of "
'expr1" and "'expr2". "'expr2" must be the same type as "'expr1"."
)
)
(proc "not" '(("h" (or/c bool? bool-array?)) (or/c bool? bool-array?))
(text "Returns the inverse of "'h".")
)
(proc "mincut" '((arr bool-array?) (x nat?) bool-array?)
(text
"Turn all 0 runs that are less than "'x" in length to 1s. "
"0s represent cuts, 1s represent clips."
)
)
(proc "minclip" '((arr bool-array?) (x nat?) bool-array?)
(text "Turn all 1 runs that are less than "'x" in length to 0s")
)
(proc "maxcut" '((arr bool-array?) (x nat?) bool-array?)
(text "Turn all 0 runs that are greater than "'x" in length to 1s")
)
(proc "maxclip" '((arr bool-array?) (x nat?) bool-array?)
(text "Turn all 1 runs that are more than "'x" in length to 0s")
)
(value "all" "'all"
(text
"The symbol 'all. "
"Exists for backwards compatibility for older auto-editor versions."
)
)
]
"Ranges" #[
(pred "range?" (text "Returns "#t" if "'v" is a range object, "#f" otherwise."))
(proc "range" '((start int?) (stop int?) (step (and/c int? (not/c 0)) 1) range?)
(text "Returns a range object.")
)
(proc "range->vector" '((rng range?) vector?)
(text "Returns a new vector based on "'rng".")
)
]
"Generic Sequences" #[
(pred "iterable?"
(text
"Returns "#t" if "'v" is a vector array string hash or range, "#f" otherwise."
)
)
(pred "sequence?"
(text "Returns "#t" if "'v" is a vector array string or range, "#f" otherwise.")
)
(proc "len" '((iter iterable?) nat?) (text "Returns the length of "'iter"."))
(proc "member" '((x any) (seq sequence?) bool?)
(text "Returns "#t" if "'x" is in "'seq", "#f" otherwise.")
)
(proc "ref" '((seq sequence?) (pos int?) any)
(text
"Returns the element of "'seq" at position "'pos
" where the first element is at position 0. Negative positions are allowed."
)
)
(proc "reverse" '((seq sequence?) sequence?)
(text "Returns "'seq" in reverse order.")
)
(proc "slice"
'((seq sequence?) (start int?) (stop int? (len seq)) (step int? 1) sequence?)
(text
"Returns the elements of "'seq" from "'start" inclusively to "'stop
" exclusively. If "'step" is negative then "'stop " is inclusive and "
'start" is exclusive."
)
)
(proc "max-seq" '((v sequence?) any) (text "Returns the largest value of "'v"."))
(proc "min-seq" '((v sequence?) any) (text "Returns the smallest value of "'v"."))
]
"Hashmaps" #[
(pred "hash?" (text "Returns "#t" if "'v" is a hash table, "#f" otherwise."))
(proc "hash" '((key any) (val any) ... hash?)
(text "Returns a newly constructed hash map from key-value pairs.")
)
(proc "hash-ref" '((hash hash?) (key any) any)
(text "Returns the value for "'key" in "'hash".")
)
(proc "hash-set!" '((hash hash?) (key any) (v any) void?)
(text "Set "'key" to "'v" in "'hash", overwriting any existing mappings.")
)
(proc "has-key?" '((hash hash?) (key any) bool?)
(text "Returns "#t" if "'key" is in the hash map, "#f" otherwise.")
)
(proc "hash-update!" '((hash hash?) (key any) (updater any) void?)
(text "Updates the value mapped by "'key" in "'hash" by applying "'updater
" to the value. The value returned by "'updater
" becomes the new mapping for "'key", overwriting the original value in "'hash".")
)
(proc "hash-remove!" '((hash hash?) (key any) void?)
(text "Removes any existing mapping for "'key" in "'hash".")
)
]
"File System" #[
(proc "file-exists?" '((str path) bool?)
(text "Returns "#t" if a file (not a directory) "'path" exists, "#f" otherwise.")
)
]
"I/O" #[
(pred "input-port?" (text "Returns "#t" if "'v" is an input port, "#f" otherwise."))
(proc "open-input-file" '((path string?) input-port?)
(text "Opens the file specified by "'path" for input.")
)
(pred "output-port?" (text "Returns "#t" if "'v" is an output port, "#f" otherwise."))
(proc "open-output-file" '((path string?) output-port?)
(text "Opens the file specified by "'path" for output.")
)
(pred "port?" (text "Returns "#t" if "'v" is an input or output port, "#f" otherwise."))
(proc "close-port" '((port port?) void?)
(text
"Flushes, then closes the port "'port". The port is now incapable of delivering"
" or accepting data. This has no effect if the port has already been closed."
)
)
(proc "closed?" '((v port?) bool?)
(text "Returns "#t" if "'port" is a closed port, "#f" otherwise.")
)
(proc "read-line" '((v input-port?) (or/c string? void?))
(text "Returns the next line in "'v", returns void when at the end of the file.")
)
]
"Subprocess" #[
(proc "system" '((cmd string?) bool?)
(text
"Executes a Unix-like or Windows shell command synchronously. "
"Returns "#t" if successful, "#f" otherwise."
)
)
(proc "system*" '((command string?) (arg string?) ... bool?)
(text
"Executes a Unix-like or Windows shell command synchronously. "
"Returns "#t" if successful, "#f" otherwise."
)
)
]
"Printing" #[
(proc "print" '((datum any) (out output-port? "#<stdout>") void?)
(text "Display "'datum" like REPL does.")
)
(proc "println" '((datum any) (out output-port? "#<stdout>") void?)
(text "Display "'datum" like print but with a newline character.")
)
(proc "display" '((datum any) (out output-port? "#<stdout>") void?)
(text "Display "'datum" to stdout.")
)
(proc "displayln" '((datum any) (out output-port? "#<stdout>") void?)
(text "Display "'datum" to stdout with a newline character.")
)
]
"Actions" #[
(proc "begin" '(("datum" "any") ... "any")
(text "Evaluates all arguments and returns the last one.")
)
(proc "assert" '((expr any) (msg (or/c string? #f) #f) void?)
(text "Raises error if "'expr" is not "#t".")
)
(proc "error" '((msg string?) void?)
(text "Raises an exception with "'msg" as the message.")
)
(proc "sleep" '((time (or/c int? float?)) void?)
(text "Adds a delay of "'time" seconds.")
)
]
"Void" #[
(pred "void?" (text "Returns "#t" if "'v" is "(void)", "#f" otherwise."))
(proc "void" '((v any) ... void?)
(text "Returns the constant "(void)". All "'v" arguments are ignored.")
)
]
"Procedures" #[
(pred "procedure?" (text "Returns "#t" if "'v" is a procedure, "#f" otherwise."))
(pred "contract?"
(text
"Returns "#t" if "'v" is a contract, "#f" otherwise. "
"A contract is either a " (link 'bool?) ", " (link 'number?) ", "
(link 'string?) ", " (link 'symbol?) " literal, or a predicate."
)
)
(pred "any" (text "Always returns "#t" regardless of the value of "'v"."))
(proc "map" '((proc procedure?) (seq sequence?) sequence?)
(text "Returns a new sequence with the results of "'proc" applied to each element.")
)
(proc "apply" '((proc procedure?) (seq sequence?) any)
(text "Applies "'proc" given "'seq" as its arguments.")
)
(proc "and/c" '((contract contract?) contract?)
(text
"Takes any number of contracts and returns a contract predicate that "
"accept values that satisfies all contracts."
)
)
(proc "or/c" '((contract contract?) contract?)
(text
"Takes any number of contracts and returns a contract predicate that "
"accept values that can satisfy one or more contracts."
)
)
(proc "not/c" '((contract contract?) contract?)
(text
"Takes one contract and returns a contract that accepts a value that "
"satisfies the opposite of the given contract."
)
)
(proc ">=/c" '((n real?) contract?)
(text
"Returns a new contract that requires the input to be "(link 'real?)
" and "(link '>=)" than "'n"."
)
)
(proc ">/c" '((n real?) contract?)
(text "Like "(link '>=/c)" but for "(link '>)".")
)
(proc "<=/c" '((n real?) contract?)
(text "Like "(link '>=/c)" but for "(link '<=)".")
)
(proc "</c" '((n real?) contract?)
(text "Like "(link '>=/c)" but for "(link '<)".")
)
(proc "between/c" '((n real?) (m real?) contract?)
(text
"Returns a contract that requires the input a real number between "'n
" and "'m" or equal to one of them."
)
)
]
"Reflection" #[
(syntax "quote" "body"
(text
"Returns "'body" as its \"literalized\" form, "
"a constant value with its binding names copied."
)
)
(proc "var-exists?" '((sym symbol?) bool?)
(text
"Returns "#t" if the variable corresponding to "'sym
" is defined in the current environment, "#f" otherwise."
)
)
(syntax "rename" "original new"
(text
"Move the original identifier to the new identifier. "
"Works for both procedures and syntaxes."
)
)
(syntax "delete" "identifier" (text "Deletes identifier from the environment."))
(proc "eval" '((arg any) any)
(text "Allows running arbitrary, dynamically generated code. Effective the opposite of "(link 'quote)".")
)
]
"Objects" #[
(syntax "class" "name [id contract?]..." (text
"Creates a object initiator and a predicate to identify that object. Example:\n"
(codeblock "(class person [name string?] [age nat?])
(define alyssa (person \"Alyssa P.\" 23))
alyssa.name ; returns \"Alyssa P.\"
alyssa.age ; returns 23
(person? alyssa) ; returns #t")
"Class objects are mutable"
(codeblock "(incf alyssa.age) ; Increase age by 1"))
)
(syntax "@r" "obj attr"
(text
"Returns the specified attribute on the object. "
"Users are not expected to directly use this special form. "
"Instead, use the `.` syntax."
(codeblock "(define a 10)\na.incf ; turns into (@r a incf)")
)
)
]
})
(define file (open-output-file "src/ref/palet.html"))
(when (equal? file #f)
(error "palet.html port failed to open.")
)
(displayln "{{ header \"Palet Scripting Reference\" }}
<style>
.palet-block {
padding-left: 7px;
padding-bottom: 7px;
padding-top: 7px;
margin-top: 30px;
margin-bottom: 6px;
}
.palet-block > p {margin-top: 0; margin-bottom: 0}
.palet-var {
position: relative;
left: -1px;
font-size: 85%;
font-style: italic;
font-family: SFMono-Regular, ui-monospace, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
}
.palet-val {
color: #0B65B8;
font-size: 85%;
font-family: SFMono-Regular, ui-monospace, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
}
.palet-block { background-color: #F9F5F5; border-top: 3px solid #EAEAEA}
@media (prefers-color-scheme: dark) {
.palet-block {background-color: #323232; border-top: 3px solid #4A4A4A}
.palet-val {color: #A3DEFF}
}
</style>
<body>
{{ nav }}
<section class=\"section\">
<div class=\"container\">
<h1>Palet Scripting Reference</h1>
<p>This reference manual describes all the builtin syntax, procedures, and values in the language that are defined by default. <a href=\"/ref/edit\">--edit docs</a></p>"
file )
(doc-builder file core-docs standard-env)
(define file2 (open-output-file "src/ref/edit.html"))
(when (equal? file2 #f)
(error "edit.html port failed to open.")
)
(displayln "{{ header \"Edit Reference\" }}
<style>
.palet-block {
padding-left: 7px;
padding-bottom: 7px;
padding-top: 7px;
margin-top: 30px;
margin-bottom: 6px;
}
.palet-block > p {margin-top: 0; margin-bottom: 0}
.palet-var {
position: relative;
left: -1px;
font-size: 85%;
font-style: italic;
font-family: SFMono-Regular, ui-monospace, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
}
.palet-val {
color: #0B65B8;
font-size: 85%;
font-family: SFMono-Regular, ui-monospace, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
}
.palet-block { background-color: #F9F5F5; border-top: 3px solid #EAEAEA}
@media (prefers-color-scheme: dark) {
.palet-block {background-color: #323232; border-top: 3px solid #4A4A4A}
.palet-val {color: #A3DEFF}
}
</style>
<body>
{{ nav }}
<section class=\"section\">
<div class=\"container\">
<h1>Edit Reference</h1>
<p>When you run:<p>
<pre><code>auto-editor example.mp4 --edit audio:0.05,stream=0</code></pre>
<p>You're actually running a palet expression!<br>To be precise, you're writing the syntax-sugary equivalent of:</p>
<pre><code>auto-editor example.mp4 --edit \"(audio 0.05 #:stream 0)\"</code></pre>
<p>Isn't that neat.<br>You can use any syntax or procedure <a href=\"/ref/palet\">defined in the core language</a>.</p>
<pre><code>auto-editor example.mp4 --edit '(print \"Hello World!\")(audio 0.05 #:stream 0)'</code></pre>
<p>And that command will indeed, print \"Hello World!\".<br>As long as that expression returns a boolean array, you can do anything.</p>
<p>All the edit methods are listed below:</p>" file2)
;<p>Of course, you probably know that you can use procedures like <code>motion</code> and <code>subtitle</code> too. However, this example doesn't have much motion and has no subtitle streams.</p>
;<pre><code>auto-editor example.mp4 --edit '(map (lambda (x) (and (< x 0.01) (>= x 0.9) audio-levels:0)</code></pre>
(doc-builder file2 edit-docs #f)
|