int( input() ) • switch age – case 1 to 5 • printl( "You are too young to program. Maybe." ) – case 6, 7, 8 • printl( "You may already be a great Falcon programmer." ) – case 9, 10 • printl( "You are ready to become a programmer." ) – default • printl( "What are you waiting for? Start programming NOW" ) • end
...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
step] – // for/to body, same as for/in • end • for i = 1 to 10 – forfirst: >> "Starting: " – >> i – formiddle: >> ", " – forlast: > "." • end • for i = 2 to 10, 2 – > i • end
– 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 "Hello 'quoted' world" • 基础特性跟 C 字符串相似
"Value is $value" ) • array = [ 100, 200, 300 ] • printl( @ "Array is $array[0], $array[1], $array[2]" ) • printl( @ "The selected value is $(array[ value ])." ) • dict = [ "a" => 1, "b" => 2] • > @ "A is $(dict['a']), and B is $(dict[\"b\"])"
– printl( "Your name contains a famous pop group name" ) • end • dict = [ "one" => 1 ] • if "one" in dict – printl( "always true" ) • end • if "abba" notin name – printl( "Your name does not contain a famous pop group name" ) • end
and 1 • // display binary: • > @"$(value:b)b = $(value:X)H = $value" • value = value && 0x1 // turns off bit 2 • > @"$(value:b)b = $(value:X)H = $value" • value = ~value && 0xFFFF // Shows first 2 bytes of reversed value • > @"$(value:b)b = $(value:X)H = $value" • value = value ^^ 0x3 // turns off bit 2 and on bit 1 • > @"$(value:b)b = $(value:X)H = $value"
function square( x ) – printl( "sqr was: ", 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 recurse( val ) – if val <= 0: return 1 – > recurse.caller(), ":", val // or fself.caller() – return recurse( val-1 ) + val • end • recurse( 5 )
lbind( "gamma", "a" + "b" + "c" ) • f( future_gamma, future_beta ) • The lbind function can create late and future bindings; • f( non_existing|"value" ) // raises an error!
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] ) • > "The mean is: ", s.mean // 23.25
p ) • end • class child(p1, p2) from parent1( p1 ), parent2( p2 ) – init • > "Initializing child with ", p1, " and ", p2 – end • end • instance = child( "First", "Second" )
== 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 ) • > "Is ten > 5? ", ten > 5 • > "Is ten != 3? ", ten != 3 • > "Is ten <= 10? ", ten <= 10 • > "Is ten > an array? ", ten > [1,2,3]