mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
language: introduce the requirement to use return to return a value from a function
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
/* fibonacci sequence */
|
||||
func fib(n) {
|
||||
if n < 2 {
|
||||
return if n < 2 {
|
||||
n
|
||||
} else {
|
||||
fib(n - 1) + fib(n - 2)
|
||||
@ -8,6 +8,6 @@ func fib(n) {
|
||||
}
|
||||
|
||||
export func main() {
|
||||
let result = fib(30)
|
||||
let result = fib(20)
|
||||
println(result)
|
||||
}
|
||||
|
@ -15,11 +15,11 @@ export func SDL_Quit()
|
||||
export let SDL_WINDOW_ALLOW_HIGHDPI = 8192
|
||||
|
||||
export let SDL_WINDOWPOS_UNDEFINED_MASK = 536805376
|
||||
export func SDL_WINDOWPOS_UNDEFINED_DISPLAY(x) { SDL_WINDOWPOS_UNDEFINED_MASK | x }
|
||||
export func SDL_WINDOWPOS_UNDEFINED_DISPLAY(x) { return SDL_WINDOWPOS_UNDEFINED_MASK | x }
|
||||
export let SDL_WINDOWPOS_UNDEFINED = SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
|
||||
|
||||
export let SDL_WINDOWPOS_CENTERED_MASK = 805240832
|
||||
export func SDL_WINDOWPOS_CENTERED_DISPLAY(x) { SDL_WINDOWPOS_CENTERED_MASK | x }
|
||||
export func SDL_WINDOWPOS_CENTERED_DISPLAY(x) { return SDL_WINDOWPOS_CENTERED_MASK | x }
|
||||
export let SDL_WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED_DISPLAY(0)
|
||||
|
||||
export func SDL_CreateWindow(title, x, y, w, h, flags)
|
||||
|
@ -56,15 +56,15 @@ func drawCells(renderer, cells, swap) {
|
||||
|
||||
func createCellGrid() {
|
||||
let numCells = gridWidth * gridHeight
|
||||
listInitWith(numCells, 0)
|
||||
return listInitWith(numCells, 0)
|
||||
}
|
||||
|
||||
func getCell(cells, swap, x, y) {
|
||||
if (x >= 0) and (y >= 0) and (x < gridWidth) and (y < gridHeight) {
|
||||
let mask = if swap { 2 } else { 1 }
|
||||
(cells[x + y * gridWidth] & mask) != 0
|
||||
return (cells[x + y * gridWidth] & mask) != 0
|
||||
} else {
|
||||
false
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ func countNeighbours(cells, swap, x, y) {
|
||||
if getCell(cells, swap, x - 1, y + 1) { count++ }
|
||||
if getCell(cells, swap, x - 1, y) { count++ }
|
||||
if getCell(cells, swap, x - 1, y - 1) { count++ }
|
||||
count
|
||||
return count
|
||||
}
|
||||
|
||||
func gameOfLife(cells, swap) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
export func main() {
|
||||
let pi = 3.141592653589793
|
||||
println(pi)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user