Wilfred / suggest.el

discover elisp functions that do what you want
367 stars 14 forks source link

Add boolean functions #36

Closed nickdrozd closed 6 years ago

nickdrozd commented 6 years ago

It looks like for the most part, boolean p-functions (numberp, stringp, consp) are included in the results when the output is t, but not when the output is nil. For instance, the query [5] => nil might be expected to return (stringp 5). Functions that operate on booleans (booleanp, not) don't seem to show up at all.

Maybe suggest is fundamentally list-oriented, and the output nil is interpreted as a list, rather than a boolean. Perhaps the split is due to the arguably dumb choice in Emacs to use the empty list for false instead of a dedicated boolean symbol.

;; Inputs (one per line):
5

;; Desired output:
t

;; Suggestions:
(numberp 5) ;=> t
(last t 5) ;=> t
(remove 5 t) ;=> t
(plist-member t 5) ;=> t
(cdr (cons 5 t)) ;=> t
;; Inputs (one per line):
5

;; Desired output:
nil

;; Suggestions:
(elt nil 5) ;=> nil
(nth 5 nil) ;=> nil
(remq 5 nil) ;=> nil
(last nil 5) ;=> nil
(-drop 5 nil) ;=> nil
;; Inputs (one per line):
"string"

;; Desired output:
t

;; Suggestions:
(stringp "string") ;=> t
(remove "string" t) ;=> t
(plist-member t "string") ;=> t
(cdr (cons "string" t)) ;=> t
(car (cons t "string")) ;=> t
;; Inputs (one per line):
"string"

;; Desired output:
nil

;; Suggestions:
(-zip "string" nil) ;=> nil
(remq "string" nil) ;=> nil
(last "string" -1) ;=> nil
(assoc "string" nil) ;=> nil
(-take -1 "string") ;=> nil
;; Inputs (one per line):
'(1 2 3)

;; Desired output:
t

;; Suggestions:
(consp '(1 2 3)) ;=> t
(remove '(1 2 3) t) ;=> t
(-is-infix-p nil '(1 2 3)) ;=> t
(plist-member t '(1 2 3)) ;=> t
(-is-suffix-p nil '(1 2 3)) ;=> t
;; Inputs (one per line):
'(1 2 3)

;; Desired output:
nil

;; Suggestions:
(-zip '(1 . 2) nil) ;=> nil
(remq '(1 . 2) nil) ;=> nil
(last '(1 . 2) -1) ;=> nil
(assoc '(1 . 2) nil) ;=> nil
(-take -1 '(1 . 2)) ;=> nil
;; Inputs (one per line):
t

;; Desired output:
t

;; Suggestions:
(last t) ;=> t
(-cons* t) ;=> t
(append t) ;=> t
(-concat t) ;=> t
(identity t) ;=> t
;; Inputs (one per line):
t

;; Desired output:
nil

;; Suggestions:
(-zip t nil) ;=> nil
(remq t nil) ;=> nil
(last t -1) ;=> nil
(assoc t nil) ;=> nil
(-take -1 t) ;=> nil

Note that this PR does NOT solve #35.

Wilfred commented 6 years ago

Yep, boolean functions are definitely worth adding. Suggest.el isn't intended to be limited to lists: it does a good job with strings and numbers too (vector support is limited currently).

Booleans are less useful when you can only supply one example, see #29.

Based on your great examples here, I've tweaked suggest-extra-args in 0601f08 to avoid some of these sillier examples. A lot of functions return nil if they don't know what to do, so 5 => nil is a tricky problem.

Suggest.el will stop searching after it's found more than 20 results, see suggest--max-possibilities. For nil, we're finding so many ways of calculating it that we don't reach the boolean functions.

Could you put the booleans first in suggest-functions? That will ensure we suggest using them.

nickdrozd commented 6 years ago

Updated

Wilfred commented 6 years ago

Thank you :)