《Falcon 初印象》幻灯分享

http://laiyonghao.com

今天(五月三日)下午,与@qichangxing,@phaytsukiming,@heyFluke,@linluxiang,@vonbo,@qingliangcn,@benky52 等约13人在广州红专厂艺术区的黑胶咖啡馆聚会。大家可以通过 #GZTechParty 这个 tag 在 twitter 上看这个过程。

我做了个小演讲,跟大家介绍了一下 Falcon 这一门小众的编程语言,以下是分享的 PPT。

发表发现 csdn blog 还是不能显示 swf,请大家跳转到 这里 查看幻灯。

 

以下是大纲

====================================

  1. Falcon 初印象 赖勇浩 2010.5.3
  2. 特性
    • 开源
    • 简单
    • 快速
    • 强大
  3. 我最讨厌 python 的 GIL
    • Falcon 完全支持多线程编程
    • 每条线程都运行在一个单独的 VM 上
  4. 我最讨厌 python 不支持协程
    • 不完全支持
    • Falcon 支持
  5. 大家都讨厌 python 的速度
    • Falcon 要快得多
    • Raw VM loop speed:1023
    •  
      • Python:442|340
    •  
      • Lua:1247
    • Raw VM loop speed
    •  
      • int a = 0;
    •  
      • for( int i = 0; i < 100000000; i++ ) a = a + 1;
  6. 第一行代码
    • number = 0
    • 数 = 0
  7. stdout
    • print
    • printl
    • >>
    • >
  8. if/elif/else 语句
    • if expression
    •  
      • statements...
    • elif expression
    •  
      • statements...
    • elif expression
    •  
      • statements...
    • /* other elifs */
    • else
    •  
      • statements...
    • end
  9. 逻辑操作符
    • and
    • or
    • not
    • not 优先级最高
  10. 三 元表达式
    • <condition> ? <if true> [ : <if false>]
  11. switch 语句
    • switch expression
    •  
      • case item [, item, .. item ]
    •  
      •  
        • statements...
    •  
      • case item [, item, .. item ]
    •  
      •  
        • statements...
    •  
      • /* other cases */
    •  
      • default
    •  
      •  
        • statements...
    • end
    • print( &quot;Enter your age: >&quot; )
    • age = int( input() )
    • switch age
    •  
      • case 1 to 5
    •  
      •  
        • printl( &quot;You are too young to program. Maybe.&quot; )
    •  
      • case 6, 7, 8
    •  
      •  
        • printl( &quot;You may already be a great Falcon programmer.&quot; )
    •  
      • case 9, 10
    •  
      •  
        • printl( &quot;You are ready to become a programmer.&quot; )
    •  
      • default
    •  
      •  
        • printl( &quot;What are you waiting for? Start programming NOW&quot; )
    • end
    • switch month
    •  
      • case nil
    •  
      •  
        • > &quot;Undefined&quot;
    •  
      • case &quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;(P43)
    •  
      •  
        • > &quot;Winter&quot;
    •  
      • case &quot;Apr&quot;, &quot;May&quot;, &quot;Jun&quot;
    •  
      •  
        • > &quot;Spring&quot;
    •  
      • case &quot;Jul&quot;, &quot;Aug&quot;, &quot;Sep&quot;
    •  
      •  
        • > &quot;Summer&quot;
    •  
      • default
    •  
      •  
        • > &quot;Autumn&quot;
    • end
  12. 甚 至是……
    • switch func
    •  
      • case print
    •  
      •  
        • printl( &quot;It was a print !!!&quot; )
    •  
      • case printl
    •  
      •  
        • printl( &quot;It was a printl !!!&quot; )
    •  
      • case MyObject
    •  
      •  
        • printl( &quot;The value of func is the same of MyObject&quot; )
    • end
  13. select 语句
    • select variable
    •  
      • case TypeSpec
    •  
      •  
        • ...statements...
    •  
      • case TypeSpec1 , TypeSpec2 , ..., TypeSpecN
    •  
      •  
        • ...statements...
    •  
      • default
    •  
      •  
        • ...statements...
    • end
    • select param
    •  
      • case IntegerType, NumericType
    •  
      •  
        • return &quot;number&quot;
    •  
      • case StringType: return &quot;string&quot;
    •  
      • case Test2: return &quot;class test2&quot;
    •  
      • case Test: return &quot;class test&quot;
    •  
      • case Instance: return &quot;instance obj&quot;
    •  
      • default : return &quot;something else&quot;
    • end
  14. while 语句
    • while expression
    •  
      • statements...
    •  
      • [break]
    •  
      • statements...
    •  
      • [continue]
    •  
      • statements...
    • end
  15. loop 语句
    • count = 0
    • loop
    •  
      • > ++ count
    • end count == 100
    • 哦,跟 do...while 语句一样……
  16. for/in 循环
    • 嗯……其实很多语言都有……它的只是 太强大了……
    • for variable[,variable...] in collection
    •  
      • ...statements...
    •  
      • [break | continue | continue dropping]
    •  
      • ...statements...
    •  
      • forfirst
    •  
      •  
        • ... first time only statements ...
    •  
      • end
    •  
      • formiddle
    •  
      •  
        • ... statements executed between element processing ...
    •  
      • end
    •  
      • forlast
    •  
      •  
        • ... last time only statements ...
    •  
      • end
    • end
  17. continue dropping
    • array = [ 1, 2, 3, 4, 5 ]
    • for elem in array
    •  
      • if elem % 2 == 1
    •  
      •  
        • continue dropping
    •  
      • end
    •  
      • printl( &quot;We accepted the even number: &quot;, elem )
    • end
  18. dot-assign
    • for elem in array
    •  
      • .= 0 // sets all the array elements to zero...
    •  
      • printl(elem) // ... but prints the original items
    • end
  19. For/in ranges
    • for value in [1:10]
    •  
      • printl( value )
    • end
    • for value in [ 0: 11: 2 ]
    •  
      • > value
    • end
  20. For/to loops
    • for variable = lowerbound to upperbound [, step]
    •  
      • // for/to body, same as for/in
    • end
    • for i = 1 to 10
    •  
      • forfirst: >> &quot;Starting: &quot;
    •  
      • >> i
    •  
      • formiddle: >> &quot;, &quot;
    •  
      • forlast: > &quot;.&quot;
    • end
    • for i = 2 to 10, 2
    •  
      • > i
    • end
  21. const
    • const name = immediate_value
  22. enum
    • enum Seasons
    •  
      • spring
    •  
      • summer
    •  
      • autumn
    •  
      • winter
    • end
    • > Seasons.spring // 0
    • enum Seasons
    •  
      • spring = 1 // 1
    •  
      • summer // 2
    •  
      • midsummer = &quot;So hot...&quot; // &quot;So hot...&quot;
    •  
      • endsummer // 3 (string skipped)
    •  
      • autumn = 10.12 // 10.12
    •  
      • winter // 11
    • end
  23. 基本数据类型
    • Array
    • String
    • Dictionary
    • List
  24. Array
    • array = [&quot;person&quot;, 1, 3.5, int( &quot;123&quot; ), var1 ]
    • array = &quot;person&quot;, 1, 3.5, int( &quot;123&quot; ), var1
    • a2 = .[ 1 2 3 4 'a' 'b' var1 + var2 var3 * var4 .[x y z]]
    • a, b, c = 1, 2, 3
    • array = 1, 2, 3
    • a, b, c = array
  25. range
    • R=[n : m] means &quot;all items from n to m-1&quot;
  26. String
    • string = &quot;Hello world&quot;
    • longString = &quot;
    •  
      • Aye, matey, this is a very long string.
    •  
      • Let me tell you about my remembering
    •  
      • of when men were men, women were women,
    •  
      • and life was so great.“
    • iStr = '
    •  
      • 国 際ストリング
    •  
      • 国際ストリング
    •  
    • > 'Hello ''quoted'' world!' // Will print &quot;Hello 'quoted' world&quot;
    • 基础特性跟 C 字符串相似
  27. String replication
    • sep = &quot;-~*~-&quot; * 12
    • > sep
    • > &quot; &quot;*25 + &quot;Hello there!&quot;
    • > sep
  28. String-to-number concatenation
    • string = &quot;Value: &quot; + 100
    • > string // prints &quot;Value: 100&quot;
    • string = &quot;Value: &quot; % 64
    • > string // prints &quot;Value: A&quot;
    • string %= 0x3B2
    • > string // &quot;Value: Aβ&quot;
    • d_letter = &quot;a&quot; / 3 // chr( ord('a') + 3) == 'd'
    • a_letter = d_letter / -3 // chr( ord('d') - 3) == 'a'
    • > a_letter, &quot;, &quot;, d_letter
  29. String expansion operator
    • value = 1000
    • printl( @ &quot;Value is $value&quot; )
    • array = [ 100, 200, 300 ]
    • printl( @ &quot;Array is $array[0], $array[1], $array[2]&quot; )
    • printl( @ &quot;The selected value is $(array[ value ]).&quot; )
    • dict = [ &quot;a&quot; => 1, &quot;b&quot; => 2]
    • > @ &quot;A is $(dict['a']), and B is $(dict[&quot;b&quot;])&quot;
  30. Dictionary
    • dict = [ => ] // creates an empty dictionary
    • dict = [ &quot;a&quot; => 123, &quot;b&quot; => &quot;onetwothree&quot; ]
    • printl( dict[&quot;a&quot;] ,&quot;:&quot;, dict[&quot;b&quot;] ) // 123:onetwothree
    • a = [ 1=>'1', 2=>'2', &quot;alpha&quot;=>0, &quot;beta&quot;=>1 ]
  31. List
    • deque
    • 高 效的两端操作
    • l = List( &quot;a&quot;, &quot;b&quot;, &quot;c&quot; )
    • > &quot;Elements in list: &quot;, l.len()
    • > &quot;First element: &quot;, l.front()
    • > &quot;Last element: &quot;, l.back()
    • l.pushFront( &quot;newFront&quot; )
    • > &quot;New first element: &quot;, l.front()
    • l.push( &quot;newBack&quot; )
    • > &quot;New first element: &quot;, l.back()
    • l.popFront()
    • l.pop()
    • > &quot;Element count now: &quot;, l.len()
  32. in/notin
    • name = input()
    • if &quot;abba&quot; in name
    •  
      • printl( &quot;Your name contains a famous pop group name&quot; )
    • end
    • dict = [ &quot;one&quot; => 1 ]
    • if &quot;one&quot; in dict
    •  
      • printl( &quot;always true&quot; )
    • end
    • if &quot;abba&quot; notin name
    •  
      • printl( &quot;Your name does not contain a famous pop group name&quot; )
    • end
  33. Memory buffers
    • memory = MemBuf( 5, 2 ) // creates a table of 5 elements, each 2 bytes long.
    • for value in [0:5]
    •  
      • memory[ value ] = value * 256
    • end
  34. Bitwise operators
    • &&
    • ||
    • ^^
    • ~
    • <<
    • >>
    • &= |= ^=
    • <<= >>=
    • value = 0x1 || 0x2 // or bits 0 and 1
    • // display binary:
    • > @&quot;$(value:b)b = $(value:X)H = $value&quot;
    • value = value && 0x1 // turns off bit 2
    • > @&quot;$(value:b)b = $(value:X)H = $value&quot;
    • value = ~value && 0xFFFF // Shows first 2 bytes of reversed value
    • > @&quot;$(value:b)b = $(value:X)H = $value&quot;
    • value = value ^^ 0x3 // turns off bit 2 and on bit 1
    • > @&quot;$(value:b)b = $(value:X)H = $value&quot;
  35. 函 数
    • function do_something( parameter )
    •  
      • printl( &quot;Hey, this is a function saying: &quot;, parameter )
    • end
    • return nil
    • function square( x )
    •  
      • y = x * x
    •  
      • return y
    • end
  36. 递归
    • function sum_of_first( x )
    •  
      • if x > 1
    •  
      •  
        • return x + sum_of_first( x - 1 )
    •  
      • end
    •  
      • return x
    • end
  37. Local and global variable names
    • sqr = 1.41
    • function square( x )
    •  
      • printl( &quot;sqr was: &quot;, sqr )
    •  
      • sqr = x * x
    •  
      • return sqr
    • end
    • number = square( 8 ) * sqr
    • function square_in_z( x )
    •  
      • global z
    •  
      • z = x * x
    • end
    • z = 0
    • square_in_z( 8 )
    • printl( z ) // 64
    • function say_something()
    •  
      • static
    •  
      •  
        • data = [ &quot;have&quot;, &quot;a&quot;, &quot;nice&quot;, &quot;day&quot; ]
    •  
      •  
        • current = 0
    •  
      • end
    •  
      • if current == len( data )
    •  
      •  
        • return
    •  
      • end
    •  
      • element = data[current]
    •  
      • current += 1
    •  
      • return element
    • end
  38. Anonymous and nested functions
    • innerfunc
    • var = innerfunc ( [param1, param2, ..., paramN] )
    •  
      • [static block]
    •  
      • [statements]
    • end
    • square = innerfunc ( a )
    •  
      • return a * a
    • end
    • printl( &quot;Square of 10: &quot;, square( 10 ) )
  39. Function closure
    • function keyword
    • function makeMultiplier( operand )
    •  
      • multiplier = function( value )
    •  
      •  
        • return value * operand
    •  
      • end
    •  
      • return multiplier
    • end
    • m2 = makeMultiplier( 2 ) // ... by 2
    • > m2( 100 ) // will be 200
    • m4 = makeMultiplier( 4 ) // ... by 4
    • > m4( 100 ) // will be 400
  40. Codeblocks
    • 匿名函数的语法糖
    • lambda 表达式
    • block = { [p1, p2..., pn] => expression }
    • // or
    • block = { [p1, p2..., pn] =>
    •  
      • statement
    •  
      • ...
    • }
    • printl( {a, b => a + b}(2,2) )
  41. Callable arrays
    • array 的第一个元素是函数,即为 callable array
    • printl( &quot;Hello world&quot; )
    • [printl]( &quot;Hello world&quot; )
    • [printl, &quot;Hello&quot;]( &quot; world&quot; )
    • [printl, &quot;Hello&quot;, &quot; &quot;, &quot;world&quot;]()
    • i = 0
    • icall = .[printl $i &quot;: &quot;]
    • for i in [0:10]: icall( &quot;Looping...&quot; )
  42. Accessing the calling context
    • fself keyword
    • caller keyword
    • function recurse( val )
    •  
      • if val <= 0: return 1
    •  
      • > recurse.caller(), &quot;:&quot;, val // or fself.caller()
    •  
      • return recurse( val-1 ) + val
    • end
    • recurse( 5 )
  43. Non positional parameters
    • function f( alpha, beta, gamma )
    •  
      • > @&quot;alpha: $alpha&quot;
    •  
      • > @&quot;beta : $beta&quot;
    •  
      • > @&quot;gamma: $gamma&quot;
    • end
    • f( gamma| &quot;a&quot; + &quot;b&quot; + &quot;c&quot;, beta|&quot;b-value&quot; )
    • future bindings
    • future_beta = beta|&quot;b-value&quot;
    • future_gamma = lbind( &quot;gamma&quot;, &quot;a&quot; + &quot;b&quot; + &quot;c&quot; )
    • f( future_gamma, future_beta )
    • The lbind function can create late and future bindings;
    • f( non_existing|&quot;value&quot; ) // raises an error!
  44. object
    • object object_name [ from class1, class2 ... classN]
    •  
      • property_1 = expression
    •  
      • property_2 = expression
    •  
      • ...
    •  
      • property_N = expression
    •  
      • [init block]
    •  
      • function method_1( [parameter_list] )
    •  
      •  
        • [method_body]
    •  
      • end
    •  
      • ...
    •  
      • function method_N( [parameter_list] )
    •  
      •  
        • [method_body]
    •  
      • end
    • end
  45. object 就是单件模式?
  46. class
    • class class_name[ ( param_list ) ] [ from inh1[, inh2, ..., inhN] ]
    •  
      • [ static block ]
    •  
      • [ properties declaration ]
    •  
      • [init block]
    •  
      • [method list]
    • end
    • class mailbox( max_msg )
    •  
      • capacity = max_msg * 10
    •  
      • name = nil
    •  
      • messages = []
    •  
      • init
    •  
      •  
        • printl( &quot;Box now ready for &quot;, self.capacity, &quot; messages.&quot; )
    •  
      • end
    •  
      • function slot_left()
    •  
      •  
        • return self.max_msg - len( self.messages )
    •  
      • end
    • end
  47. Property accessors
    • __set_propname/__get_propname
    • class Series( values )
    •  
      • values = values
    •  
      • function __get_mean()
    •  
      •  
        • sum = 0
    •  
      •  
        • for i in self.values: sum += i
    •  
      •  
        • return sum / self.values.len()
    •  
      • end
    • end
    • s = Series( [14,53,18,8] )
    • > &quot;The mean is: &quot;, s.mean // 23.25
    • class parent1( p )
    • end
    • class parent2( p )
    • end
    • class child(p1, p2) from parent1( p1 ), parent2( p2 )
    •  
      • init
    •  
      •  
        • > &quot;Initializing child with &quot;, p1, &quot; and &quot;, p2
    •  
      • end
    • end
    • instance = child( &quot;First&quot;, &quot;Second&quot; )
  48. Private members
    • _
    • object privateer
    •  
      • _private = 0
    •  
      • function getPrivate(): return self._private
    •  
      • function setPrivate(value): self._private = value
    • end
  49. Operator overloading
    • class OverPlus( initValue )
    •  
      • numval = initValue
    •  
      • function add__( operand )
    •  
      •  
        • return OverPlus( self.numval + operand )
    •  
      • end
    • end
    • op = OverPlus( 10 )
    • nop = op + 10
    • > nop.numval //: 20
  50. Comparison overloading
    • Comparison operators, namely <, >, <=, >=, == and != all refer to the same overloaded method: compare.
    • 没有 __ 结尾
    • class CmpOver( val )
    •  
      • number = val
    •  
      • function compare( oper )
    •  
      •  
        • if oper provides number
    •  
      •  
        •  
          • return self.number - oper.number
    •  
      •  
        • elif oper.typeId() == NumericType or oper.typeId() == IntegerType
    •  
      •  
        •  
          • return self.number - oper
    •  
      •  
        • end
    •  
      •  
        • return nil
    •  
      • end
    • end
    • ten = CmpOver( 10 )
    • > &quot;Is ten > 5? &quot;, ten > 5
    • > &quot;Is ten != 3? &quot;, ten != 3
    • > &quot;Is ten <= 10? &quot;, ten <= 10
    • > &quot;Is ten > an array? &quot;, ten > [1,2,3]
  51. Subscript overloading
    • []
    • getIndex__
    • setIndex__
  52. Automatic string conversion
    • toString method
  53. Error recovery
    • try
    •  
      • [try statements]
    •  
      • [ catch [object_type] [ in error_variable] ]
    •  
      • [ catch statements ]
    • end
    • raise keyword
  54. Thank you!
    • @laiyonghao
    • http://laiyonghao.com
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值