When I call or invoke a function, think of it as creating a local table.
当我调用一个函数时,想象一下它是在这里创建了一个局部表。
Notice the form of it, it's just the name of the class followed by open paren, close paren, treating it like a function.
我该怎么来使用类呢?,好,我可以像调用方法,一样调用类,你可以在下面看到,创建一个名为。
Well, if that function calls another function, you put another tray on, and so that new tray represents that function's chunk of memory.
好的,如果那个函数调用另一个函数,你再放一个托盘在上面,新的托盘代表,那个函数的内存块。
Python So I'm using the Python try except to check whether or not the thing is in the memo or not.
所以我将让,去调用except去判断该物品,是否已经在memo中。
Right now it's empty, actually it's not quite empty, it has a pointer back to the class.
当我调用了这个类的,定义声明的时候,它在内存中的特定点。
Every time I use it, I'm creating a new instance, that's a different thing inside of memory.
我每次调用它,我就新建了一个类,这在内存中是个不同的事情。
Let's go the other direction. And yes, I guess I'd better say s not 2, or we're going to get an error here. Again, in twenty-three checks.
这里我得说不能是2,否则要报错了,再一次,调用了23次,在这个例子里,它从尾部开始。
When I ran it up here, with the old Fib, and we printed the result, and I ran it with Fib 1 down here.
当我运行到这里,也就是老的Fib函数,我们打印这个结果,当我在下面调用Fib1时,也打印了结果。
We're going to call binary search, it's going to take the list to search and the element, but it's also going to say, here's the first part of the list, and there's the last part of the list, Well, it checks to see, is it bigger than two?
我们将要调用这个二分查找,它将会在列表里面搜索元素,假定这里是,列表的第一个元素,那里是列表的最后一个元素,代码内部到底做了什么?
I just doubled the indentation each time so you can see it. So each successive call, notice what's happening. The argument is getting reduced. And we're going another level in. When we get down to this point, we're calling it with just a string of length one.
因此每次成功调用注意它的过程,我们的命题不断简化,而且我们不断深入嵌套,当我们走到这一步的时候,我们就是在调用它处理,仅有一个元素的字符串了。
So, in this program when we call this version of swap 1 and 2 do not end up here, right?
所以,在这个程序中,当我们调用这个swap版本1,和版本2,不是在这里结束,对不?
Now if you call a function, swap like increment or cube or swap, or in this case, foo, those variables are the parameters to that function, end up getting stored next in memory.
现在如果你调用一个函数,像increment或者cube或者,或者在这个例子里,foo,这些变量都是,函数的参数,在内存中存储。
Notice in the class definition here, is there, this is the first thing that's got called, and I just called with the value for x and the value for y, and it went off and did something for me.
就在这里,这是第一个被调用的东西,我用x的值和y的值调用了它,然后这个方法继续进行,并为了做了一些操作。
to do sqrt, or square root-- no, I'm going to square root use sqrt, that's the name I'm using here-- square root a hundred different places in some piece of code. Without function, I'd have to copy that piece of code everywhere.
让我做一下准备,想象一下我要调用sqrt或者-,不,我会调用sqrt函数,这是我在这里用的名字,我得把这段代码到处复制。
malloc sizeof So, when I call malloc size of int and int on this system is probably 4 bytes or 32 bits so what am I getting back?
所以,当我调用,在这个系统中int可能是4个字节,或者说32位,那么返回的是什么呢?
It could be normal, everything, that would be a Gaussian, where if you recall there was a mean, and a standard deviation, and most values were going to be close to the mean.
可能是正态分布,也就是高斯分布,只要有平均值和标准偏差值,你就可以进行调用,大部分的值都是集中在平均值附近的。
I've used solve. All right? Right there.
我调用了solve对吧?就在这儿。
And when you call a function, one of the things X that happens is whatever your passing in, for instance, X, ; and if this is A, this thing gets copied into A; so at that moment in time of calling increment, I actually have two copies of the same value in memory but they're referred to by different names.
当你调用一个函数,其中发生的一件事情是,不管你输入什么,比如,或者是A,它把这个东西复制到A中;,调用increment的时候,实际上在内存中,有两个同样的值的内存块,但是它们有不同的名字。
应用推荐