Named parameters: Difference between revisions

Content added Content deleted
(→‎{{header|ALGOL 68}}: Updated for latest ALGOL 68G, print an/a depending on whether the breed starts with a vowel or not)
Line 38: Line 38:
OWNER=STRUCT(STRING first name, middle name, last name);
OWNER=STRUCT(STRING first name, middle name, last name);


# earlier versions of Algol 68G would allow empty options to be specified as () #
# Version 2 of Algol 68G would not allow empty options to be specified as () so #
# VOID would need to be included in the MODEs for options and Empty option lists #
# however more recent versions reject that and so we include VOID in the MODEs #
# for options. Empty option lists can be written as (EMPTY) #
# would need to be written as (EMPTY) #
MODE OPTIONS = FLEX[1:0]UNION(OPTNAME,OPTSPECIES,OPTBREED,OWNER,VOID);
MODE OPTIONS = FLEX[1:0]UNION(OPTNAME,OPTSPECIES,OPTBREED,OWNER); # add ,VOID for Algol 68G version 2 #


# due to the Yoneda ambiguity simple arguments must have an unique operator defined #
# due to the Yoneda ambiguity simple arguments must have an unique operator defined #
Line 60: Line 60:
ESAC
ESAC
OD;
OD;
print(("Details: a ",breed, " ", species, " named ",name," owned by ",owner, newline))
print(("Details: "
,IF CHAR c = breed[LWB breed]; char in string( c, NIL, "AaEeIiOoUu" ) THEN "an " ELSE "a " FI
,breed, " ", species, " named ",name," owned by ",owner, newline))
);
);
print pet((NAME "Mike", SPECIES "Dog", BREED "Irish Setter", OWNER("Harry", "S.", "Truman")));
print pet((NAME "Mike", SPECIES "Dog", BREED "Irish Setter", OWNER("Harry", "S.", "Truman")));
print pet((EMPTY))
print pet(()) # use print pet((EMPTY)) for Algol 68G version 2 #
END
END</lang>
</lang>
Output:
Output:
<pre>
<pre>
Details: a Irish Setter Dog named Mike owned by Harry S. Truman
Details: an Irish Setter Dog named Mike owned by HarryS.Truman
Details: a Tyrannosaurus Dinosaur named Rex owned by George W. Bush
Details: a Tyrannosaurus Dinosaur named Rex owned by GeorgeW.Bush
</pre>
</pre>