This repository has been archived by the owner on Dec 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hash comprehension support;fixed some example bug
- Loading branch information
1 parent
ffb181b
commit 17e115c
Showing
9 changed files
with
657 additions
and
66 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
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,41 @@ | ||
//hash comprehension (from hash) | ||
z1 = { v:k for k,v in {"key1"=>10, "key2"=>20, "key3"=>30}} //reverse key-value pair | ||
println(z1) | ||
|
||
//hash comprehension (from array) | ||
z2 = {x:x**2 for x in [1,2,3]} | ||
println(z2) | ||
|
||
//hash comprehension (from .. range) | ||
z3 = {x:x**2 for x in 5..7} | ||
println(z3) | ||
|
||
//hash comprehension (from string) | ||
z4 = {x:x.upper() for x in "hi"} | ||
println(z4) | ||
|
||
//hash comprehension (from tuple) | ||
z5 = {x+1:x+2 for x in (1,2,3)} | ||
println(z5) | ||
|
||
|
||
println("==================================") | ||
//���� | ||
x = [[word.upper(), word.lower(), word.title()] for word in ["hello", "world", "good", "morning"]] | ||
println(x) | ||
|
||
//�ַ��� | ||
y = [ c.upper() for c in "huanghaifeng" where $_ % 2 != 0] //$_ is the index | ||
println(y) | ||
|
||
//��Χ | ||
w = [i + 1 for i in 1..10] | ||
println(w) | ||
|
||
//tuple | ||
v = [x+1 for x in (12,34,56)] | ||
println(v) | ||
|
||
//��ϣ | ||
z = [v * 10 for k,v in {"key1"=>10, "key2"=>20, "key3"=>30}] | ||
println(z) |
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
Oops, something went wrong.