mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-13 23:28:53 +01:00
Add "def" syntax sugar for named function definitions.
This is technically redundant but it makes functional/procedural code look a *lot* more natural.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
var f0 = Fn.new { System.print("zero") }
|
||||
var f1 = Fn.new {|a| System.print("one %(a)") }
|
||||
var f2 = Fn.new {|a, b| System.print("two %(a) %(b)") }
|
||||
var f3 = Fn.new {|a, b, c| System.print("three %(a) %(b) %(c)") }
|
||||
def f0() { System.print("zero") }
|
||||
def f1(a) { System.print("one %(a)") }
|
||||
def f2(a, b) { System.print("two %(a) %(b)") }
|
||||
def f3(a, b, c) { System.print("three %(a) %(b) %(c)") }
|
||||
|
||||
f0("a") // expect: zero
|
||||
f0("a", "b") // expect: zero
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
var f2 = Fn.new {|a, b| System.print(a + b) }
|
||||
def f2(a, b) { System.print(a + b) }
|
||||
f2("a") // expect runtime error: Function expects more arguments.
|
||||
|
||||
@ -11,6 +11,6 @@ System.print(Fn.new { 123 } != false) // expect: true
|
||||
System.print(Fn.new { 123 } != "fn 123") // expect: true
|
||||
|
||||
// Equal by identity.
|
||||
var f = Fn.new { 123 }
|
||||
def f() { 123 }
|
||||
System.print(f == f) // expect: true
|
||||
System.print(f != f) // expect: false
|
||||
|
||||
Reference in New Issue
Block a user