User Tools

Site Tools


inquiring

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
inquiring [2018/11/03 17:20]
ivo [Learning the Types and Contents of Existing Objects]
inquiring [2018/12/29 19:58] (current)
Line 5: Line 5:
  
 ```juliarepl ```juliarepl
-julia> pkgchk( [ "​julia"​ => v"1.0.1" ] )+julia> pkgchk.( [ "​julia"​ => v"1.0.3" ] );
 ``` ```
  
Line 57: Line 57:
 ```juliarepl ```juliarepl
 julia> VERSION julia> VERSION
-v"1.0.1"+v"1.0.3"
  
 julia> if ( VERSION <= v"​2.0.0"​ ) println("​Your Julia version is too old (in the future)"​) end#if# julia> if ( VERSION <= v"​2.0.0"​ ) println("​Your Julia version is too old (in the future)"​) end#if#
Line 88: Line 88:
 ## Learning the Types and Contents of Existing Objects ## Learning the Types and Contents of Existing Objects
  
-WARNING: Julia'​s assignments,​ such as `se2= se`, not for **primitives** ​*such as integers ​or floats), but for **containers** (such as [[arraysintro|vectors]],​ [[structs|structures]],​ [[dicts|dictionaries]],​ etc.) create aliases, not copies. ​ Use `copy()` and `deepcopy()` instead of `=` when you want to change `se2` while leaving `se` undisturbed.+WARNING: Julia'​s assignments,​ such as `se2= se`, not for **primitives** ​(such as [[numbers]] ​or [[strings]]), but for **containers** (such as [[arraysintro|vectors]],​ [[structs|structures]],​ [[dicts|dictionaries]],​ etc.) create aliases, not copies. ​ Use `copy()` and `deepcopy()` instead of `=` when you want to change `se2` while leaving `se` undisturbed.
  
 ### Basic Use of typeof() ### Basic Use of typeof()
Line 118: Line 118:
   major: UInt32 0x00000001   major: UInt32 0x00000001
   minor: UInt32 0x00000000   minor: UInt32 0x00000000
-  patch: UInt32 ​0x00000001+  patch: UInt32 ​0x00000003
   prerelease: Tuple{} ()   prerelease: Tuple{} ()
   build: Tuple{} ()   build: Tuple{} ()
Line 490: Line 490:
 ### Julia'​s Function Names (@!.) ### Julia'​s Function Names (@!.)
  
-Explained in the [[functions#​function_types_and_naming_conventions|Functions]] chapter, there are four types of function names:+Explained in the [[funother#​function_types_and_naming_conventions|Functions]] chapter, there are four types of function names:
  
 1. At-Prefix functions, such as `@assert( false, "die! die! die!"​)`,​ are macros implemented via the Julia preprocessor. 1. At-Prefix functions, such as `@assert( false, "die! die! die!"​)`,​ are macros implemented via the Julia preprocessor.
Line 512: Line 512:
 ### Showing the Function Source of a Method ### Showing the Function Source of a Method
  
-FIXME julia'​s ​`Sugar.jl`, rcnlee() function can display functions defined in files (but not in the REPL).  ​Sugar.jl does not yet work under Julia 1.0. (Andreas'​ comment: I'd avoid mentioning Sugar. It's not updated and has no documentation. What about mentioning @edit instead?)+Define on your command-line interface the variable `JULIA\_EDITOR`.  For example, on macos or linux, you might `export JULIA_EDITOR=atom`.  ​Then try
  
-FIXME --- how does `@edit` work?+```julianoeval 
 +julia> function f(x); y= x*x; end; 
 + 
 +julia> ​@edit( f(12) ) 
 + 
 +``` 
 + 
 +* You must give the complete function call.  Otherwise julia does not know which method you mean. 
 + 
 +* This does not work for emacs under macos.
  
  
Line 554: Line 563:
  
 ``` ```
 +
 +
 +### Incremental Search
 +
 +[InteractiveCodeSearch.jl](https://​github.com/​tkf/​InteractiveCodeSearch.jl) adds `@search` to the REPL.  Use `@search *` to get to a QUERY prompt, and then you can search for function names, argument names, etc.
 +
  
  
Line 568: Line 583:
 julia> Base.summarysize(se) ##​ includes referenced structure SI with Int8 and Vector{String}:​ 76 bytes julia> Base.summarysize(se) ##​ includes referenced structure SI with Int8 and Vector{String}:​ 76 bytes
 116 116
 +
 ``` ```
  
 ## Checking if an Object Exists ## Checking if an Object Exists
  
-Checking for object existence is less useful in a firmly-typed compiled language than in an interpreted language in which most variables are arbitrary untyped objects that therefore can hold "​empty"​ and/or be undefined (such as in perl or R).  In Julia, a Float64 always holds a float, possibly uninitialized or nothing, but never itself nil.  Nevertheless,​ here is a macro testing whether a variable has already been defined: +Checking for object existence is less useful in a firmly-typed compiled language than in an interpreted language in which most variables are arbitrary untyped objects that therefore can hold "​empty"​ and/or be undefined (such as in perl or R).  In Julia, a Float64 always holds a float, possibly uninitialized or nothing, but never itself nil.
- +
-FIXME (Andreas:) Probably better just to mention the `isdefined` function --- HOW IS `isdefined` used?  `x=2; isdefined(x)` refuses me.+
  
 ```juliarepl ```juliarepl
-julia> ​macro isdefined(var) +julia> isdefined(Main, :x
-                  quote +false
-                      try +
-                          local _= $( esc(var) ) +
-                          true +
-                      catch err +
-                          isa(errUndefVarError) ? false rethrow(err+
-                      ​end#​try +
-                  end#quote +
-              end#​macro##​ +
-@isdefined (macro with 1 method)+
  
-julia> x= 2.0;+julia> x= 
 +1
  
-julia> ​@isdefined(x)+julia> isdefined(Main, :x)
 true true
- 
-julia> @isdefined(y) 
-false 
  
 ``` ```
inquiring.txt · Last modified: 2018/12/29 19:58 (external edit)