The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
NewRPL: Default and optional arguments
04-19-2019, 04:20 PM
Post: #1
NewRPL: Default and optional arguments
Hello

1: Optional arguments

In the following code, when executing the SUMa function, it waits for 3 arguments and returns 24

PHP Code:
«
   → a b c
   «
      a  b 
+
   
»
»
'SUMa' STO
CLEAR 9 8 7 SUMa 
[enterreturns 24 
CLEAR 9 8 SUMa [enter] ERROR, TOO FEW ARGUMENTS

The second version of the previous code SUMb, using a global variable 'args', selects the type of code to execute

PHP Code:
«
   
IF args 2 == THEN
    → a b
     «
        a b 
+
     
»
   
ELSE
     IF 
args 3 == THEN
       → a b c
       «
         a b 
+
       
»
     
ELSE
       
"ERROR, TOO FEW ARGUMENTS"
     
END
   END
»
'SUMb' STO
CLEAR 9 8 7 3 
'args' STO SUMb 24
CLEAR 9 8 2 
'args' STO SUMb 17 

My idea or notation is to specify those arguments in the following way OPERATORNAME←ARGS

PHP Code:
CLEAR 9 8 7 SUMb←3 24
CLEAR 9 8 SUMb←2 
17 

Where the numeric value after ← stores the value in the temporary variable associated with the name of the current function # ←args

2: the other idea is to be able to specify the initial value

«
→ expr var = 'x'
«
expr var xOperator
»
»
'FNTa' STO

'x^3' FNTa←1 @ takes 1 unique argument and by default the second with value 'x'
'Y^3' 'Y' FNTa←2 or
'Y^3' 'Y' FNTa @ takes 2 arguments and overwrites the second with the value of 'Y'
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
NewRPL: Default and optional arguments - compsystems - 04-19-2019 04:20 PM



User(s) browsing this thread: 2 Guest(s)