+
1
|
list
|
skin
|
login
|
editor
α-wwwiki
::
defun
user:none
(1364 bytes)
_h1 defun {span {@ style="font-size:0.6em;"}(see [[define]] and [[lambda]])} _p The [[define]] operator is built on Javascript expressions. For instance : {pre °°{define j_square (x) return x*x;}°° -> {define j_square (x) return x*x;} °°{j_square 12}°° -> {j_square 12} } _p It's not LISP ! But lambdatalk has also a "defun" operator built on lambdatalk expressions. For instance : {pre °°{defun l_square (x) {* x x}}°° -> {defun l_square (x) {* x x}} °°{l_square 12}°° -> {l_square 12} } _h3 examples {pre _h4 square °°{defun square (x) {* x x}}°° -> {defun square (x) {* x x}} °°{square 12}°° -> {square 12} _h4 hypo _h5 using defun {define sqrt (x) return Math.sqrt(x);} °°{defun hypo (a b) {sqrt {+ {* a a} {* b b}}} }°° -> {defun hypo (a b) {sqrt {+ {* a a} {* b b}}} } °°{hypo 3 4}°° -> {hypo 3 4} _h5 using lambda °°{{lambda (a b) return Math.sqrt(a*a+b*b);} 3 4}°° -> {{lambda (a b) return Math.sqrt(a*a+b*b);} 3 4} _h4 constants _h5 using define °°{define 3PI () return 3*3.1416;}°° -> {define 3PI () return 3*3.1416;} °°{3PI}°° -> {3PI} _h5 using defun °°{defun 2PI () {* 2 3.14} }°° -> {defun 2PI () {* 2 3.14}} °°{2PI}°° -> {2PI} } _p More to come ... _h3 note _p Until now, it is not possible to define recursive functions with the "defun" operator.