DWIM sketch added by kon on Fri Aug 22 15:22:01 2025
(import string-interpolation) (define BUILTINS '(x p d du dur r q l ln t exn e ch h c f g s ?)) (define (command? id) (or (memq id BUILTINS) (assq id command-table))) ;optional help, reuses "current help" when missing. ; ;say statement "." means info, ";" means commentary, ; ;ask query "?" means a Y|N boolean, ":" means a * (define-type say (string -> void)) (define-type ask (string #!rest string -> *)) (define-type evaluator (* -> void)) (define (dwim-dot-command form command? say ask evaluator) (and-let* ((hd (car form)) (((symbol? hd))) ((nm (symbol->string hd))) ) (if (not (positive? (string-length nm))) (false (say "Looking for a command or an expression but got nothing; #(form)")) (begin ;what's wrong (say "You began what might be a command w/ an invalid marker.") ;try common mistake(s) 1st. then a more generic ask (if (or (and (char=? #\. (string-ref rm 0)) (ask "Looks like you typed the `.', instead of the `,'. Fix it?")) (ask "Did you mean a command? Maybe just typo'ed the marker?" "A \"marker\" is the leading character used to signal a command." "Here looking for a `,'.")) ;then see if can extract a viable command w/ little effort (let ((cmd (string->symbol (substring nm 1)))) (if (command? cmd) ;then go for it w/o asking since exact spelling (evaluator `(unquote ,cmd ,@(cdr form))) ;else give up ;not just a typo'ed marker. skip prefix & try again. then fail. (false (say #"`#(cmd)' is not unrecognized as a command"))) ) ;else give up (false (say "There isn't more help.")) ) ) ) ) ) (set! ##sys#user-form-parse-hook dwim-command)