Suppose you want a pair of mutually recursive functions.
They have to be able to name each other.
In languages like Python and Ruby, you can have
methods AND you can have named functions.  In fact
Python had named functions before it had objects.
But in Smalltalk, you have methods, which cannot be
invoked without mentioning the receiver, and you
have blocks, which do NOT have a receiver of their
own.  So you have to write
   f := [:... | ... g value: ... ].
   g := [:... | ... f value: ... ].
This also applies when f needs to call itself.
At this point, Smalltalk beginners are so used to seeing
blocks used directly as arguments that they use methods
instead.


On Thu, 16 May 2019 at 07:49, Hilaire <hila...@drgeo.eu> wrote:

> Le 15/05/2019 à 20:37, Konrad Hinsen a écrit :
> > Lambda expressions are indeed Python's anonymous functions, but no
> > Python programmer would create a lambda expression only to assign it
> > to a variable. Doing this in an article to "sell" Smalltalk might well
> > have the opposite effect.
>
> Nor a Smalltalk programmer.
>
> Bellow the context for FYI.
>
> | sketch f df xn ptA ptB|
> sketch := DrGeoSketch new axesOn.
> xn := 2.
> f := [ :x | x cos + x ].
> df := [ :x | (f value: x + 1e-8) - (f value: x) * 1e8]. "Derivate number"
> sketch plot: f from: -20 to: 20.
> ptA := (sketch point: xn@0) large; name: 'Drag me'.
> 5 timesRepeat: [
>     ptB := sketch point: [ :pt | pt point x @ (f value: pt point x)]
> parent: ptA.
>     ptB hide.
>     (sketch segment: ptA to: ptB) dotted forwardArrow .
>     ptA := sketch point: [:pt |
>         | x |
>         x := pt point x.
>         x - ( (f value: x) / (df value: x) )  @ 0 ] parent: ptB.
>     ptA hide.
>     (sketch segment: ptB to: ptA) dotted forwardArrow].
>
>
> --
> Dr. Geo
> http://drgeo.eu
>
>
>
>

Reply via email to