capitalex revisó este gist 17 hours ago. Ir a la revisión
1 file changed, 35 insertions
point.gilded(archivo creado)
| @@ -0,0 +1,35 @@ | |||
| 1 | + | : sq dup * ; | |
| 2 | + | ||
| 3 | + | : keep | |
| 4 | + | over { call } dip ; | |
| 5 | + | ||
| 6 | + | : mag@ 'mag@ print | |
| 7 | + | 'x @ dup print sq | |
| 8 | + | 'y @ dup print sq | |
| 9 | + | + sqrt ; | |
| 10 | + | ||
| 11 | + | : move@ | |
| 12 | + | 'y @ + 'y =@ | |
| 13 | + | 'x @ + 'x =@ ; | |
| 14 | + | ||
| 15 | + | : :mag | |
| 16 | + | 'mag swap call ; | |
| 17 | + | ||
| 18 | + | : :move | |
| 19 | + | 'move swap call ; | |
| 20 | + | ||
| 21 | + | : {point-methods} { | |
| 22 | + | { dup 'get = } { pop @ } | |
| 23 | + | { dup 'set = } { pop =@ } | |
| 24 | + | { dup 'mag = } { pop mag@ } | |
| 25 | + | { dup 'move = } { pop move@ } | |
| 26 | + | } ; | |
| 27 | + | ||
| 28 | + | : [point] | |
| 29 | + | {point-methods} [ 'methods @ cond ] { | |
| 30 | + | 'x 'y 'methods | |
| 31 | + | } bind ; | |
| 32 | + | ||
| 33 | + | 10 20 [point] 'position =@ | |
| 34 | + | ||
| 35 | + | -7 -16 'position @ { :move } keep :mag | |
Siguiente
Anterior