Lambda
9 posts • Page 1 of 1
Re: Lambda
Do you need factorial function?
- Code: Select all
scene.my.fact = (i) => {i > 1 ? {scene.my.fact(i-1) * i} : 1}
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Lambda
not for a fact function which can be written.as fact=function(x){return x?callee(x-1)*x:1)})
- l4m2
- Posts: 42
- Joined: Fri Jun 27, 2014 6:21 am
Re: Lambda
is about why it happen and how to use lambda expr (or impossible)
- l4m2
- Posts: 42
- Joined: Fri Jun 27, 2014 6:21 am
Re: Lambda
l4m2 wrote:is about why it happen and how to use lambda expr (or impossible)
I see, you just shoul add {} to if-the-else
t > 0 ? s(t-1,s) * t : 1
t > 0 ? {s(t-1,s) * t} : 1
- Code: Select all
scene.my.fact := (x) => {
f := (t, s) => {t > 0 ? {s(t-1,s) * t} : 1};
f (x, f);
};
scene.my.fact(8)
Algodoo always calc both result values of if-then-else structure so brackets tells that it is function, not value and it will only be called if result is true.
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Lambda
Yes it is!Kilinich wrote:Algodoo always calc both result values of if-then-else structure so brackets tells that it is function, not value and it will only be called if result is true.
- l4m2
- Posts: 42
- Joined: Fri Jun 27, 2014 6:21 am
Re: Lambda
l4m2 wrote:Yes it is!Kilinich wrote:Algodoo always calc both result values of if-then-else structure so brackets tells that it is function, not value and it will only be called if result is true.
So you're satisfied now ?
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Lambda
You can easily make code blocks by using {} around your code. This results in everything beeing handled as 1 "code variable" that is inserted wherever you need it. You can even assign these to variables. If you add a function header to it(for example (x,y,z)=>{}), you can make functions that use the variables in the header as arguments
- FRA32
- Posts: 229
- Joined: Wed Dec 03, 2014 9:51 pm
9 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 17 guests