2 ms·
> How do you write a Common Lisp function which polymorphicly converts an integer to whatever type you need? How does the callee know what the caller needs? S
by anamax 17y ago
> How do you write a Common Lisp function which polymorphicly converts an integer to whatever type you need?
How does the callee know what the caller needs?
Suppose that one callee produces an int (as above), the first caller wants a string (decimal digits in ascii) and the second wants a byte array (little endian). Do you really think that the caller (or compiler) should be responsible for accomodating those conversions? Now let's add a caller that wants the index of the "high bit" - how are you going to accomodate that? (Of course, other callers want an int - I'm just mentioning the callers that require some sort of conversion.)
Neither the callee nor the compiler/system can automatically provide anything beyond the most trivial of conversions. That's why the right solution to the third caller, either an in-line shim or a wrapper, is the right solution to either the first or second caller.
> With macros, you could just include the creation of the appropriate classes in the form that defines a new type. In fact, it could be built into the language making even macros unnecessary.
Lisp macros can do many other things. (Consider the loop construct.)