Skip to content
Kyle Barbary edited this page Jul 4, 2014 · 2 revisions

This page notes some important differences between Yorick and Python as well as Yorick features that may be surprising to someone familiar with Python.

  • Yorick has column-major arrays while Python has row-major arrays In other words, in Yorick, the first array index is the "fastest" (contiguous in memory) while in numpy the last array index is the fastest. For example, the 4-d data in Yorick might have shape (n_x, n_y, n_lambda, n_time) but in numpy the shape is (n_time, n_lambda, n_y, n_x), e.g., (<nfiles>, 779, 15, 15).

  • Yorick has 1-based indexing while Python/numpy has 0-based indexing.

  • In Yorick, ranges are inclusive while in python they are not: Given some array x, x(1:5) is a 5-element array in Yorick, but in Python, x[1:5] is a 4-element array.

  • Yorick doesn't handle history natively. Do alias yorick='rlwrap yorick'.

  • In Yorick, any variable name can be referenced without error, even if it hasn't been defined:

    > x = blah
    > x
    []
    > double(seriously_not_a_variable)
    0
    
  • Unlike Python, objects are copied upon assignment.

    Python:

    >>> x = [1, 2, 3, 4]
    >>> y = x  # y and x now point to the same list
    >>> x[2] = 10  # changing the list is reflected in both
    >>> x
    [1, 2, 10, 4]
    >>> y
    [1, 2, 10, 4]

    Yorick:

    > x = [1, 2, 3, 4]
    > y = x  /* this performs a copy */
    > x(2) = 10
    > x
    [1,10,3,4]
    > y  /* y is unchanged */
    [1,2,3,4]
    

    However, Yeti "hash tables" do not copy upon assignment:

    z = h_new("foo", y)
    

    Changing z.foo will change y. They point to the same object.

  • Following the C influence, there are no multiple return values (tuples). Multiple return values are handled as in C: a function defined with function foo(&bar) can reassign bar and have the changes reflect to the caller. (Apparently, with the &, the variable is evaluated in the caller's scope?)

  • The function dimsof(<array>) doesn't return dimensions of the array: [d1, d2, d3, ...]. Instead, the first element is the number of dimensions: [ndim, d1, d2, d3, ...].

Clone this wiki locally