Welcome to mirror list, hosted at ThFree Co, Russian Federation.

README.md - github.com/torch/trepl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fa7cbff57ad45e373cdede8634e2440405773030 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# TREPL: A REPL for Torch

```
  ______             __   |  Torch7
 /_  __/__  ________/ /   |  Scientific computing for LuaJIT.
  / / / _ \/ __/ __/ _ \  |
 /_/  \___/_/  \__/_//_/  |  https://github.com/torch
                          |  http://torch.ch

th>
```

A pure Lua [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) 
for LuaJIT, with heavy support for Torch types. 

Uses Readline for tab completion.

This package installs a new binary named `th`, which
comes packed with all these features:

Features:

  * Tab-completion on nested namespaces
  * Tab-completion on disk files (when opening a string)
  * History
  * Pretty print (table introspection and coloring)
  * Auto-print after eval (can be stopped with ;)
  * Each command is profiled, timing is reported
  * No need for '=' to print
  * Easy help with: `? funcname`
  * Self help: `?`
  * Shell commands with: $ cmd (example: `$ ls`)
  * Print all user globals with `who()`
  * Import a package's symbols globally with `import(package)`
  * Require is overloaded to provide relative search paths: `require('./mylocallib/')`
  * Optional strict global namespace monitoring
  * Optional async repl (based on [async](https://github.com/clementfarabet/async))

Install
-------

Via luarocks:

```
luarocks install trepl
```

Launch
------

We install a binary, simple to remember:

```
th
> -- amazing repl!
```

Alternatively, you can always bring up the repl by loading it as a lib,
from anywhere:

```
luajit
> repl = require 'trepl'
> repl()
```

Use
---

Completion:

```lua
> cor+TAB   ...  completes to: coroutine
```

History:

```lua
> ARROW_UP | ARROW_DOWN
```

Help (shortcut to Torch's help method):

```lua
> ? torch.FloatTensor
prints help...
```

Shell commands:

```lua
> $ ls
README.md
init.lua
trepl-scm-1.rockspec

[Lua # 2] > $ ll
...

> $ ls
...
```

History / last results. Two variables are used:

```
_RESULTS: contains the history of results:

> a = 1
> a
1
> 'test'
test
> _RESULTS
{
   1 : 1
   2 : test
}

_LAST: contains the last result
> _LAST
test

Convenient to get output from shell commands:
> $ ls -l
> _LAST
contains the results from ls -l, in a string.
```

Hide output. By default, TREPL always tries to dump
the content of what's evaluated. Use ; to stop it.

```lua
> a = torch.Tensor(3)
> a:zero()
0
0
0
[torch.DoubleTensor of dimension 3]

> a:zero();
> 
```

Helpers
-------

Colors libraries can be loaded independently:

```lua
> c = require 'trepl.colorize'
> print(c.red('a red string') .. c.Blue('a bold blue string'))
```

Globals
-------

Global variables are a well known issue with Lua. `th` can be run
with a flag `-g` that will monitor global variables creation and access.

Creation of a variable will generate a warning message, while access
will generate an error.

```sh
th -g
> require 'sys';
created global variable: sys @ [c-module]
> a = 1
created global variable: a @ a = 1
> b
error: attempt to read undeclared variable b
```

Async repl [BETA]
-----------------

An asynchronous repl can be started with `-a`. Based on [async](https://github.com/clementfarabet/async), 
this repl is non-blocking, and can be used to spawn/schedule asyncrhonous jobs. It is still beta, 
and does not yet have readline support:

```sh
th -a
> idx = 1
> async.setInterval(1000, function() print('will be printed every second - step #' .. idx) idx = idx + 1 end)
will be printed every second - step #1
will be printed every second - step #2
will be printed every second - step #3
> idx = 20
will be printed every second - step #20
will be printed every second - step #21
```