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); |
||
# |
# 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 # |
|||
# |
# would need to be written as (EMPTY) # |
||
MODE OPTIONS = FLEX[1:0]UNION(OPTNAME,OPTSPECIES,OPTBREED,OWNER |
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: |
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: |
Details: an Irish Setter Dog named Mike owned by HarryS.Truman |
||
Details: a Tyrannosaurus Dinosaur named Rex owned by |
Details: a Tyrannosaurus Dinosaur named Rex owned by GeorgeW.Bush |
||
</pre> |
</pre> |
||