2 ms·
Dispatch a function based on the value it is expected to return. The version of this that exists in some real programming languages at the moment (no "fantasy
by dllthomas 12y ago
Dispatch a function based on the value it is expected to return. The version of this that exists in some real programming languages at the moment (no "fantasy semantics") is dispatching based on the inferred type of the expression. Depending on your POV, that's quite arguably a part of the value returned. It obviously can't be chosen dynamically by the call, or we would be dealing with "fantasy semantics" (or a time machine).
- kazinator 12y ago"fantasy semantics" simply refers to the imagined semantics we want to have: the functional requirement. The semantics which isn't real right now, but we would like to implement. (Not sure why I got a downvote. Is there a possible perception that I wasn't being civil?) It occurs to me that some dynamic dispatch can take place based on what the method call returns. Suppose we split the computation of the function into two functions: the function proper, and a fixup which is applied to the return value. The main function's method could have a CLOS :around method wrapped around it which obtains the return value of the primary method (via en explicit (call-next-method) call, and then invokes the fixup method on the argument. The fixup method is then dynamically dispatched on this return value, and possibly provides the ultimate return value. Of course, this is different from dispatching a method based on the context in which it occurs. Still, no time machine needed.
- dllthomas 12y agoI did think "fantasy semantics" was meant to imply it was unlikely I could come up with coherent semantics for it. I wouldn't have considered that sufficient incivility to earn a down-vote, though. Splitting functions is an interesting idea, though unless you're passing in context as an argument it'd be another way of dispatching on the same arguments (with, presumably, more user control but probably also more boiler plate).
- kazinator 12y agoYes, in this conception of what it means to dispatch on the actual returned type, the caller doesn't know, in the same sense that it doesn't know what sequence of methods is dispatched based on the arguments, either! It calls a generic function, which does some magic internally and produces a return value (or various side effects or both). By the way, it appears I can explain why I had used the word "fantasy": I have been recently involved in some discussions about Gödel's Incompleteness Theorem. That stirred up distant memories of reading Hofstadter, dredging up some of his vocabulary.