Open In App

Extract a named field in Julia – getfield() Method

Last Updated : 01 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The getfield() is an inbuilt function in julia which is used to extract a named field from the specified value of composite type.

Syntax:
getfield(value, name::Symbol)

Parameters:

  • value: Specified value of composite type.
  • name::Symbol: Specified symbol.

Returns: It returns the extracted named field from the specified value of composite type.

Example 1:




# Julia program to illustrate 
# the use of getfield() method
   
# Getting the extracted named field
# from the specified value of composite type. 
a = 5//2
println(getfield(a, :num))


Output:

5

Example 2:




# Julia program to illustrate 
# the use of getfield() method
   
# Getting the extracted named field
# from the specified value of composite type. 
a = 7//3
println(getfield(a, :num))


Output:

7

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads