Package support in Erlang: Status ?

Richard Carlsson richardc@REDACTED
Mon May 26 18:47:14 CEST 2003


On Thu, 22 May 2003, david wallin wrote:

> How about this, do a file:consult/1 on a file containing :
>
> {abba_a,a}.
> {abba.b,b}.
>
> This results in an error : '{error,{1,erl_parse,"bad term"}}'

Found it - the function erl_parse:normalise/1 did not understand the dot
notation. Below is a patch, which also fixes another latent bug.

	/Richard



*** lib/stdlib/src/erl_parse.yrl	16 May 2003 12:15:16 -0000	1.13
--- lib/stdlib/src/erl_parse.yrl	26 May 2003 16:12:09 -0000
***************
*** 511,523 ****

  package_segments(Name) ->
!     package_segments(Name, []).

! package_segments({record_field,_,F1,F2}, Fs) ->
!     package_segments(F1, [F2 | Fs]);
! package_segments({atom,La,A}, [F | Fs]) ->
!     [A | package_segments(F, Fs)];
! package_segments({atom,La,A}, []) ->
!     [A];
! package_segments(_, _) ->
      error.

--- 511,523 ----

  package_segments(Name) ->
!     package_segments(Name, [], []).

! package_segments({record_field, _, F1, F2}, Fs, As) ->
!     package_segments(F1, [F2 | Fs], As);
! package_segments({atom, _, A}, [F | Fs], As) ->
!     package_segments(F, Fs, [A | As]);
! package_segments({atom, _, A}, [], As) ->
!     lists:reverse([A | As]);
! package_segments(_, _, _) ->
      error.

***************
*** 581,584 ****
--- 581,590 ----
  normalise({tuple,_,Args}) ->
      list_to_tuple(normalise_list(Args));
+ %% Atom dot-notation, as in 'foo.bar.baz'
+ normalise({record_field,_,_,_}=A) ->
+     case package_segments(A) of
+ 	error -> erlang:fault({badarg, A});
+ 	As -> list_to_atom(packages:concat(As))
+     end;
  %% Special case for unary +/-.
  normalise({op,_,'+',{char,_,I}}) -> I;
***************
*** 587,591 ****
  normalise({op,_,'-',{char,_,I}}) -> -I;		%Weird, but compatible!
  normalise({op,_,'-',{integer,_,I}}) -> -I;
! normalise({op,_,'-',{float,_,F}}) -> -F.

  normalise_list([H|T]) ->
--- 593,598 ----
  normalise({op,_,'-',{char,_,I}}) -> -I;		%Weird, but compatible!
  normalise({op,_,'-',{integer,_,I}}) -> -I;
! normalise({op,_,'-',{float,_,F}}) -> -F;
! normalise(X) -> erlang:fault({badarg, X}).

  normalise_list([H|T]) ->







Richard Carlsson (richardc@REDACTED)   (This space intentionally left blank.)
E-mail: Richard.Carlsson@REDACTED	WWW: http://user.it.uu.se/~richardc/
 "Having users is like optimization: the wise course is to delay it."
   -- Paul Graham



More information about the erlang-questions mailing list