From 6edb6a45d8b2d2993f50176b3324d3fff97fe123 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Thu, 9 Mar 2017 10:12:31 +0100 Subject: stdlib: Improve the Erlang shell's handling of references As of Erlang/OTP 20.0, the type of ETS tables, ets:tid(), is a reference(). A request was put forward that the Erlang shell should be able to handle references in its input. This commit introduces an extended parser in module lib. It can parse pids, ports, references, and external funs under the condition that they can be created in the running system. The parser is meant to be used internally in Erlang/OTP. The alternative, to extend erl_scan and erl_parse, was deemed inferior as it would require the abstract format be able to represent pids, ports, references, and funs, which would be confusing as they are not expressions as such, but data types. --- lib/stdlib/doc/src/shell.xml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'lib/stdlib/doc/src') diff --git a/lib/stdlib/doc/src/shell.xml b/lib/stdlib/doc/src/shell.xml index ab62c2fcdd..2593d3690b 100644 --- a/lib/stdlib/doc/src/shell.xml +++ b/lib/stdlib/doc/src/shell.xml @@ -569,7 +569,7 @@ Hello Number: 3378
 42> E = ets:new(t, []).
-17
+#Ref<0.1662103692.2407923716.214192>

Command 42 creates an ETS table.

@@ -602,7 +602,7 @@ false
 47> E = ets:new(t, []).
-18
+#Ref<0.1662103692.2407923716.214197>
 48> ets:insert({d,1,2}).
 * exception error: undefined function ets:insert/1
@@ -617,10 +617,23 @@ true

Command 49 successfully inserts the tuple into the ETS table.

-50> halt().
+50> ets:insert(#Ref<0.1662103692.2407923716.214197>, {e,3,4}).
+true
+ +

Command 50 inserts another tuple into the ETS table. This time + the first argument is the table identifier itself. The shell can + parse commands with pids (<0.60.0>), ports + (#Port<0.536>), references + (#Ref<0.1662103692.2407792644.214210>), and external + functions (#Fun<a.b.1>), but the command fails unless + the corresponding pid, port, reference, or function can be created + in the running system.

+ +
+51> halt().
 strider 2>
-

Command 50 exits the Erlang runtime system.

+

Command 51 exits the Erlang runtime system.

-- cgit v1.2.3