Why is there no generic operators for Common Lisp? -
in cl, have many operators check equality depend on data type: =, string-equal, char=, equal, eql , whatnot, on other data types, , same comparison operators (edit don't forget answer these please :) have generic <, > etc ? can make them work object ?)
however language has mechanisms make them generic, example generics (defgeneric, defmethod) described in practical common lisp. imagine same == operator work on integers, strings , characters, @ least !
there have been work in direction: https://common-lisp.net/project/cdr/document/8/cleqcmp.html
i see major frustration, , wall, beginners (of am), specially come other languages python use 1 equality operator (==) every equality check (with of objects make on custom types).
i read a blog post (not monad tutorial, great serie) today pointing this. guy moved clojure, other reasons of course, there 1 (or two?) operators.
so why ? there reasons ? can't find third party library, not on cl21.
on other questions read performance. first, won't apply little code i'll write don't care, , if think have figures make point ?
edit: despite tone of answers, looks there not ;) discuss in comments.
yes have! eq works all values , works time. not depend on data type @ all. looking for. it's is operator in python. must looking for? other ones agree eq when it's t, tend t totally different values have various levels of similarities.
(defparameter *a* "this string") (defparameter *b* *a*) (defparameter *c* "this string") (defparameter *d* "this string") all of these equalp since contain same meaning. equalp perhaps sloppiest of equal functions. don't think 2 , 2.0 same, equalp does. in mind 2 2 while 2.0 somewhere between 1.95 , 2.04. see not same.
equal understands me. (equal *c* *d*) nil , good. returns t (equal *a* *c*) well. both arrays of characters , each character same value, 2 strings not same object. happen same.
notice i'm using string here every single 1 of them. have 4 equal functions tells if 2 values have in common, eq tells if same.
none of these type specific. work on types, not generics since around long before added in language. perhaps make 3-4 generic equal functions better ones have?
Comments
Post a Comment