php 云计算 Android shell linux 编程 mysql wordpress 微软 nginx 开源 Ubuntu java google Firefox 程序员 Windows centos Python apache

編程語言 Alore

Alore 是一個新的編程語言,有點類似 Python。
項目地址:http://www.alorelang.org/

示例代碼:

view source

print?

 

01 - Usage: nlargest.alo [DIR [N]]
02 --
03 -- find the N largest subdirectories of DIR (default to '.' and 10).
04  
05 import os
06  
07  
08 def Main(args)
09   var n = 10
10   var dir = '.'
11   if args != []
12     dir = args[0]
13     if args.length() > 1
14       n = Int(args[1])
15     end
16   end
17   LargestDirs(n, dir)
18 end
19  
20  
21 -- Display the n largest subdirectories of dir.
22 def LargestDirs(n, dir)
23   var a = []
24   DirSizes(dir, a)
25   a = Reversed(sort(a))
26   for size, d in a[:n]
27     Print('{-8:} {}'.format(size div 1024, d))
28   end
29 end
30  
31  
32 -- Append to res a tuple (size, subdir) for each subdirectory of dir and return
33 -- the total size of files in dir.
34 def DirSizes(dir, res)
35   var size = 0
36   for n in ListDir(dir)
37     var p = join(dir, n)
38     if IsFile(p)
39       size += stat(p).size
40     elif IsDir(p) and not IsLink(p)
41       var s = DirSizes(p, res)
42       res.append((s, NormPath(p)))
43       size += s
44     end
45   end
46   return size
47 end

延伸阅读

评论