Named parameters: Difference between revisions

→‎{{header|ALGOL 68}}: Updated for latest ALGOL 68G, print an/a depending on whether the breed starts with a vowel or not
(→‎{{header|ALGOL 68}}: Updated for latest ALGOL 68G, print an/a depending on whether the breed starts with a vowel or not)
Line 38:
OWNER=STRUCT(STRING first name, middle name, last name);
 
# earlierVersion versions2 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 #
# forwould options.need Empty option lists canto be written as (EMPTY) #
MODE OPTIONS = FLEX[1:0]UNION(OPTNAME,OPTSPECIES,OPTBREED,OWNER,VOID); # add ,VOID for Algol 68G version 2 #
 
# due to the Yoneda ambiguity simple arguments must have an unique operator defined #
Line 60:
ESAC
OD;
print(("Details: a ",breed, " ", species, " named ",name," owned by ",owner, newline))
,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(()) # use print pet((EMPTY)) for Algol 68G version 2 #
END</lang>
</lang>
Output:
<pre>
Details: aan Irish Setter Dog named Mike owned by Harry SHarryS. Truman
Details: a Tyrannosaurus Dinosaur named Rex owned by George WGeorgeW. Bush
</pre>
 
3,022

edits