Julia

12 flashcards · Programming Languages · by lakesare

  1. How to concatenate strings in Julia?

    * String concatenation is done with * in Julia, not + like in Python. Analogously, string repetition is done with ^, not *. Implicit string concatenation of string literals like in Python (e.g. 'ab' 'cd' == 'abcd') is not done in Julia.

  2. Python list corresponds to Julia's _________?

    Vector{Any} Python Lists—flexible but slow—correspond to the Julia Vector{Any} type or more generally Vector{T} where T is some non-concrete element type.In Julia, indexing of arrays, strings, etc. is 1-based not 0-based.

  3. x[1:] in Python is equivalent to x[________] in Julia.

    x[2:end]

  4. What's @ in Julia?

    A macro. In Julia the @ symbol refers to a macro, whereas in Python it refers to a decorator.

  5. How to represent a rational number in Julia?

    2//3

  6. How to write the same function f more compactly?

    The traditional function declaration syntax demonstrated above is equivalent to the following compact "assignment form".

  7. How to state the return type of the function?

    ::

  8. Name 2 ways to create an anonymous function in Julia.

  9. What are the names in Julia for: an array a hash

    an array - a tuple a hash - a named tuple

  10. What does this function return?

    A tuple. In Julia, one returns a tuple of values to simulate returning multiple values. However, tuples can be created and destructured without needing parentheses, thereby providing an illusion that multiple values are being returned, rather than a single tuple value.

  11. What's the result?

    This is function composition. Function composition is when you combine functions together and apply the resulting composition to arguments. You use the function composition operator (∘) to compose the functions, so (f ∘ g)(args...) is the same as f(g(args...)).

  12. What does the dot do in this syntax f.(A)?

    Any Julia function f can be applied elementwise to any array (or other collection) with the syntax f.(A). Of course, you can omit the dot if you write a specialized "vector" method of f, e.g. via f(A::AbstractArray) = map(f, A), and this is just as efficient as f.(A). The advantage of the f.(A) syntax is that which functions are vectorizable need not be decided upon in advance by the library writer.