4 ms·
I'm guessing there are very few people out there that think of programs as that dynamic? Especially considering that the message you are quoting started from p
by taeric 3y ago
I'm guessing there are very few people out there that think of programs as that dynamic? Especially considering that the message you are quoting started from python, how does it compare there?
I'm also curious to know why I would want something that was so dynamic that + could be redefined on me.
- Turing_Machine 3y agoOne that comes immediately to mind is that you might want + to handle vectors as well as scalars. Something like: (define scalar-sum +) (define (+ . arguments) (if (vectors? 'arguments) (vector-sum 'arguments) (apply scalar-sum arguments))) vectors? and vector-sum not shown for clarity. Edit: or maybe you want any sum in excess of (say) $5,000 to alert a manager. (define old-plus +) (define (+ . args) (let ((value (apply old-plus args))) (if (> value 5000) (begin (alert-manager) value) value))) The nice thing here is that this Just Works anywhere + appears in the code. You don't need to put the conditional and the call to alert-manager everywhere you're calculating a sum. Of course, in a real implementation you'd want to pass stuff to alert-manager like what module you're in, the transaction number, etc.
- taeric 3y agoFair, I should have tried to use my imagination there. Basically operator overloading? I forgot that generic functions are different beasts, and I've rarely had need for this, myself.