[erlang-questions] Guards on assignment (i.e. assertions)

Hynek Vychodil hynek@REDACTED
Thu Mar 11 13:13:33 CET 2010


What about

true = B > C,
A = B

On Mon, Mar 1, 2010 at 9:00 PM, Garrett Smith <g@REDACTED> wrote:
> In most cases, assertions come "free" in Erlang in guards and pattern
> matching. There are cases though where I'd like to apply a guard a
> statement like this:
>
>  A = B when B > C
>
> I currently do this:
>
>  A = case B of ValidB when ValidB > C -> ValidB end
>
> or, a simpler form (but the error message on failure isn't as clear):
>
>  A = if B > C -> B end
>
> There are other ways as well, e.g. using functions, etc. but I like
> the first form.
>
> I'm wondering how others implement basic assertions on assignments. I
> think if the first form were supported by the language, I'd use the
> "assert" pattern and my code would be better for it.
>
> Garrett
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>



-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill
your boss.  Be a data hero!
Try GoodData now for free: www.gooddata.com


More information about the erlang-questions mailing list