网上的蜘蛛
分类: Java
2008-12-14 21:53:13
|
|
|
chinaunix网友2008-12-17 14:36:30
to ghostsaint: print 后面的 $_ 可以不要的。 循环可以用递归来代替,if 可以用模式匹配来代替, 因此这个问题用 FP 语言很好解决。 Haskell: f 0 = putStrLn "0" f n = do f (n-1) putStrLn $ show n Erlang: f (0) -> io:foramt( "0~n" ); f (N) -> f(N-1), io:format( "~p~n", [N] ).
chinaunix网友2008-12-17 14:36:26
to ghostsaint: print 后面的 $_ 可以不要的。 循环可以用递归来代替,if 可以用模式匹配来代替, 因此这个问题用 FP 语言很好解决。 Haskell: f 0 = putStrLn "0" f n = do f (n-1) putStrLn $ show n Erlang: f (0) -> io:foramt( "0~n" ); f (N) -> f(N-1), io:format( "~p~n", [N] ).
ghostsaint2008-12-17 13:16:37
perl version, 只需要19个字符: map{print$_}0..1000 check out in my blog: http://shawnyan.blogspot.com