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.

  • 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]
    
  • 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