[erlang-questions] erlang improvement - objective c (or smalltalk) syntax

Tony Rogvall <>
Fri Jun 5 11:50:41 CEST 2009

I like the idea.

just think about the way you handle variant functions:

format(value:V) ->
	format(value:V precision:0 width:0 pad:$\s).
format(value:V width:W) ->
	format(value:V precision:0 width:W pad:$\s).
format(value:V precision:P) ->
	format(value:V precision:P width:0 pad:$\s).
format(value:V precision:P width:W pad:C) ->
	format_v(value:V precision:P width:W pad:C).

The API designer still has to specify several cases but the user can  
use the variants more freely.

	format(value:"Hello" width:12)

	format(value:3.13 precision:2)

	format(value:16#4562 width:8 pad:$0)

To simplify the API designers work a syntax for default values could  
be designed.
  (Without thinking much about syntax! or the gory cases ;-)

format(value:V precision:P=0 width:W=0 pad:C=$\s) ->
	format_v(value:V precision:P width:W pad:C).

The translator must in this case generate all versions of format (note  
the argument name sorting)

format_value(V) -> format_pad_precision_value_width($\s,0,V,0).
format_precision_value(V,P) -> format_pad_precision_value_width($ 
format_width_value(V,W) -> format_pad_precision_value_width($\s,0,V,W).
... etc

To make this change and preserve backwards compatibility then old  
functions must be mapped to the
new or vice versa (depending on situation)

keysearch(Key,Index,List) -> keysearch(key:Key index:Index list:List).

keysearch(key:Key index:Index list:List) -> keysearch(Key,Index,List).

The new keysearch will probably be called something like


On my which list is also some kind of syntax (sugar) to change some  
arguments in "recursive" functions
without having to specify every one again:

my_func(X1, X2, X3, X4, X5, X6, X7, X8) ->
	case X1 of
		1 -> my_func(X1-1, X2, X3, X4, X5, X6, X7, X8);
		2 -> my_func(X1, X2-1, X3, X4, X5, X6, X7, X8);
		3 -> my_func(X1, X2, X3-3, X4, X5, X6, X7, X8);

Someway of grouping the arguments ?

my_func(As=#(x1=X1 x2=X2 x3=X3, x4=X4, x5=X5,x6=X6,x7=X7,x8=X8)) ->
	case X1 of
		1 -> my_func(As# {x1=X1-1});
		2 -> my_func(As# {x2=X2-1});
		3 -> my_func(As# {x3=X3-1})

A record like syntax? other suggestions?  Maybe even anonymous  
arguments as a group.



On 5 jun 2009, at 10.09, Vlad Dumitrescu wrote:

> On Fri, Jun 5, 2009 at 09:46, Bengt Kleberg < 
> > wrote:
>> The drawback with
>> string:substring_string_start_length(S, X, J)
>> is that you might still have made a mistake. If/When
>> string:substring(string:S, start:X, length:J)
>> is introduced the compiler will put things in the correct position.
> Yes, but you can still write "start:J, length:X" and make a mistake
> :-) Nothing is completely error-proof.
>> It could also make sure that the function (ought to) exist, at  
>> least for
>> OTP functions. That would be nice.
>> The number of times I have written
>> lists:length/1 is embarrassing.
> Yeah, me too :-)
> This is a different can of worms. There is no reason the compiler
> couldn't check if lists:length exist now either, if it wanted to. But
> then we couldn't compile each erl file separately, only the whole
> system together.
> dialyzer can check if the target of a call exists.
> regards,
> Vlad
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org

More information about the erlang-questions mailing list