Monday, June 19, 2017

Julia - Programming Language - ans variable

In an interactive session of Julia programming language. When you type an expression at the prompt, say, 1 + 5 - the output is displayed at the prompt.

$ julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.3.11 (2015-07-27 06:18 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org release
|__/                   |  x86_64-linux-gnu

julia> 1+5

6

We can access this output using the variable "ans". This is because the result gets stored in the "ans" variable. 

julia> ans
6

Now, consider the below expression, in which we are explicitly storing the result in a variable, "var":

julia> var = 2 + 3
5

julia> var
5

julia> ans
5

julia>

In such a case, the answer of the expression is stored in both "var" and the "ans" variables. 

Caveat:

The binding of the result to the "ans" variable happens only during interactive sessions. It does not happen in other ways. 



No comments:

Post a Comment