Jump to content

Named parameters: Difference between revisions

Applesoft BASIC
(→‎{{header|Ruby}}: Added info about Ruby 2.1)
(Applesoft BASIC)
Line 77:
getName({lastName:"Doe"})
--> Returns: "?, Doe"</lang>
 
=={{header|Applesoft BASIC}}==
Function definitions in Applesoft BASIC using the DEF FN statement can only have one parameter. Subroutines and functions with many parameters can be simulated using global variables which are effectively named parameters. Default or optional parameters can be simulated with a check in the subroutine.
 
<lang ApplesoftBasic> 100 IF LAST$ = "" THEN PRINT "?";
110 IF LAST$ < > "" THEN PRINT LAST$;
120 IF FIRST$ < > "" THEN PRINT ", "FIRST$;
200 FIRST$ = ""
210 LAST$ = ""
220 RETURN</lang>
 
<pre>]FIRST$ = "JOHN" : GOSUB 100"PRINT NAME
?, JOHN
]LAST$ = "DOE" : GOSUB 100"PRINT NAME
DOE
]FIRST$ = "JOHN" : LAST$ = "DOE" : GOSUB 100"PRINT NAME
DOE, JOHN</pre>
 
=={{header|AutoHotkey}}==
413

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.