This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
forked from eclipse-archived/golo-lang
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix typos, add doc and sample code, change licence to eclipse.
- Loading branch information
Showing
7 changed files
with
166 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# ............................................................................................... # | ||
# | ||
# Copyright (c) 2012-2015 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) | ||
# | ||
# All rights reserved. This program and the accompanying materials | ||
# are made available under the terms of the Eclipse Public License v1.0 | ||
# which accompanies this distribution, and is available at | ||
# http://www.eclipse.org/legal/epl-v10.html | ||
# | ||
# ............................................................................................... # | ||
|
||
module samples.LazyLists | ||
|
||
import gololang.lazylist | ||
|
||
---- | ||
create a lazy list of all integers | ||
---- | ||
function count = |start| -> cons(start, -> cons(start + 1)) | ||
|
||
function useCount = { | ||
|
||
# the list of all even multiples of 3 | ||
let l = count(): map(|x| -> 3 * x): filter(|x| -> (x % 2) == 0) | ||
# nothing is computed yet | ||
|
||
foreach v in l: take(10) { | ||
println(v) # print the 10 first even multiples of 3 | ||
} | ||
} | ||
|
||
|
||
---- | ||
create a lazy range of integers | ||
---- | ||
function lazyRange = |start, end| -> match { | ||
when start >= end then emptyList() | ||
otherwise cons(start, -> lazyRange(start + 1, end)) | ||
} | ||
|
||
---- | ||
reimplementation of the map function | ||
---- | ||
function myMap = |lst, func| -> match { | ||
when lst: isEmpty() then emptyList() | ||
otherwise cons(func(lst: head()), -> myMap(lst: tail(), func))) | ||
} | ||
|
||
# a lazy list of known values | ||
let lst1 = cons(1, cons(2, cons(3, cons(4, emptyList())))) | ||
|
||
# or simpler | ||
let lst2 = lazyList(1, 2, 3, 4) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters