[erlang-questions] Reading records with file:consult/1 or erl_eval/2?

Rusty Klophaus <>
Fri Nov 21 15:29:21 CET 2008


Hi all,

I'm working on a small utility that reads Erlang terms from a file,  
processes them, and spits out another file.

I've hit an unanticipated snag on step one. I can read basic terms  
just fine, but I can't make file:consult/1 or erl_eval:expr/2  
recognize records. Any suggestions? Is this just a known limitation?

Output and code are below.

Thanks,
Rusty


*** OUTPUT ***

Eshell V5.6.5  (abort with ^G)
1> reader:read_with_consult().
{error,{1,erl_parse,"bad term"}}
2> reader:read_with_eval().
** exception error: {undefined_record,document}

Here is the code and supporting files:

*** READER.ERL CONTAINS ***

-module (reader).
-include ("records.hrl").
-compile(export_all).

read_with_consult() ->
	file:consult("terms.txt").

read_with_eval() ->
	{ok, B} = file:read_file("terms.txt"),
	S = binary_to_list(B),
	{ok, Tokens, _} = erl_scan:string(S),
	{ok, [Form]} = erl_parse:parse_exprs(Tokens),
	erl_eval:expr(Form, []).



*** RECORDS.HRL CONTAINS ***

-record(document, {title, description}).



*** TERMS.TXT CONTAINS ***

#document {}.










More information about the erlang-questions mailing list