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