Skip to content

Commit 445b7c4

Browse files
committed
Added more livescript examples
1 parent a9dd91c commit 445b7c4

12 files changed

+129
-7
lines changed

livescript/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<img src="https://raw.githubusercontent.com/rtoal/polyglot/master/docs/resources/livescript-logo-64.png">
2+
3+
# LiveScript Explorations:
4+
5+
To begin coding with LiveScript, start by installing the LiveScript compiler using this command below. Note that you need to have already installed npm before (See the JavaScript README for more details).
6+
7+
```
8+
npm install -g livescript
9+
```
10+
11+
To run a LivveScript file like hello_world.hx, go to the same directory as the file and then run the following command:
12+
13+
```
14+
lsc .\hello_world.ls
15+
```
16+
17+
You can run the tests below on Powershell below using the following command:
18+
19+
```
20+
.\test.ps1
21+
```
22+
23+
## About LiveScript:
24+
25+
LiveScript is... TODO
26+
27+
## LiveScript Resources:
28+
29+
Continue your study of LiveScript via:
30+
31+
[LiveScript GitHub](https://github.com/gkz/LiveScript)
32+
[LiveScript Documentation](https://livescript.net/)
33+
[LiveScript prelude.ls Library](https://www.preludels.com/)

livescript/assignment_scoping.ls

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
x = "X = 1"
2+
3+
do ->
4+
x = "X = 2"
5+
console.log x
6+
7+
console.log x
8+
console.log "------"
9+
10+
do ->
11+
x := "X = 3"
12+
console.log x
13+
14+
console.log x

livescript/clockhands.ls

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
for t in [Math.floor (i + 0.5) * 43200 / 11 for i from 0 to 10]
2-
console.log "#{("#{(Math.floor t / 3600 - 1) %% 12 + 1}").padStart(2, \0)}:#{("#{Math.floor t % 3600 / 60}").padStart(2, \0)}:#{("#{t % 60}").padStart(2, \0)}"
1+
pad = (n) -> "#{n}".padStart(2, "0")
2+
for i from 0 to 10
3+
t = Math.floor (i + 0.5) * 43200 / 11
4+
[h, m, s] = [(Math.floor t / 3600), (Math.floor t / 60) % 60, t % 60]
5+
console.log "#{pad(h || 12)}:#{pad m}:#{pad s}"

livescript/clockhands_clean.ls

Lines changed: 0 additions & 5 deletions
This file was deleted.

livescript/clockhands_golf.ls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
for t in [Math.floor (i + 0.5) * 43200 / 11 for i from 0 to 10]
2+
console.log "#{("#{(Math.floor t / 3600 - 1) %% 12 + 1}").padStart(2, \0)}:#{("#{Math.floor t % 3600 / 60}").padStart(2, \0)}:#{("#{t % 60}").padStart(2, \0)}"

livescript/clockhands_time.ls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
for i from 0 to 10
2+
new Date(Math.floor((43200000 * i + 21600000) / 11)).
3+
toISOString().substring(11, 19).
4+
replace(/^00/, '12') |> console.log

livescript/expression_ubiquity.ls

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
result = if true
2+
then 5
3+
else 0
4+
5+
console.log result
6+
7+
result = for i from 1 to 40
8+
i
9+
10+
console.log result

livescript/expressive_booleans.ls

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
x = (true && on && yes)
2+
y = (false || off || no)
3+
4+
console.log x
5+
console.log y
6+
7+
console.log {+a, -b}

livescript/interpolation_split.ls

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
x = 3
2+
y = no
3+
z = 7
4+
a = %"#x#y#z"
5+
6+
console.log a

livescript/list.ls

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[1, 2, 3]
2+
[1 2 3]
3+
4+
list1 =
5+
1
6+
2
7+
3
8+
9+
list2 =
10+
1
11+
...
12+
13+
tree =
14+
* 1
15+
2
16+
* 3
17+
* 4
18+
5
19+
6
20+
7
21+
* 8
22+
9
23+
10
24+
11
25+
26+
word_list = <[ Hello my name is Sam ]>

0 commit comments

Comments
 (0)