---
title: "单分派与多分派,聊天记录"
author: "coderplay"
date: "2008-06-14T19:11:52Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2008-06-14T19:11:52Z"
id: 203290
url: "https://coderplay.iteye.com/blog/203290"
---

2007-12-17 23:06:01 lct  
The solution to these problems is to replace  
dynamically-dispatched messages with one or more statically-bound procedure calls  
wherever possible, to inline-expand the callee methods whenever the callee is small (a  
common case given the presence of accessor methods, user-defined control structures, and  
standard operations like addition implemented as methods), and to eliminate creations of  
closures whenever no more references to the closures remain after inlining their bodies.  
 

2007-12-17 23:06:08 lct  
这什么意思

2007-12-17 23:06:16 lct  
 inline-expand ？？？？？？？

2007-12-17 23:06:32 coderplay  
上下文是?  
 

2007-12-17 23:07:08 lct  
就是那篇的3 Language Implementation Research  
 

2007-12-17 23:07:35 lct  
profile？？？？？？？？大纲？？？

2007-12-17 23:07:46 coderplay  
估计你是看不懂了.呵呵  
 

2007-12-17 23:07:59 coderplay  
profile是一个专业术语  
 

2007-12-17 23:08:07 lct  
\[/流汗]赶紧帮我看看啊\[/撇嘴]

2007-12-17 23:08:14 lct  
明天还得上台讲呢

2007-12-17 23:08:23 lct  
我都看不懂，

2007-12-17 23:08:23 coderplay  
是用来观察程序哪里运行最耗时间,最占内存.  
 

2007-12-17 23:08:44 lct  
profile怎么翻译

2007-12-17 23:10:02 lct  
剖面？？？可否？

2007-12-17 23:10:25 coderplay  
就是profile, 没有翻译  
 

2007-12-17 23:10:47 coderplay  
剖析应该比较准确  
 

2007-12-17 23:11:35 lct  
哦

2007-12-17 23:11:54 lct  
看了，你对文章大意理解如何

2007-12-17 23:12:39 lct  
The set of classes computed for each expression is different than the information available  
from static type declarations. The set of classes is a specific list of concrete classes, with no  
ambiguity or open-endedness. A static type declaration, on the other hand, specifies an  
interface to an expression, but provides no information about what classes might implement  
that interface.  
 

2007-12-17 23:12:57 lct  
ambiguity or open-endedness.？？？？？？？？？

2007-12-17 23:14:20 coderplay  
也有不懂的地方,我得花时间...  
 

2007-12-17 23:15:32 coderplay  
这个论题很窄嘞  
 

2007-12-17 23:15:46 lct  
compile-time method lookup,  
？？？？？？？？

2007-12-17 23:15:46 coderplay  
涉及到的具体东西很多  
 

2007-12-17 23:16:05 lct  
太具体，太专业了

2007-12-17 23:16:23 coderplay  
compile-time method lookup,编译期的方法查找  
 

2007-12-17 23:16:32 lct  
我觉得我完全没有那个背景知识，很难理解

2007-12-17 23:16:35 coderplay  
对应的是 run-time method lookup  
 

2007-12-17 23:16:42 lct  
好

2007-12-17 23:17:12 coderplay  
我要花一个半小时看完  
 

2007-12-17 23:17:35 lct  
perform method lookup     ？

2007-12-17 23:17:47 lct  
我花了两三天

2007-12-17 23:18:00 coderplay  
那你等下吧,不要先提.我现在才看第一段  
 

2007-12-17 23:33:10 lct  
When static class analysis cannot determine a tight bound on the set of possible classes of the  
receiver of some message,  
 

2007-12-17 23:37:43 coderplay  
晕...  
 

2007-12-17 23:37:49 coderplay  
好像很难解释  
 

2007-12-17 23:38:40 coderplay  
你知道重载,重写的区别? 还有它们与多态的联系吗?  
 

2007-12-17 23:39:01 lct  
忘了

2007-12-17 23:39:13 coderplay  
还有面向对象的消息传递  
 

2007-12-17 23:39:18 coderplay  
这好像很难说...  
 

2007-12-17 23:39:24 coderplay  
换一篇吧...  
 

2007-12-17 23:39:40 lct  
呵呵，哪来得及，明天早上8点

2007-12-17 23:39:51 lct  
死马当活马医了

2007-12-17 23:40:03 coderplay  
他开始说的是设计了一种叫cecil的语言  
 

2007-12-17 23:40:38 lct  
嗯

2007-12-17 23:40:52 coderplay  
语言设计分两类, 一种是追求语言的表达能力, 还有一种是追求语言的运行性能  
 

2007-12-17 23:41:28 lct  
These results indicate that intraprocedural optimizations of messages speed Cecil programs  
by at least a factor of two.

 

2007-12-17 23:41:29 coderplay  
他设计的cecil语言能和c++一样高效,但比c++更规范,更灵活  
 

2007-12-17 23:41:36 lct  
a factor of two.？？？？？

2007-12-17 23:42:00 coderplay  
不要去钻哪个字的意思啊  
 

2007-12-17 23:42:20 lct  
a factor of two.？？？？？

2007-12-17 23:42:29 lct  
这是关键意思

2007-12-17 23:42:32 lct  
关系理解

2007-12-17 23:43:42 lct  
还有文章中的class，虽然我理解成“类”，但感觉怪怪的

2007-12-17 23:45:03 coderplay  
你先说一遍意思吧  
 

2007-12-17 23:45:09 coderplay  
我还在看前面的  
 

2007-12-17 23:45:42 lct  
coderplay 23:45:03  
你先说一遍意思吧

？

2007-12-17 23:48:11 coderplay  
就是你先说说你的理解  
 

2007-12-17 23:48:22 coderplay  
通篇的  
 

2007-12-17 23:50:06 lct  
正在整理

2007-12-17 23:52:33 lct  
如果说通篇内容，也就是introduction那部分的内容

2007-12-17 23:52:57 coderplay  
你先打,我看着  
 

2007-12-17 23:53:07 coderplay  
具体的说说看  
 

2007-12-17 23:53:52 coderplay  
他是指语言的灵活性和程序性能是相冲突的,但他有办法解决  
 

2007-12-17 23:54:26 lct  
Multi-methods are treated as overloaded functions, where overload resolution is  
determined by the dynamic classes of the arguments,  
 

2007-12-17 23:54:34 lct  
这关系到理解

2007-12-17 23:56:41 coderplay  
这个是灵活性的部分了  
 

2007-12-17 23:56:53 lct  
怎么理解

2007-12-17 23:56:57 coderplay  
看来搞不完嘞.边给你解释,边看  
 

2007-12-17 23:57:16 lct  
看懂字面，却理解不了

2007-12-17 23:57:24 coderplay  
传统的OOP语言有重载与重写  
 

2007-12-17 23:58:31 coderplay  
重载是一个类里面有多个同名的方法比如

class A  
{  
   public void func\_name(void);  
   public void func\_name(Object obj);  
}  
 

2007-12-17 23:58:36 coderplay  
这是重载.  
 

2007-12-17 23:59:02 coderplay  
到底是调用func\_name(void)还是调用func\_name(Object).  
 

2007-12-17 23:59:13 coderplay  
这取决于你传给方法的参数的类型  
 

2007-12-17 23:59:16 lct  
There are no variables or  
expressions where this subtype polymorphism is restricted, unlike C++  
 

2007-12-18 00:00:01 lct  
重载明白，重写呢？

2007-12-18 00:01:00 lct  
overloaded是重写？

2007-12-18 00:01:28 coderplay  
重写是和继承相关的

class A  
{  
  virtual fun\_name()  
}

class B inherite A  
{  
  func\_name();  
}

   
 

2007-12-18 00:01:42 coderplay  
重载(overload) ,重写(override)  
 

2007-12-18 00:02:26 lct  
呵呵，好

2007-12-18 00:02:27 coderplay  
然后有一个B的实例  
B b = new B;  
b.func\_name(); // 这句不会调用A.fun\_name  
 

2007-12-18 00:03:02 coderplay  
虽然参数都一样,这是为了消除继承的二义性  
 

2007-12-18 00:03:25 coderplay  
class Cat{  
    public void eat(){  
        System.out.println("cat eat");  
    }  
}  
public class BlackCat extends Cat{  
    public void eat(){  
        System.out.println("black cat eat");  
    }  
    public static void main(String\[] args){  
        Cat cat = new BlackCat();  
        cat.eat();  
    }  
}  
 

2007-12-18 00:03:33 coderplay  
这个时候的结果是:  
black cat eat  
 

2007-12-18 00:04:11 coderplay  
如果  
 Cat cat = new Cat();  
 cat.eat();  
结果则是cat eat  
   
 

2007-12-18 00:04:32 lct  
多方法可以看作重载函数，

2007-12-18 00:04:44 coderplay  
no  
 

2007-12-18 00:04:51 coderplay  
有区别  
 

2007-12-18 00:04:52 lct  
好，你说的例子我明白，但遇到字面无法翻译

2007-12-18 00:05:07 lct  
Multi-methods are treated as overloaded functions, where overload resolution is  
determined by the dynamic classes of the arguments,

2007-12-18 00:05:17 lct  
我要说出这个意思

2007-12-18 00:05:31 coderplay  
重载是编译完成后,调用的方法是确定的  
 

2007-12-18 00:05:54 lct  
？

2007-12-18 00:05:54 coderplay  
而重写,程序到底调用哪个方法是运时期决定的  
 

2007-12-18 00:06:12 coderplay  
而不是编译期  
 

2007-12-18 00:07:10 coderplay  
比如这个  
class A  
{  
   public void func\_name(void);  
   public void func\_name(Object obj);  
}

编译后,两个函数分别是  
func\_name\_void(A this)  
func\_name\_Object(A this, Object o)  
 

2007-12-18 00:07:24 coderplay  
所以编译完成后,它们实际上是两个名称不相同的函数  
 

2007-12-18 00:07:31 coderplay  
而重写却不同  
 

2007-12-18 00:07:40 coderplay  
它们的函数名在编译完成后还是相同的  
 

2007-12-18 00:08:15 lct  
哦

2007-12-18 00:08:19 lct  
那Multi-methods are treated as overloaded functions, where overload resolution is  
determined by the dynamic classes of the arguments,

2007-12-18 00:08:23 lct  
？？？？？？？？

2007-12-18 00:08:25 coderplay  
只是第一个参数this的类型不同  
func\_name\_void (A this)  
func\_name\_void (B this)  
 

2007-12-18 00:09:07 coderplay  
Multi-methods有点像重载函数  
 

2007-12-18 00:09:57 coderplay  
但CLOS的Multi-methods是多重分发(multiple dispatching)的  
 

2007-12-18 00:10:18 lct  
参数的动态类决定重载的，，

2007-12-18 00:10:36 coderplay  
重载是编译期后就决定了的,是静态的  
 

2007-12-18 00:10:51 coderplay  
而Multi-methods是运态决定的,是动态的  
 

2007-12-18 00:11:38 coderplay  
它通过动态检测所有参数的类型来决定调用哪个函数  
 

2007-12-18 00:11:56 coderplay  
是动态意义上的函数重载  
 

2007-12-18 00:12:00 lct  
coderplay 00:09:07  
Multi-methods有点像重载函数  
coderplay 00:10:35  
重载是编译期后就决定了的,是静态的  
coderplay 00:10:52  
而Multi-methods是运态决定的,是动态的

2007-12-18 00:12:03 lct  
糊涂了

2007-12-18 00:13:48 coderplay  
重载编译后,两个函数分别是  
func\_name\_void(A this)  
func\_name\_Object(A this, Object o)

当你调用时,实际上是调用两个不同的函数  
func\_name\_void(A this)和  
func\_name\_Object(A this, Object o)  
仅管你的程序,看上去是调用同名的方法.但编译器已经帮你的函数的名称全部换了  
 

2007-12-18 00:15:37 coderplay  
编译前是  
A::func\_name(void)  
A::func\_name(Object o)  
调用方法分别是  
a.func\_name()  
b.func\_name(obj)

编译后是  
func\_name\_void(A this)  
func\_name\_Object(A this, Object o)  
调用方法分别是  
func\_name\_void(a)  
func\_name\_Object(a, obj)  
 

2007-12-18 00:16:09 coderplay  
运行时,两个方法根本没有任何联系  
 

2007-12-18 00:16:12 coderplay  
连名称都不一样  
 

2007-12-18 00:16:22 coderplay  
这是重载  
 

2007-12-18 00:16:39 coderplay  
而Multi-Methods编译后的名称是一样的  
 

2007-12-18 00:16:58 coderplay  
只是参数类型不一样    
 

2007-12-18 00:17:20 coderplay  
程序到底调用哪个函数, 是通过所有参数的类型来决定的  
 

2007-12-18 00:18:46 lct  
在C++中也学过，你说了我也明白了，但是对那篇文章的理解还是不行

2007-12-18 00:19:07 coderplay  
他的意思是说Multi-Methods兼俱重写的动态性, 和重载的灵活性  
 

2007-12-18 00:19:36 coderplay  
Multi-methods are treated as overloaded functions, where overload resolution is  
determined by the dynamic classes of the arguments,  
这句你应该明白了吧  
 

2007-12-18 00:19:45 coderplay  
这是CLOS的作法  
 

2007-12-18 00:19:50 lct  
怎么翻译

2007-12-18 00:19:57 coderplay  
一定要翻译?  
 

2007-12-18 00:20:03 lct  
dynamic classes

2007-12-18 00:20:16 coderplay  
动态类型  
 

2007-12-18 00:20:31 lct  
参数的动态类？or动态类型

2007-12-18 00:20:38 coderplay  
类型  
 

2007-12-18 00:20:55 lct  
与type？

2007-12-18 00:21:03 coderplay  
不要去抠字眼,这是因为英语和汉语的差别  
 

2007-12-18 00:21:26 coderplay  
你只是感觉类与类型的区别比class与type大  
 

2007-12-18 00:21:34 lct  
因为我一直把全文的class理解成类了，面向对象中的类

2007-12-18 00:21:35 coderplay  
明白意思就okay  
 

2007-12-18 00:21:49 coderplay  
后面作者说他的语言  
 

2007-12-18 00:21:51 lct  
现在明白了

2007-12-18 00:21:57 coderplay  
与CLOS不同  
 

2007-12-18 00:22:05 coderplay  
他的语言灵活性更强  
 

2007-12-18 00:22:41 lct  
class hierarchy analysis  
这个应该是类层次分析吧？不会是类型了吧

2007-12-18 00:22:50 coderplay  
In fact, the implementation of the  
operation can evolve over time, with special cases added incrementally without revising  
previous versions or client code. The choice of implementation strategy is properly hidden  
from clients, and there are no restrictions on future incremental extension to the set of multi-  
methods.  
 

2007-12-18 00:23:00 coderplay  
对头  
 

2007-12-18 00:23:48 coderplay  
复制错了.这句:  
 The Cecil  
approach to multi-methods differs from the CLOS approach by allowing each multi-method  
to independently determine which subset of its arguments requires dynamic dispatching  
(there is no °∞congruent lambda list°± rule as in CLOS) and by treating all argument positio  
with equal priority (there is no left-to-right ordering of argument positions as in CLOS).  
 

2007-12-18 00:24:29 coderplay  
Cecil对multi-methods的方法与CLOS的方法不同  
 

2007-12-18 00:24:52 coderplay  
CLOS是要检查所有的参数的类型来决定调用哪个函数  
 

2007-12-18 00:25:51 lct  
这个明白

2007-12-18 00:26:29 coderplay  
而Cecil可以自定义.  
比如参数是 (A a, B b, C c)  
CLOS要检查a,b,c的类型  
而Cecil用户则可能只要检查一个子集b,c的类型.    
 

2007-12-18 00:27:21 coderplay  
Cecil语言支持这种特性  
 

2007-12-18 00:27:28 lct  
嗯

2007-12-18 00:28:01 coderplay  
lambda list是一个术语, 与丘奇的可计算模型相关  
 

2007-12-18 00:28:52 lct  
\[/惊讶]太有才了

2007-12-18 00:28:56 coderplay  
下面那段就是消息传递  
 

2007-12-18 00:29:09 lct  
谢谢周大叔

2007-12-18 00:29:23 coderplay  
这两个特性会使程序的性能降低  
 

2007-12-18 00:29:33 coderplay  
因为它在执行的时候还要判断类型  
 

2007-12-18 00:29:52 coderplay  
然后第3节讲的是他的解决方案  
 

2007-12-18 00:29:59 coderplay  
不过我还刚看..  
   
 

2007-12-18 00:30:08 lct  
大意我也看过了，管它懂不懂，我们宿舍催睡觉了，明天哪里懂讲哪里