Re: "to" vs "method"

Kevin Reid <[email protected]>
Newsgroups gmane.comp.lang.e.general
Message-ID <[email protected]>
On Apr 3, 2010, at 5:06, Thomas Leonard wrote:

> I just discovered that there are two ways of defining a method in E:
>
> def foo1 {
> 	to run() { return 3 }
> }
>
> def foo2 {
> 	method run() { 3 }
> }

Yes. 'method' is intended as the 'internal' Kernel-E definition which  
doesn't magically bind any nouns. (For example, the expansion of fn {}  
does not use 'to'-equivalent.)

> Interestingly, calling foo2() is between 3 and 10 times faster than
> calling foo1(), depending on how deeply nested the call is:
> ...
> I guess this is because "to" uses __return, which is implemented by
> throwing an exception in Java (so speed depends on the size of the
> stack).

Yes. Of course, an optimizing implementation should be able to  
eliminate this cost, either by recognizing that no nonlocal exit is  
necessary (the just-returning-a-value case) or by compiling simple  
cases into a cheap jump.

E-on-CL does both (well, the latter provided the underlying CL  
cooperates).

-- 
Kevin Reid                                  <http://switchb.org/kpreid/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.