Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#501 translate matrix[1], list[1,2] wrong/FIX

closed
nobody
None
5
2005-12-06
2004-01-29
Stavros Macrakis
No

firstrow(m):=m[1]$
firstrow(matrix([a,b],[c,d])) => [a,b] OK
translate(firstrow)$
firstrow(matrix([a,b],[c,d])) => false NO!

oneone(m):=m[1,1]$
oneone([1,2,3]) => error OK
translate(oneone)$
oneone([1,2,3]) => 1 NO!

Here is the patch to maref1 to fix these cases:

((and (= (length inds) 1)
(or ($listp ar) ($matrixp ar)))
(nth (first inds) ar))
((and ($matrixp ar) (= (length inds) 2))
(nth (second inds) (nth (first inds) ar)))

Discussion

  • Raymond Toy
    Raymond Toy
    2004-11-23

    Logged In: YES
    user_id=28849

    Is this the desired patch you wanted? This function passes
    the tests you have listed here.

    But the untranslated oneone([1,2,3]) returns a nice error
    message about wrong number of indices. The translated
    version now just says it's "not a valid array reference ..."

    (defun maref1 (ar &rest inds &aux )
    (let ((.type. (#. *primitive-data-type-function* ar)))
    (cond
    ((one-of-types .type. (make-array 3)) (apply
    #'aref ar inds))
    ((one-of-types .type. (make-hash-table :test 'equal))
    (gethash (if (cdr inds) inds (car inds)) ar))
    ((one-of-types .type. 'a) `((,ar array) ,@
    (copy-list inds)))
    ((and (= (length inds) 1)
    (or ($listp ar) ($matrixp ar)))
    (nth (first inds) ar))
    ((and ($matrixp ar) (= (length inds) 2))
    (nth (second inds) (nth (first inds) ar)))
    (t (error "not a valid array reference to ~A" ar)))))

     
  • Raymond Toy
    Raymond Toy
    2005-12-06

    Logged In: YES
    user_id=28849

    Suggested fix applied, and modified error message to match
    what the interpreter does.

     
  • Raymond Toy
    Raymond Toy
    2005-12-06

    • status: open --> closed