Ask Your Question
1

LISP: globalni promenne a operace na 2d matici

asked 2015-04-09 21:19:42 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated 2015-04-10 18:00:11 +0100

anonymous user

Anonymous

Ahoj, predem chci rict, ze ulohu mam v C i v Lispu hotovou a funkcni, jen bych to chtel jeste vysperkovat, tak mam par (2) dotazu. Pisu sem, protoze jsem videl peknou odpoved v predchozim vlakne.

Moji ulohu resim pres globalni 2d matici sousednosti, kterou je potreba upravovat. (1) Jak nejjednoduseji lze mit matici jako lokalni promennou a menit/provadet na ni vypocty pomoci dalsich funkci?

(2) Jak funkcionalne zavolat n-krat relaxaci na kazdou hranu? Reseni pres 3 cykly asi je uplne spatne a hloupe to prepsat na rekurzi je jeste horsi. Ted mam:

(dotimes (k n) (dotimes (i n) (dotimes (j n) (relax i j))))

Predem moc dekuji za odpoved

edit retag flag offensive close delete

1 Answer

Sort by » oldest newest most voted
1

answered 2015-05-26 21:29:43 +0100

wvi gravatar image

updated 2015-05-27 00:43:23 +0100

Miro Hrončok gravatar image

1) Lexikalni scope. Pokud teda chapu spravne, ze stojis o data hiding, pokud ne, tak pak uplne nevim o cem je rec. Protoze let muzes mit i lokalne a funkce pracujici s matici pak volat a matici predavat paramterem.

   (let ((a (make-hidden-whatever)))
         (defun foo (x)
.           (change a).... )
         (defun bar (y)
          (modify a)......)
    )

K a lze pristupovat jen pres foo a bar

2) Rekurze je funkcionalni. Dalsi moznosti jsou treba volat mapcar pres radky/sloupce, tohle by asi chtelo vice kontextu, protoze zalezi na tom jak je matice realizovana, pres array nebo list? Inspirace z rosetta code pro nasobeni matic. http://rosettacode.org/wiki/Matrix_multiplication#Common_Lisp

edit flag offensive delete publish link more

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

Add answer

[hide preview]

Question tools

Follow
1 follower

Stats

Asked: 2015-04-09 21:19:42 +0100

Seen: 538 times

Last updated: May 27 '15