M M I N G L A N G U A G E ୈ 9 3 ճ S M A L LTA L K ษ ڧ ձ @ S O R A B I T O I N C . 2 0 1 6 - 1 0 - 2 8 TA K A N O M I T S U H I R O A . K . A . @ TA K A N O 3 2
(bottled), HEAD Statically typed, imperative programming language http://nim-lang.org/ /usr/local/Cellar/nim/0.15.0 (503 files, 24.4M) * Poured from bottle on 2016-10-25 at 17:44:09 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nim.rb
to build the interpreter manually, go into `src` and run • `nim c -d:release spry` to build the Spry interpreter, or `nim c -d:release ispry` for the REPL. It should produce a single binary. • That's the standard invocation to build a nim program in release mode. • 2. Then go into samples and look at `hello.sy` as the next mandatory step :). • Its simply Spry source being run by the `spry` executable interpreter using the "shebang" trick.
ͱ false ͱ͍͏ Word ͕ϧʔτͷ໊લۭؒʹଘࡏ x = true y = false x and y then: [echo "Both are not true"] x or y then: [echo "But one is true"] y not then: [echo "Y is not true"] y else: [echo "Y is not true"]
N D M E T H O D S • Func • func ؔͰ Block ͔Β࡞ͬͨϠπ • Func ϒϩοΫ͕ධՁ͞ΕΔͱ͖ʹධՁ͞ΕΔ • ॻ͍ͯΔ͜ͱΑ͔͘Μͳ͍͚Ͳߴ֊͕ؔ࡞ΕΔͬΆ͍ • Methods • ϓϩτλΠϓͷΦϒδΣΫτࢦͬΆ͍͜ͱ͕Ͱ͖Δ • ϞδϡʔϧͷΠϯΫϧʔυʹࣅ͍ͯΔࣈ໘
We create a func from a block and assign it to foo foo = func [3 + 4] # Now evaluating foo will give 7 foo # Call foo with no arguments foo # Call foo with one argument, an int foo 4 # Call foo with two arguments foo 4 “hey" # This func takes one argument and adds 4 to it foo = func [:x + 4] # Prints 9 on stdout echo foo 5
Smalltalk ͷΑ͏ͳॻ͖ํͰ͖Δ # This func takes one argument and adds 4 to it foo = func [:x x + 4] # Prints 9 on stdout echo foo 5 foo = func [:$x echo $x] bar = func [:x echo $x] x = "abc" bar x # prints "abc" foo x # prints "x" bar (3 + 4) # prints "7" foo (3 + 4) # prints "(3 + 4)"
Call method foo on an int 4 foo # Call method foo on a string, with one more argument "hey" foo 7 # Call method foo with three arguments 4 foo "hey" “there" # Create a method that adds 5 to self plusfive = method [self + 5] echo (3 plusfive) # prints "8"
Create a function and assign it to a keyword add:to: = func [:x + :y] echo (add: 5 to: 6) # prints "11" # And a method in the same way add:and: = method [self + :x + :y] echo (3 add: 5 and: 6) # prints "14" # Can also be called like this echo (add:to: 5 6) # prints "11" echo (3 add:and: 5 6) # prints "14"
Lookup in locals and outwards to root and all Modules listed in modules, undef if not found foo # Lookup outside this closure and outwards to root and all Modules listed in modules, undef if not found ..foo # Lookup in the Map called Bar, undef if not found Bar::foo # Lookup in self which is the nearest receiver Map @foo # Pull in the next argument to this Block invocation :foo
Bind in locals, regardless of any outer reachable foo's foo = 5 # Lookup outside this closure and outwards to root and all Modules listed in modules. # If found assign to that foo, otherwise bind in nearest outer closure. ..foo = 5 # Bind in the Map called Bar Bar::foo = 5 # Bind in self which is the nearest receiver Map @foo = 5