[m-users.] Idiomatic Mercury - if-then-else or (C->I;E)

Richard A. O'Keefe ok at cs.otago.ac.nz
Mon Nov 23 17:06:36 AEDT 2015


On 23/11/2015, at 5:08 pm, Mark Brown <mark at mercurylang.org> wrote:
> I must confess that, as a newbie Prolog programmer, this was not my
> first hypothesis. :-(

You must remember that all the original Prolog
developers knew Lisp quite well, including familiarity
with the Lisp 1.5 manual.
> 
> To a Scala programmer, => looks like case selection not implication.

Weird.  Does any other language use => for case selection?
> So I'd like to add another reason for using if-then-else, which is
> that across programming languages it is used much more consistently
> than any kind of arrow.

Consistency?  You *really* believe that there is
any great consistency across programming languages?
- There are languages where conditional expressions
  exist.  C, for example, spells them "Cond ? Then : Else"
  while Algol 60 spelled them "if Cond then Then else Else"
  and Algol 68 required "if Cond then Then else Else fi".
  R uses "if(Cond, Then, Else)" but evaluates all of the
  arguments; this is perhaps closer to Fortran's
  WHERE/ELSEWHERE/ENDWHERE.  There have been languages
  that used "Then if Cond else Else".
- There are languages where IF statements and WHILE
  statements exist but there are no Boolean values
  (which should come as no surprise to Mercury programmers).
  (This used to describe COBOL.  This used to describe
  Erlang.  It describes a number of 20th century
  system implementation languages.)
- When it comes to statements, there are languages
  (IMP, Basic on RSTS/E, Perl) where
  Then if Cond
  is a statement.
- There are languages in which one-armed 'if'
  is written using 'when' or 'unless'.
- For that matter, C's grandfather BCPL distinguished
  between one-armed 'if Cond then Then' and
  two-armed 'test Cond then Then else Else' statements.
- There are languages where 'if' statements must be
  closed; they disagree about whether to use
  'close', 'fi', 'end', 'endif', 'end if', or 'end-if'.
  (Probably others that I've forgotten.)
- APL used ->Label/Cond; Dyalog APL these days has
  :If Cond
      statements
  :EndIf
  which reminds us that the word 'then' is often
  dispensed with (as in C, C++, C#, Java, JavaScript, &c).
  (You really don't want to know about :AndIf and
  :OrIf in Dyalog APL.)
- While we're at it, Erlang has
  if Guard -> Body ; Guard -> Body ; ... Guard -> Body end
  where the Guards are conditional forms, not expressions.

Almost the only point of agreement between languages
(and they *don't* all agree on it) is that conditional
execution based on a true/false test has the word 'if'
in it somewhere.  Or possibly 'unless' as a fairly
common abbreviation if 'if-not'.  Except for languages
that used non-English keywords, like translations of
Algol 60, Algol 68, Pascal into French or Russian.
See https://en.wikipedia.org/wiki/Non-English-based_programming_languages
for a bit of a culture shock.

I'm not even talking about deliberately weird languages
like Intercal here.  There are more and weirder
programming languages designed for serious use than
you can imagine.  Do NOT mistake the quirks of C syntax
(or even of Ada or Fortran syntax) for programming
language universals.  Not even 'function call' syntax
is universal.  For that matter, neither are integers.
(There have been high level programming languages in
which the default base was 8, not 10.)




More information about the users mailing list