Rosetta Code:Solve a Task: Difference between revisions

From Rosetta Code
Content added Content deleted
(Undo revision 126189 by 203.185.175.244 (talk) vandalism)
(LOGO)
Line 1: Line 1:
=={{header|LOGO}}==
So you'd like to solve a task? Great! Here's a brief walkthrough on how you might do that. While you may already have a task and a language in mind, we're going to assume the language is "Ayrch", and the task is [[Hello world]]. If the language you're familiar with doesn't already have a [[:Category:Programming Languages|presence on Rosetta Code]], consider going through the motions of [[Rosetta Code:Add a Language|adding a language]]. If you don't have a task in mind, check out our [[:Category:Unimplemented_tasks_by_language|lists of unsolved tasks]].


<lang LOGO>
=The Basics=


TO LISTVMD :A :F :C :NV
Quickly getting started, this is all you really need to do.
;PROCEDURE LISTVMD
;A = LIST
;F = ROWS
;C = COLS
;NV = NAME OF MATRIX / VECTOR NEW
;this procedure transform a list in matrix / vector square or rect


(LOCAL "CF "CC "NV "T "W)
==Copyright==
MAKE "CF 1
MAKE "CC 1
MAKE "NV (MDARRAY (LIST :F :C) 1)
MAKE "T :F * :C
FOR [Z 1 :T][MAKE "W ITEM :Z :A
MDSETITEM (LIST :CF :CC) :NV :W
MAKE "CC :CC + 1
IF :CC = :C + 1 [MAKE "CF :CF + 1 MAKE "CC 1]]
OUTPUT :NV
END
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


Please familiarize yourself with [[Rosetta Code:Copyrights|Rosetta Code's copyright policies]]. If you want the layman's summary: Don't post code you don't have permission to, and be aware that you're giving us (and others) permission to use it under specific conditions.


TO XX
==Solve the task==
; MAIN PROGRAM
It is best to read the task thoroughly, solve it, and check your solution ''before'' starting to edit the Rosetta Code page, (especially for tasks needing more than a very short solution).
;LRCVS 10.04.12
; THIS PROGRAM multiplies two "square" matrices / vector ONLY!!!
; THE RECTANGULAR NOT WORK!!!


CT CS HT
==Adding Code==


; FIRST DATA MATRIX / VECTOR
Language examples on each page are in alphabetical order, so you need to find where your example would fit. Once you've found that, click the "edit" link closest above the area where you want to insert your code, and add something like this to the bottom of the edit field:
MAKE "A [1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49]
MAKE "FA 5 ;"ROWS
MAKE "CA 5 ;"COLS


; SECOND DATA MATRIX / VECTOR
<pre>=={{header|Ayrch}}==
MAKE "B [2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50]
MAKE "FB 5 ;"ROWS
MAKE "CB 5 ;"COLS


<lang Ayrch>PRINT "Goodbye, World!"</lang></pre>


IF (OR :FA <> :CA :FB <>:CB) [PRINT "Las_matrices/vector_no_son_cuadradas THROW
Remember, for the sake of simplicity, we're assuming your language is Ayrch, and the task is [[Hello world]]. We're also assuming, for the moment, that Ayrch looks a lot like BASIC.
"TOPLEVEL ]
IFELSE (OR :CA <> :FB :FA <> :CB) [PRINT
"Las_matrices/vector_no_son_compatibles THROW "TOPLEVEL ][MAKE "MA LISTVMD :A
:FA :CA "MA MAKE "MB LISTVMD :B :FB :CB "MB] ;APPLICATION <<< "LISTVMD"


PRINT (LIST "THIS_IS: "ROWS "X "COLS)
Once you've added your code, hit the preview button to make sure you crossed all your T's and closed all your tags. If the language name shows up in red (a broken link), then either the language doesn't exist on the site yet (as a category), or you misspelled/mis-capitalized the name. Check your spelling against the one in [[:Category:Programming Languages]].
PRINT []
PRINT (LIST :MA "=_M1 :FA "ROWS "X :CA "COLS)
PRINT []
PRINT (LIST :MB "=_M2 :FA "ROWS "X :CA "COLS)
PRINT []


That's all you really need to do!


MAKE "T :FA * :CB
=Going a little further=
MAKE "RE (ARRAY :T 1)


If you want to give your code that spit and polish shine, there are a few more steps you can take.


MAKE "CO 0
==Comments and Description==
FOR [AF 1 :CA][
FOR [AC 1 :CA][
MAKE "TEMP 0
FOR [I 1 :CA ][
MAKE "TEMP :TEMP + (MDITEM (LIST :I :AF) :MA) * (MDITEM (LIST :AC :I) :MB)]
MAKE "CO :CO + 1
SETITEM :CO :RE :TEMP]]


Consider adding descriptions to your code examples, to help the reader understand what's going on. This is particularly helpful if your code or language paradigms are very unlike ones that are already commonly known. Regardless, it's considered good practice in any environment where you would like other people to understand what you've written.


PRINT []
==Libraries==
PRINT (LIST "THIS_IS: :FA "ROWS "X :CB "COLS)
SHOW LISTVMD :RE :FA :CB "TO ;APPLICATION <<< "LISTVMD"
END


It's perfectly all right to depend on external (or even non-standard) libraries in your code examples. However, it can be problematic for others if they don't know they need to use a library, or don't know where to find it. There's a template for that: '''libheader'''.


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\
<pre>=={{header|Ayrch}}==


{{libheader|Ayrch Console Extensions}}


M1 * M2 RESULT / SOLUTION
<lang ayrch>PRINT "Goodbye World!"</lang></pre>


1 3 5 7 9 2 4 6 8 10 830 1880 2930 3980 5030
The '''libheader''' template identifies that your code uses that library, and will even provide a link to where a description of that library may be found.
11 13 15 17 19 12 14 16 18 20 890 2040 3190 4340 5490
21 23 25 27 29 X 22 24 26 28 30 = 950 2200 3450 4700 5950
31 33 35 37 39 32 34 36 38 40 1010 2360 3710 5060 6410
41 43 45 47 49 42 44 46 48 50 1070 2520 3970 5420 6870


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\
==Works With==
Not all code works with all versions of a language, all versions of a compiler, interpreter or other implementation, or even all operating systems that the language may run on. If you're aware of certain constraints or other prerequisites that haven't already been mentioned, try using the '''works with''' template.


<pre>=={{header|Ayrch}}==


NOW IN LOGO!!!!
{{works with|Ayrch Virtual Machine|6.2}}


<lang ayrch>PRINT "Goodbye World!"</lang></pre>


THIS_IS: ROWS X COLS
=Conclusion=


{{1 3 5 7 9} {11 13 15 17 19} {21 23 25 27 29} {31 33 35 37 39} {41 43 45 47
Thank you for adding code, and even more thanks of you added the spit and polish to make your code shine!
49}} =_M1 5 ROWS X 5 COLS


{{2 4 6 8 10} {12 14 16 18 20} {22 24 26 28 30} {32 34 36 38 40} {42 44 46 48
==Where to go?==
50}} =_M2 5 ROWS X 5 COLS



Now that you've solved one task, you might like to be reminded that there are [[:Category:Unimplemented_tasks_by_language|lists of all the unsolved tasks]] for all of the languages that have a presence on Rosetta Code. If your preferred language isn't there, then you may need to go through the motions of [[Rosetta Code:Add a Language|adding a language]] in order to get the site software to automatically generate the list.
THIS_IS: 5 ROWS X 5 COLS
{{830 1880 2930 3980 5030} {890 2040 3190 4340 5490} {950 2200 3450 4700 5950}
{1010 2360 3710 5060 6410} {1070 2520 3970 5420 6870}}


</lang>

Revision as of 09:37, 10 April 2012

<lang LOGO>

TO LISTVMD :A :F :C :NV

PROCEDURE LISTVMD
A = LIST
F = ROWS
C = COLS
NV = NAME OF MATRIX / VECTOR NEW
this procedure transform a list in matrix / vector square or rect

(LOCAL "CF "CC "NV "T "W) MAKE "CF 1 MAKE "CC 1 MAKE "NV (MDARRAY (LIST :F :C) 1) MAKE "T :F * :C FOR [Z 1 :T][MAKE "W ITEM :Z :A MDSETITEM (LIST :CF :CC) :NV :W MAKE "CC :CC + 1 IF :CC = :C + 1 [MAKE "CF :CF + 1 MAKE "CC 1]] OUTPUT :NV END


TO XX

MAIN PROGRAM
LRCVS 10.04.12
THIS PROGRAM multiplies two "square" matrices / vector ONLY!!!
THE RECTANGULAR NOT WORK!!!

CT CS HT

FIRST DATA MATRIX / VECTOR

MAKE "A [1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49] MAKE "FA 5 ;"ROWS MAKE "CA 5 ;"COLS

SECOND DATA MATRIX / VECTOR

MAKE "B [2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50] MAKE "FB 5 ;"ROWS MAKE "CB 5 ;"COLS


IF (OR :FA <> :CA :FB <>:CB) [PRINT "Las_matrices/vector_no_son_cuadradas THROW "TOPLEVEL ] IFELSE (OR :CA <> :FB :FA <> :CB) [PRINT "Las_matrices/vector_no_son_compatibles THROW "TOPLEVEL ][MAKE "MA LISTVMD :A

FA :CA "MA MAKE "MB LISTVMD :B :FB :CB "MB] ;APPLICATION <<< "LISTVMD"

PRINT (LIST "THIS_IS: "ROWS "X "COLS) PRINT [] PRINT (LIST :MA "=_M1 :FA "ROWS "X :CA "COLS) PRINT [] PRINT (LIST :MB "=_M2 :FA "ROWS "X :CA "COLS) PRINT []


MAKE "T :FA * :CB MAKE "RE (ARRAY :T 1)


MAKE "CO 0 FOR [AF 1 :CA][ FOR [AC 1 :CA][ MAKE "TEMP 0 FOR [I 1 :CA ][ MAKE "TEMP :TEMP + (MDITEM (LIST :I :AF) :MA) * (MDITEM (LIST :AC :I) :MB)] MAKE "CO :CO + 1 SETITEM :CO :RE :TEMP]]


PRINT [] PRINT (LIST "THIS_IS: :FA "ROWS "X :CB "COLS) SHOW LISTVMD :RE :FA :CB "TO ;APPLICATION <<< "LISTVMD" END


\


              M1 * M2 RESULT / SOLUTION
1  3  5  7  9    2  4  6  8 10    830 1880 2930 3980 5030

11 13 15 17 19 12 14 16 18 20 890 2040 3190 4340 5490 21 23 25 27 29 X 22 24 26 28 30 = 950 2200 3450 4700 5950 31 33 35 37 39 32 34 36 38 40 1010 2360 3710 5060 6410 41 43 45 47 49 42 44 46 48 50 1070 2520 3970 5420 6870

\


NOW IN LOGO!!!!


THIS_IS: ROWS X COLS

{{1 3 5 7 9} {11 13 15 17 19} {21 23 25 27 29} {31 33 35 37 39} {41 43 45 47 49}} =_M1 5 ROWS X 5 COLS

{{2 4 6 8 10} {12 14 16 18 20} {22 24 26 28 30} {32 34 36 38 40} {42 44 46 48 50}} =_M2 5 ROWS X 5 COLS


THIS_IS: 5 ROWS X 5 COLS {{830 1880 2930 3980 5030} {890 2040 3190 4340 5490} {950 2200 3450 4700 5950} {1010 2360 3710 5060 6410} {1070 2520 3970 5420 6870}}


</lang>