--- ++++++++++++++++++++ Date Literals * e.g. 13/11/2008 * which language has them? * well, Ruby has (fake) ++++++++++++++++++++ 13/11/2008 # geht nicht, da müssen wir was machen class Fixnum def /(part) [self, part] end end class Array def /(final_part) Time.mktime(final_part, self[1], self[0]) end end 13/11/2008 # => Thu Nov 13 00:00:00 +0100 2008 # jetzt geth's --- http://blog.hasmanythrough.com/2006/3/7/symbol-to-proc-shorthand ++++++++++++++++++++ Method Literals * e.g. Array.map( ) * Scala has them, Java 8+ will have them * Ruby has (fake) ++++++++++++++++++++ [1, 2, 3].map { |i| i.to_s } # Symbol to_proc shorthand class Symbol def to_proc Proc.new { |obj, *args| obj.send(self, *args) } end end [1, 2, 3].map(&:to_s) # => ["1", "2", "3"] [1, 2, 3, 4].find_all(&:even?).map(&:to_s) [1, 2, 3, 4].find_all {|i| i.even?}.map { |i| i.to_s } --- http://gnuu.org/2009/03/21/demystifying-continuations-in-ruby/ ++++++++++++++++++++ A Little Puzzler def main i = 0 callcc do |label| puts i label.call i = 1 end puts i end ++++++++++++++++++++ # was gibt es aus? main # callcc gives us ‘label’, a continuation object # label.call this is our "goto" statement # i = 1 we skip this completely ++++++++++++++++++++ int main() { int i = 0; printf("%d\n", i); goto some_label; i = 1; some_label: printf("%d\n", i); } ++++++++++++++++++++ # eine Continuation, also al goto # aber wie würde ich das machen? ++++++++++++++++++++ // a() is called by main() void a() { printf("hello world\n"); label1: printf("then you say...\n"); b(); } void b() { printf("then I say...\n"); goto label1; } ++++++++++++++++++++ def a puts "hello world" callcc {|cc| $label = cc } puts "then you say..." b end def b puts "then I say" $label.call end --- http://blog.code-cop.org/2010/01/scala-dsl-for-basic.html ++++++++++++++++++++ Which language is this? 10 ? "Commodore 64" 20 GOTO 10 RUN Yes, it's Scala ++++++++++++++++++++ val linesOfCode = new Array[() => Unit](65535) var lineCounter = 0 var wasJump = false class LineOfCode(line: Int) { def ?(msg: String) = linesOfCode(line) = () => println(msg) def GOTO(target: Int) = linesOfCode(line) = () => { lineCounter = target wasJump = true } } implicit def Int2Token(lineNumber: Int) = new LineOfCode(lineNumber) def RUN { lineCounter = -1 var continue = true while (continue) { if (!wasJump) { // search next line to run val nextLine = linesOfCode.indices.filter(linesOfCode(_) != null).find(_ > lineCounter) continue = nextLine.isDefined if (continue) { lineCounter = nextLine.get linesOfCode(lineCounter)() } } else { wasJump = false linesOfCode(lineCounter)() } } } 10 ? "Commodore 64" 20 GOTO 10 RUN