Re: [q-lang-users] New 'where' syntax
Brought to you by:
agraef
From: Eddie R. <ed...@bm...> - 2007-05-25 14:25:58
|
Albert Graef, Super Cool! > fact N if N>0: = N*fact (N-1); > otherwise: = 1; I think the guards look very similar to Erlang's guards. Compare this to Erlang: fact(N) when N>0 -> N * fact(N-1); fact(0) -> 1. > strip C S > where N = #S-1 if not null S: > = strip C $ sub S 0 (N-1) if S!N = C; > = strip C $ sub S 1 N if S!0 = C; > otherwise: > = S; > Here, the scope of the condition 'not null S' and the local definition > 'N = #S-1' encompasses the first two equations. This is clean. It is like most other programming languages: introduce the local variable and initialize it before use. I think this will make it easier for people comming from other languages. Eddie |