Hi6 Robot Controller Manual - Robot Language HRScr
English
English
  • Hi6 Robot Controller Function Manual - Robot Language HRScript
  • 1. Overview
    • 1.1 Introduction of HRScript
  • 2. Basic Syntax
    • 2.1 Statements
    • 2.2 Identifiers
    • 2.3 Types of Statements
      • 2.3.1 Procedures
      • 2.3.2 Assignment Statements
      • 2.3.3 Comment Statements
      • 2.3.4 Labels
    • 2.4 First Program – Hello, World!
    • 2.5 Data Type
      • 2.5.1 String Data Type
      • 2.5.2 Number Data Type
      • 2.5.3 Boolean Data Type
      • 2.5.4 Array Type and Object Type
    • 2.6 Variables
    • 2.7 Binary and Hexadecimal
    • 2.8 Operators and Expressions
    • 2.9 Functions
      • 2.9.1 Math Functions
      • 2.9.2 String Functions
      • 2.9.3 Date and Time Functions
      • 2.9.4 Constructor Functions
      • 2.9.5 Other Functions
  • 3. Flow-Control Statements and Sub-Program
    • 3.1 Address
    • 3.2 Stop or Wait Statement
      • 3.2.1 stop
      • 3.2.2 end
      • 3.2.3 delay
      • 3.2.4 wait
    • 3.3 Branch Statement
      • 3.3.1 goto
    • 3.4 Conditional Statements
      • 3.4.1 Single-Line if
      • 3.4.2 if-endif
      • 3.4.3 if-else-endif Statement
      • 3.4.4. if-elseif-else-endif
      • 3.4.5 switch-case-break-end_switch
    • 3.5. Nested Flow-Control Statements
    • 3.6 Loop Statements
      • 3.6.1 for-next
    • 3.7 Call, Jump Statement and Subprograms
      • 3.7.1 call
      • 3.7.2 Parameters and param, return
      • 3.7.3 jump
    • 3.8 Local Variables and Global Variables
      • 3.8.1 Local Variables
      • 3.8.2 Global Variables
      • 3.8.3 Precedence
  • 4. Arrays and Objects
    • 4.1 Arrays
      • 4.1.1 Arrays
      • 4.1.2 Multidimensional Arrays
      • 4.1.3 Array Constructor Function
    • 4.2 Object
    • 4.3 Copied assignment of arrays and objects
    • 4.4 Call-by-reference and call-by-value
  • 5. Moving a Robotwith Robot Language
    • 5.1 Pose
    • 5.2 Shift
    • 5.3 Pose Expression
    • 5.4 move
    • 5.5 User Coordinate System (UCS)
  • 6. Communicating with External Devices
    • 6.1 FB Object: Digital I/O
      • 6.1.1 Input/Output Variables
      • 6.1.2 Examples
    • 6.2 ENet Module: Ethernet TCP/UDP Communication
      • 6.2.1 Constructor
      • 6.2.2 Member Variables
      • 6.2.3 Member Procedures
        • open
        • connect
        • send
        • recv
        • close
      • 6.2.4 Member Function
        • state
      • 6.2.5 Examples of TCP and UDP Communication
    • 6.3 Http_Cli Module: HTTP Client
      • 6.3.1 Constructor
      • 6.3.2 Member Variables
      • 6.3.3 Member Procedure
        • get
        • put
        • post
        • delete
      • 6.3.4 Examples of HTTP Client Communication
    • 6.4 Getting input from console bar
      • 6.4.1 input
Powered by GitBook
On this page

Was this helpful?

Edit on Git
  1. 4. Arrays and Objects

4.4 Call-by-reference and call-by-value

In the description of call statements and jump statements given in Section 3.4, the concepts of formal parameters and actual parameters were explained. When an actual parameter has been transported to a sub-program, if the sub-program ends after changing the value of the parameter, will it be reflected to the main program?

For example, let’s assume that a sub-program 0005_pow3.job raises a value to the third power as follows:

0001.job

var x=2

call 0005_pow3,x

print x

end

0005_pow3.job

param p

var t=p

p=t*t*t # (1)

end

Result

2

Although we expected that 8 is output because 2×2×2 is 8, the result is 2. It is because, when a numeric-type actual parameter is transported to a sub-program, the value is copied as a parameter. In other words, in (1), because the value raised to the third power was assigned to the copied version, it did not affect the value of the original parameter, x.

Therefore, the teaching program should be corrected so that the resulting value is transported by a return statement.

0001.job

var x=2

call 0005_pow3,x

x=result()

print x

end

0005_pow3.job

param p

var t=p

p=t*t*t

return p

Result

8

On the other hand, in the case of arrays or objects, the reference of actual parameters, not the copied versions, will be transported. A reference refers to the position of a parameter.

In the following example, where the sub-program 0006_pow3.job raises each element of an array to the third power, the values of the elements of the actual parameter array are changed.

0001.job

var x=[3, 2, 4]

call 0006_pow3,x

print x

end

0006_pow3.job

param p

var t

for i=0 to len(arr)-1

t=p[i]

p[i] = t*t*t

next

end

Result

[27, 8, 64]

When a sub-program is called, if the copied version of the value of an actual parameter is transported, it is referred to as call-by-value; and if a reference is transported, it is referred to as call-by-reference. Whether it will be call-by-value or call-by-reference is determined by the type of values as follows:

call-by-value

Boolean, numeric, and string types

call-by-reference

Array and object types

Previous4.3 Copied assignment of arrays and objectsNext5. Moving a Robotwith Robot Language

Last updated 3 years ago

Was this helpful?