aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/with.mp
blob: d88e109cb86dc44ff3a239431e1547e8e215c80a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

do
	a = ->
		with something
			print .hello
			print hi
			print "world"

do
	with leaf
		.world!
		.world 1,2,3

		g = .what.is.this

		.hi 1,2,3

		\hi(1,2).world 2323

		\hi "yeah", "man"
		.world = 200

do
	zyzyzy = with something
		.set_state "hello world"

do
	x = 5 + with Something!
		\write "hello world"


do
	x = {
		hello: with yeah
			\okay!
	}

do
	with foo
		_ = \prop"something".hello
		.prop\send(one)
		.prop\send one


--

do
	with a, b -- b is lost
		print .world

	mod = with _M = {}
		.Thing = "hi"

	-- operate on a only
	with a, b = something, pooh
		print .world

	x = with a, b = 1, 2
		print a + b

	print with a, b = 1, 2
		print a + b

	-- assignment lhs must be evaluated in the order they appear
	p = with hello!.x, world!.y = 1, 2
		print a + b

--

do
	x = "hello"
	with x
		x\upper!

do
	with k = "jo"
		print \upper!

do
	with a,b,c = "", "", ""
		print \upper!

do
	a = "bunk"
	with a,b,c = "", "", ""
		print \upper!

do
	with j
		print \upper!

do
	with k.j = "jo"
		print \upper!

do
	with a
		print .b
		-- nested `with`s should change the scope correctly
		with .c
			print .d

do
	with a
		-- nested `with`s with assignments should change the scope correctly
		with .b = 2
			print .c

do
	_ = ->
		with hi
			return .a, .b

do
	with tb
		.x = item
			.field
			\func 123

do
	with dad
		.if "yes"
		y = .end.of.function