Skip to content

Commit 3582219

Browse files
authored
Merge pull request tsoding#104 from tsoding/seq
Proper seq implementation
2 parents 5f9af58 + c484f60 commit 3582219

File tree

4 files changed

+37
-40
lines changed

4 files changed

+37
-40
lines changed

examples/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
hello-world
22
rule110
3-
seq100
43
name
54
reverse-linked-list
65
cat
7-
rot13
6+
rot13
7+
seq

examples/seq.porth

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
include "std.porth"
2+
3+
macro limit mem end
4+
5+
argc 2 < if
6+
"Usage: seq <limit>\n" stderr write drop
7+
"ERROR: no limit is provided\n" stderr write drop
8+
1 exit
9+
end
10+
11+
1 nth_argv
12+
while dup , 0 != do
13+
dup , '0' < over , '9' > bor if
14+
"ERROR: `" stderr write drop
15+
1 nth_argv strlen 1 nth_argv stderr write drop
16+
"` is not a correct integer\n" stderr write drop
17+
1 exit
18+
end
19+
20+
limit ,64 10 *
21+
over , '0' -
22+
+
23+
limit swap .64
24+
25+
1 +
26+
end drop
27+
28+
0 while dup limit ,64 < do
29+
dup print
30+
1 +
31+
end drop
Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
:i argc 0
1+
:i argc 1
2+
:b arg0 2
3+
69
24
:b stdin 0
35

46
:i returncode 0
5-
:b stdout 290
7+
:b stdout 197
68
0
79
1
810
2
@@ -72,37 +74,6 @@
7274
66
7375
67
7476
68
75-
69
76-
70
77-
71
78-
72
79-
73
80-
74
81-
75
82-
76
83-
77
84-
78
85-
79
86-
80
87-
81
88-
82
89-
83
90-
84
91-
85
92-
86
93-
87
94-
88
95-
89
96-
90
97-
91
98-
92
99-
93
100-
94
101-
95
102-
96
103-
97
104-
98
105-
99
10677

10778
:b stderr 0
10879

examples/seq100.porth

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

0 commit comments

Comments
 (0)