[erlang-questions] how to quelch lc warnings?

Ulf Wiger (TN/EAB) <>
Thu Apr 12 10:56:37 CEST 2007


Apologies for the silly example, but imagine I want to do this:

Eshell V5.5.3.1  (abort with ^G)
1> Nums = [1,2,3], Nouns = [shoe,box,tape], Verbs = [].
[]
2> [Nums || Nums =/= []] ++ [Nouns || Nouns =/= []] ++ [Verbs || Verbs
=/= []].
[[1,2,3],[shoe,box,tape]]

I have a more complex example, where I'm actually doing something
useful,
involving a long property list, from which I generate code. I output
comments
and code given that there is actually something to output in a given
category.
Using LCs makes for quite compact expressions:

	file:write(Fd, hrl_boilerplate(File, Terms)),
	[
	 [file:write(
	    Fd,
	    ("\n\n"
	     "%%%
-------------------------------------------------------\n"
	     "%%% X records:\n"
	     "%%%
-------------------------------------------------------\n"
	    )),
	  io:fwrite(Fd, "~s~n", [erl_prettypr:format(
				   erl_syntax:form_list(XForms))])
	  ] || XForms =/= []],
	[
	 [file:write(
	    Fd,
	    ("\n\n"
	     "%%%
-------------------------------------------------------\n"
	     "%%% Imported records from " ++ atom_to_list(Mod) ++ ":\n"
	     "%%%
-------------------------------------------------------\n"
	    )),
	  io:fwrite(Fd, "~s~n", [erl_prettypr:format(
				   erl_syntax:form_list(XForms1))])
	  ] || {Mod, XForms1} <- ImportedXForms],
	[
	 [file:write(
	    Fd,
	    ("\n\n"
	     "%%%
-------------------------------------------------------\n"
	     "%%% Y Macros:\n"
	     "%%%
-------------------------------------------------------\n"
	    )),
	  file:write(Fd, gen_y_macros(Terms, Prefix))
	 ] || Y =/= []],
   ...
where I don't have to output boilerplate comments for empty 
sections. There are of course other ways to do it, but I find this
layout appealing (blame Thomas Arts and John Hughes for 
putting me onto it).

The only problem I see with this is that the compiler will issue
warnings
such as 

./codegen.erl:480: Warning: list comprehension has no generator (perhaps
"|" mistyped as "||"?)


Apparently, I can't tell the compiler that this is in fact not a typo.
Any plans to introduce such an option?

BR,
Ulf W
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070412/24688c79/attachment.html>


More information about the erlang-questions mailing list