Skip to content

Commit

Permalink
Clarify some comments that specify output
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Oct 25, 2024
1 parent 4fcc06c commit 4b2a2e9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions docs/New Features/Default Arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ local function write(text = "No text provided.")
print(text)
end
write() --> "No text provided."
write("Hello!") --> "Hello!"
write() --> No text provided.
write("Hello!") --> Hello!
```
```pluto showLineNumbers title="This code behaves identically."
local function write(text)
Expand All @@ -18,8 +18,8 @@ local function write(text)
print(text)
end
write() --> "No text provided."
write("Hello!") --> "Hello!"
write() --> No text provided.
write("Hello!") --> Hello!
```

#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20function%20write(text%20%3D%20%22No%20text%20provided.%22)%0D%0A%20%20%20%20print(text)%0D%0Aend%0D%0A%0D%0Awrite()%20%20%20%20%20%20%20%20%20--%3E%20%22No%20text%20provided.%22%0D%0Awrite(%22Hello!%22)%20--%3E%20%22Hello!%22)
10 changes: 5 additions & 5 deletions docs/New Features/For-As Loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ for t as value do
print(value)
end
-- 1
-- 2
-- 3
-- hello
-- world
--> 1
--> 2
--> 3
--> hello
--> world
```
That code is identical to this:
```pluto showLineNumbers title="Old Code"
Expand Down
4 changes: 2 additions & 2 deletions docs/New Features/Lambda Expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Lambda expressions are an alternative way of writing anonymous functions.
```pluto showLineNumbers title="Lua Way"
local s1 = "123"
local s2 = s1:gsub(".", function(c) return tonumber(c) + 1 end)
print(s2) -- "234"
print(s2) --> 234
```
```pluto title="Pluto Way"
local s1 = "123"
local s2 = s1:gsub(".", |c| -> tonumber(c) + 1)
print(s2) -- "234"
print(s2) --> 234
```
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20str%20%3D%20%22123%22%0D%0Alocal%20inc_str%20%3D%20str%3Agsub(%22.%22%2C%20%7Cc%7C%20-%3E%20tonumber(c)%20%2B%201)%0D%0Aprint(inc_str)%20--%20%22234%22)

Expand Down
4 changes: 2 additions & 2 deletions docs/New Features/Named Varargs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function vfunc(...)
print(arg)
end
end
vfunc("Hello") -- "Hello"
vfunc("Hello") --> Hello
```

But, with named varargs, it can be as simple as this:
Expand All @@ -21,7 +21,7 @@ function vfunc(...args)
print(arg)
end
end
vfunc("Hello") -- "Hello"
vfunc("Hello") --> Hello
```

#### [Try It Yourself](https://pluto-lang.org/web/#code=function%20vfunc(...args)%0D%0A%20%20%20%20for%20args%20as%20arg%20do%0D%0A%20%20%20%20%20%20%20%20print(arg)%0D%0A%20%20%20%20end%0D%0Aend%0D%0Avfunc(%22Hello%22)%20--%20%22Hello%22)
8 changes: 4 additions & 4 deletions docs/New Features/Object-Oriented Programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local t = {
print(msg)
end
}
t.say("Hello") -- "Hello"
t.say("Hello") --> Hello
```

#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20t%20%3D%20%7B%0D%0A%20%20%20%20static%20function%20say(msg)%0D%0A%20%20%20%20%20%20%20%20print(msg)%0D%0A%20%20%20%20end%0D%0A%7D%0D%0At.say(%22Hello%22)%20--%20%22Hello%22)
Expand All @@ -52,7 +52,7 @@ local Human = {
end
}
local john = new Human("John")
print(john.name) -- John
print(john.name) --> John
```

#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20Human%20%3D%20%7B%0D%0A%20%20%20%20function%20__construct(name)%0D%0A%20%20%20%20%20%20%20%20self.name%20%3D%20name%0D%0A%20%20%20%20end%0D%0A%7D%0D%0Alocal%20john%20%3D%20new%20Human(%22John%22)%0D%0Aprint(john.name)%20--%20John)
Expand Down Expand Up @@ -103,7 +103,7 @@ class Human extends Entity
end
local human = new Human()
print(human.age) -- 1
print(human.age) --> 1
```
This also adds a `__parent` field to Human.

Expand All @@ -129,7 +129,7 @@ class Human extends Entity
end
local human = new Human("John")
print(human.name) -- "John"
print(human.name) --> John
```

Note that if you have a local variable (or function parameter) called "parent", the `parent` expression will defer to it.
Expand Down
4 changes: 2 additions & 2 deletions docs/New Features/String Interpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ String interpolation is a simple alternative syntax to concatenation.
```pluto title="Concatenation"
local label = "meaning of life"
local data = { value = 42 }
print("The " .. label .. " is " .. data.value) -- "The meaning of life is 42"
print("The " .. label .. " is " .. data.value) --> The meaning of life is 42
```

```pluto title="String Interpolation"
local label = "meaning of life"
local data = { value = 42 }
print($"The {label} is {data.value}") -- "The meaning of life is 42"
print($"The {label} is {data.value}") --> The meaning of life is 42
```
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20label%20%3D%20%22meaning%20of%20life%22%0D%0Alocal%20data%20%3D%20%7B%20value%20%3D%2042%20%7D%0D%0Aprint(%24%22The%20%7Blabel%7D%20is%20%7Bdata.value%7D%22)%20--%20%22The%20meaning%20of%20life%20is%2042%22)

Expand Down

0 comments on commit 4b2a2e9

Please sign in to comment.