Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #18656 > unrolled thread
| Started by | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| First post | 2013-01-11 04:22 -0800 |
| Last post | 2013-01-21 23:40 -0800 |
| Articles | 20 on this page of 108 — 25 participants |
Back to article view | Back to comp.lang.forth
structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 04:22 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Alex McDonald <blog@rivadpm.com> - 2013-01-11 05:47 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-11 06:12 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 06:18 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-11 06:20 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-11 06:19 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 06:38 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-11 06:51 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 07:10 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 07:58 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth rickman <gnuarm@gmail.com> - 2013-01-14 10:01 -0500
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 06:25 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 06:28 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-11 06:33 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 06:37 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-11 06:56 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 08:03 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 08:06 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-11 12:27 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-13 17:32 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-13 23:21 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-13 23:41 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Paul Rubin <no.email@nospam.invalid> - 2013-01-13 23:43 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-14 00:02 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Elizabeth D. Rather" <erather@forth.com> - 2013-01-14 22:43 +1300
Re: structure and interpretation of computer programs exercsie 1.3 in forth Paul Rubin <no.email@nospam.invalid> - 2013-01-14 02:41 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-01-14 11:13 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-01-14 11:16 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth mhx@iae.nl (Marcel Hendrix) - 2013-01-14 21:27 +0200
Re: structure and interpretation of computer programs exercsie 1.3 in forth Howerd <howerdo@yahoo.co.uk> - 2013-01-14 03:34 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-14 12:53 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Elizabeth D. Rather" <erather@forth.com> - 2013-01-17 17:31 +1300
Re: structure and interpretation of computer programs exercsie 1.3 in forth Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-01-21 19:35 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Paul Rubin <no.email@nospam.invalid> - 2013-01-14 02:55 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth rickman <gnuarm@gmail.com> - 2013-01-14 10:14 -0500
Re: structure and interpretation of computer programs exercsie 1.3 in forth Bernd Paysan <bernd.paysan@gmx.de> - 2013-01-14 20:04 +0100
Re: structure and interpretation of computer programs exercsie 1.3 in forth Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-01-21 19:57 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-21 23:19 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-01-24 18:58 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Alex McDonald <blog@rivadpm.com> - 2013-01-25 15:46 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Pablo Hugo Reda <pabloreda@gmail.com> - 2013-01-25 19:09 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Alex McDonald <blog@rivadpm.com> - 2013-01-26 01:12 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth mhx@iae.nl (Marcel Hendrix) - 2013-01-26 12:58 +0200
Re: structure and interpretation of computer programs exercsie 1.3 in forth Alex McDonald <blog@rivadpm.com> - 2013-01-26 04:42 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-01-26 14:35 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-21 22:38 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-11 12:36 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-13 17:33 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Elizabeth D. Rather" <erather@forth.com> - 2013-01-14 22:46 +1300
Re: structure and interpretation of computer programs exercsie 1.3 in forth rickman <gnuarm@gmail.com> - 2013-01-14 10:20 -0500
Re: structure and interpretation of computer programs exercsie 1.3 in forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-01-14 10:41 -0600
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Elizabeth D. Rather" <erather@forth.com> - 2013-01-17 17:34 +1300
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-21 22:48 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-21 22:49 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-21 23:55 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Ed" <invalid@nospam.com> - 2013-01-18 12:50 +1100
Re: structure and interpretation of computer programs exercsie 1.3 in forth Bernd Paysan <bernd.paysan@gmx.de> - 2013-01-18 23:31 +0100
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Ed" <invalid@nospam.com> - 2013-01-20 12:42 +1100
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <markrobertwills@yahoo.co.uk> - 2013-01-20 01:24 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-01-20 15:51 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Elizabeth D. Rather" <erather@forth.com> - 2013-01-21 22:14 +1300
Re: structure and interpretation of computer programs exercsie 1.3 in forth Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-01-21 19:14 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth "A. K." <akk@nospam.org> - 2013-01-20 11:13 +0100
Re: structure and interpretation of computer programs exercsie 1.3 in forth Paul Rubin <no.email@nospam.invalid> - 2013-01-20 02:45 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-21 17:14 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth Paul Rubin <no.email@nospam.invalid> - 2013-01-23 01:52 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-01-23 04:25 -0600
Re: structure and interpretation of computer programs exercsie 1.3 in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-23 15:20 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth Paul Rubin <no.email@nospam.invalid> - 2013-01-23 09:29 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-23 17:40 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth Paul Rubin <no.email@nospam.invalid> - 2013-01-23 22:03 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Elizabeth D. Rather" <erather@forth.com> - 2013-01-24 22:13 +1300
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-24 02:57 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Paul Rubin <no.email@nospam.invalid> - 2013-01-26 13:49 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Elizabeth D. Rather" <erather@forth.com> - 2013-01-26 12:40 -1000
Re: structure and interpretation of computer programs exercsie 1.3 in forth Paul Rubin <no.email@nospam.invalid> - 2013-01-26 23:20 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth mhx@iae.nl (Marcel Hendrix) - 2013-01-27 09:52 +0200
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Paul E. Bennett" <Paul_E.Bennett@topmail.co.uk> - 2013-01-23 23:05 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-21 17:05 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth "A. K." <akk@nospam.org> - 2013-01-21 19:28 +0100
Re: structure and interpretation of computer programs exercsie 1.3 in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-22 17:43 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth "Paul E. Bennett" <Paul_E.Bennett@topmail.co.uk> - 2013-01-22 19:12 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth stephenXXX@mpeforth.com (Stephen Pelc) - 2013-01-21 12:13 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-21 17:28 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-22 18:06 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth Bernd Paysan <bernd.paysan@gmx.de> - 2013-01-22 19:30 +0100
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-21 23:06 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-22 02:20 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-22 03:36 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-22 06:51 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth marko <marko@marko.marko> - 2013-01-24 22:14 +1100
Re: structure and interpretation of computer programs exercsie 1.3 in forth the_gavino_himself <visphatesjava@gmail.com> - 2013-01-27 20:39 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth marko <marko@marko.marko> - 2013-02-01 22:07 +1100
Re: structure and interpretation of computer programs exercsie 1.3 in forth marko <marko@marko.marko> - 2013-02-01 22:53 +1100
Re: structure and interpretation of computer programs exercsie 1.3 in forth the_gavino_himself <visphatesjava@gmail.com> - 2013-02-08 19:50 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Elizabeth D Rather <erather@forth.com> - 2013-02-08 19:22 -1000
Re: structure and interpretation of computer programs exercsie 1.3 in forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-01-11 11:44 -0600
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-11 12:34 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-11 06:18 -0800
Re:structure and interpretation of computer programs exercsie 1.3 in forth Hans Bezemer <the.beez.speaks@gmail.com> - 2013-01-14 00:13 +0100
Re: structure and interpretation of computer programs exercsie 1.3 in forth Doug Hoffman <glidedog@gmail.com> - 2013-01-13 19:12 -0500
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-13 18:26 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2013-01-14 08:29 +0000
Re: structure and interpretation of computer programs exercsie 1.3 in forth Hans Bezemer <the.beez.speaks@gmail.com> - 2013-01-14 23:52 +0100
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-13 18:31 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-13 23:19 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth gavino_himself <visploveslisp@gmail.com> - 2013-01-21 22:46 -0800
Re: structure and interpretation of computer programs exercsie 1.3 in forth Mark Wills <forthfreak@gmail.com> - 2013-01-21 23:40 -0800
Page 1 of 6 [1] 2 3 4 5 6 Next page →
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-11 04:22 -0800 |
| Subject | structure and interpretation of computer programs exercsie 1.3 in forth |
| Message-ID | <f656a1dc-e406-4993-94a9-e9ff02da6a4d@googlegroups.com> |
Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. Please post a forth solution.
[toc] | [next] | [standalone]
| From | Alex McDonald <blog@rivadpm.com> |
|---|---|
| Date | 2013-01-11 05:47 -0800 |
| Message-ID | <563c9f3b-4038-4a70-bde0-9ab80453fd5d@po6g2000pbb.googlegroups.com> |
| In reply to | #18656 |
On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > Please post a forth solution. First you should post how you might go about doing it by hand. Describe how you might take 3 numbers and work out the sum of the squares of the two larger numbers.
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-01-11 06:12 -0800 |
| Message-ID | <1397e657-408f-47ce-bd1f-39fafe74d88a@17g2000vba.googlegroups.com> |
| In reply to | #18657 |
On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > Please post a forth solution. > > First you should post how you might go about doing it by hand. > Describe how you might take 3 numbers and work out the sum of the > squares of the two larger numbers. Alex, I hear you, but there's no chance of Gavino being able to concentrate on *anything* for that long. I'd be surprised if he can piss while standing up! Nicely factored: : swap? ( n1 n2 -- n1 n2 | n2 n1) 2dup < if swap then ; : gavino ( n1 n2 n3 - n) swap? rot swap? drop dup * swap dup * + ;
[toc] | [prev] | [next] | [standalone]
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-11 06:18 -0800 |
| Message-ID | <48084318-ec3d-40b9-a895-0b0a218da287@googlegroups.com> |
| In reply to | #18658 |
On Friday, January 11, 2013 6:12:45 AM UTC-8, M.R.W Wills wrote: > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > Please post a forth solution. > > > > > > First you should post how you might go about doing it by hand. > > > Describe how you might take 3 numbers and work out the sum of the > > > squares of the two larger numbers. > > > > Alex, > > > > I hear you, but there's no chance of Gavino being able to concentrate > > on *anything* for that long. I'd be surprised if he can piss while > > standing up! > > > > Nicely factored: > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > 2dup < if swap then ; > > > > : gavino ( n1 n2 n3 - n) > > swap? rot swap? drop dup * swap dup * + ; Id be suprised if you get laid by a good looking woman in 10 years past :)
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-01-11 06:20 -0800 |
| Message-ID | <f0ce4741-627a-47ab-8ae2-4345c0cdf96c@4g2000yqv.googlegroups.com> |
| In reply to | #18660 |
On Jan 11, 2:18 pm, gavino_himself <visplovesl...@gmail.com> wrote: > On Friday, January 11, 2013 6:12:45 AM UTC-8, M.R.W Wills wrote: > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > Please post a forth solution. > > > > First you should post how you might go about doing it by hand. > > > > Describe how you might take 3 numbers and work out the sum of the > > > > squares of the two larger numbers. > > > Alex, > > > I hear you, but there's no chance of Gavino being able to concentrate > > > on *anything* for that long. I'd be surprised if he can piss while > > > standing up! > > > Nicely factored: > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > 2dup < if swap then ; > > > : gavino ( n1 n2 n3 - n) > > > swap? rot swap? drop dup * swap dup * + ; > > Id be suprised if you get laid by a good looking woman in 10 years past :)- Hide quoted text - > > - Show quoted text - Ahem! I couldn't possibly comment ;-)
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-01-11 06:19 -0800 |
| Message-ID | <89de03df-c1ea-441c-9884-6d231bf9cc7d@p17g2000vbn.googlegroups.com> |
| In reply to | #18658 |
On Jan 11, 2:12 pm, Mark Wills <forthfr...@gmail.com> wrote: > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > Please post a forth solution. > > > First you should post how you might go about doing it by hand. > > Describe how you might take 3 numbers and work out the sum of the > > squares of the two larger numbers. > > Alex, > > I hear you, but there's no chance of Gavino being able to concentrate > on *anything* for that long. I'd be surprised if he can piss while > standing up! > > Nicely factored: > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > 2dup < if swap then ; > > : gavino ( n1 n2 n3 - n) > swap? rot swap? drop dup * swap dup * + ; I doubt if you can concentrate long enough to fathom it, since you're busy being both rich and a published author and all that, so here goes: swap? rot swap? drop It's a very simple bubble-sort - worse case 2 swaps required where we bring the lowest number to the top of the stack and then drop it. We then square the two remaining numbers and add their sums: dup * swap dup * +
[toc] | [prev] | [next] | [standalone]
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-11 06:38 -0800 |
| Message-ID | <e4a00ff0-a6e0-44c8-b1b2-ada27e1bbb9e@googlegroups.com> |
| In reply to | #18661 |
On Friday, January 11, 2013 6:19:30 AM UTC-8, M.R.W Wills wrote: > On Jan 11, 2:12 pm, Mark Wills <forthfr...@gmail.com> wrote: > > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > > Please post a forth solution. > > > > > > > First you should post how you might go about doing it by hand. > > > > Describe how you might take 3 numbers and work out the sum of the > > > > squares of the two larger numbers. > > > > > > Alex, > > > > > > I hear you, but there's no chance of Gavino being able to concentrate > > > on *anything* for that long. I'd be surprised if he can piss while > > > standing up! > > > > > > Nicely factored: > > > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > 2dup < if swap then ; > > > > > > : gavino ( n1 n2 n3 - n) > > > swap? rot swap? drop dup * swap dup * + ; > > > > I doubt if you can concentrate long enough to fathom it, since you're > > busy being both rich and a published author and all that, so here > > goes: > > > > swap? rot swap? drop > > > > It's a very simple bubble-sort - worse case 2 swaps required where we > > bring the lowest number to the top of the stack and then drop it. > > > > We then square the two remaining numbers and add their sums: dup * > > swap dup * + step 2 I get step one has be puzzled a bit
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-01-11 06:51 -0800 |
| Message-ID | <19613220-0cbb-4013-8633-816284ae85fa@x20g2000vbf.googlegroups.com> |
| In reply to | #18667 |
On Jan 11, 2:38 pm, gavino_himself <visplovesl...@gmail.com> wrote: > On Friday, January 11, 2013 6:19:30 AM UTC-8, M.R.W Wills wrote: > > On Jan 11, 2:12 pm, Mark Wills <forthfr...@gmail.com> wrote: > > > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > Please post a forth solution. > > > > > First you should post how you might go about doing it by hand. > > > > > Describe how you might take 3 numbers and work out the sum of the > > > > > squares of the two larger numbers. > > > > Alex, > > > > I hear you, but there's no chance of Gavino being able to concentrate > > > > on *anything* for that long. I'd be surprised if he can piss while > > > > standing up! > > > > Nicely factored: > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > > 2dup < if swap then ; > > > > : gavino ( n1 n2 n3 - n) > > > > swap? rot swap? drop dup * swap dup * + ; > > > I doubt if you can concentrate long enough to fathom it, since you're > > > busy being both rich and a published author and all that, so here > > > goes: > > > swap? rot swap? drop > > > It's a very simple bubble-sort - worse case 2 swaps required where we > > > bring the lowest number to the top of the stack and then drop it. > > > We then square the two remaining numbers and add their sums: dup * > > > swap dup * + > > step 2 I get > > step one has be puzzled a bit- Hide quoted text - > > - Show quoted text - Step 1 is this: swap? rot swap? swap? looks at the top two numbers on the stack, and swaps them if the number on the top of stack is > than the one underneath it. So... If you have this on the stack: 12 16 19 after swap? you will get 12 19 16 So we have moved the smaller of the two numbers to the top. Now we need to check the 12 against top of stack, so we get the 12 to the top with a ROT, so now the stack looks like this: 19 16 12 and we do a swap? again. This time, swap? takes no action, because the lower number is already at the top. So we can safely drop the top number, giving us 19 16 Then it's a matter of DUPing them, adding them to together to square them, and summing them at the end.
[toc] | [prev] | [next] | [standalone]
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-11 07:10 -0800 |
| Message-ID | <5edca678-69ad-437b-9536-57ff6463528a@googlegroups.com> |
| In reply to | #18668 |
On Friday, January 11, 2013 6:51:06 AM UTC-8, M.R.W Wills wrote: > On Jan 11, 2:38 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > On Friday, January 11, 2013 6:19:30 AM UTC-8, M.R.W Wills wrote: > > > > On Jan 11, 2:12 pm, Mark Wills <forthfr...@gmail.com> wrote: > > > > > > > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > > > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > > > > Please post a forth solution. > > > > > > > > > First you should post how you might go about doing it by hand. > > > > > > > > > Describe how you might take 3 numbers and work out the sum of the > > > > > > > > > squares of the two larger numbers. > > > > > > > > Alex, > > > > > > > > I hear you, but there's no chance of Gavino being able to concentrate > > > > > > > > on *anything* for that long. I'd be surprised if he can piss while > > > > > > > > standing up! > > > > > > > > Nicely factored: > > > > > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > > > > > > 2dup < if swap then ; > > > > > > > > : gavino ( n1 n2 n3 - n) > > > > > > > > swap? rot swap? drop dup * swap dup * + ; > > > > > > > I doubt if you can concentrate long enough to fathom it, since you're > > > > > > > busy being both rich and a published author and all that, so here > > > > > > > goes: > > > > > > > swap? rot swap? drop > > > > > > > It's a very simple bubble-sort - worse case 2 swaps required where we > > > > > > > bring the lowest number to the top of the stack and then drop it. > > > > > > > We then square the two remaining numbers and add their sums: dup * > > > > > > > swap dup * + > > > > > > step 2 I get > > > > > > step one has be puzzled a bit- Hide quoted text - > > > > > > - Show quoted text - > > > > Step 1 is this: > > > > swap? rot swap? > > > > swap? looks at the top two numbers on the stack, and swaps them if the > > number on the top of stack is > than the one underneath it. > > > > So... If you have this on the stack: > > > > 12 16 19 > > > > after swap? you will get > > > > 12 19 16 > > > > So we have moved the smaller of the two numbers to the top. Now we > > need to check the 12 against top of stack, so we get the 12 to the top > > with a ROT, so now the stack looks like this: > > > > 19 16 12 > > > > and we do a swap? again. This time, swap? takes no action, because the > > lower number is already at the top. > > > > So we can safely drop the top number, giving us > > > > 19 16 > > > > Then it's a matter of DUPing them, adding them to together to square > > them, and summing them at the end. so simple once explained yet so awesome
[toc] | [prev] | [next] | [standalone]
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-11 07:58 -0800 |
| Message-ID | <68627ab5-cad7-4f70-bf0a-37bd652717da@googlegroups.com> |
| In reply to | #18668 |
On Friday, January 11, 2013 6:51:06 AM UTC-8, M.R.W Wills wrote: > On Jan 11, 2:38 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > On Friday, January 11, 2013 6:19:30 AM UTC-8, M.R.W Wills wrote: > > > > On Jan 11, 2:12 pm, Mark Wills <forthfr...@gmail.com> wrote: > > > > > > > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > > > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > > > > Please post a forth solution. > > > > > > > > > First you should post how you might go about doing it by hand. > > > > > > > > > Describe how you might take 3 numbers and work out the sum of the > > > > > > > > > squares of the two larger numbers. > > > > > > > > Alex, > > > > > > > > I hear you, but there's no chance of Gavino being able to concentrate > > > > > > > > on *anything* for that long. I'd be surprised if he can piss while > > > > > > > > standing up! > > > > > > > > Nicely factored: > > > > > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > > > > > > 2dup < if swap then ; > > > > > > > > : gavino ( n1 n2 n3 - n) > > > > > > > > swap? rot swap? drop dup * swap dup * + ; > > > > > > > I doubt if you can concentrate long enough to fathom it, since you're > > > > > > > busy being both rich and a published author and all that, so here > > > > > > > goes: > > > > > > > swap? rot swap? drop > > > > > > > It's a very simple bubble-sort - worse case 2 swaps required where we > > > > > > > bring the lowest number to the top of the stack and then drop it. > > > > > > > We then square the two remaining numbers and add their sums: dup * > > > > > > > swap dup * + > > > > > > step 2 I get > > > > > > step one has be puzzled a bit- Hide quoted text - > > > > > > - Show quoted text - > > > > Step 1 is this: > > > > swap? rot swap? > > > > swap? looks at the top two numbers on the stack, and swaps them if the > > number on the top of stack is > than the one underneath it. > > > > So... If you have this on the stack: > > > > 12 16 19 > > > > after swap? you will get > > > > 12 19 16 > > > > So we have moved the smaller of the two numbers to the top. Now we > > need to check the 12 against top of stack, so we get the 12 to the top > > with a ROT, so now the stack looks like this: > > > > 19 16 12 > > > > and we do a swap? again. This time, swap? takes no action, because the > > lower number is already at the top. > > > > So we can safely drop the top number, giving us > > > > 19 16 > > > > Then it's a matter of DUPing them, adding them to together to square > > them, and summing them at the end. What I am stuck on is the < in swap? I get you english explanation. but if the top 2 numbers are say 55 44 and < is used why do you say greater than in the english description?
[toc] | [prev] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2013-01-14 10:01 -0500 |
| Message-ID | <kd16nq$sk0$1@dont-email.me> |
| In reply to | #18671 |
On 1/11/2013 10:58 AM, gavino_himself wrote: > On Friday, January 11, 2013 6:51:06 AM UTC-8, M.R.W Wills wrote: >> On Jan 11, 2:38 pm, gavino_himself<visplovesl...@gmail.com> wrote: >> >>> On Friday, January 11, 2013 6:19:30 AM UTC-8, M.R.W Wills wrote: >> >>>> On Jan 11, 2:12 pm, Mark Wills<forthfr...@gmail.com> wrote: >> >>> >> >>>>> On Jan 11, 1:47 pm, Alex McDonald<b...@rivadpm.com> wrote: >> >>> >> >>>>>> On Jan 11, 12:22 pm, gavino_himself<visplovesl...@gmail.com> wrote: >> >>> >> >>>>>>> Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. >> >>> >> >>>>>>> Please post a forth solution. >> >>> >> >>>>>> First you should post how you might go about doing it by hand. >> >>> >> >>>>>> Describe how you might take 3 numbers and work out the sum of the >> >>> >> >>>>>> squares of the two larger numbers. >> >>> >> >>>>> Alex, >> >>> >> >>>>> I hear you, but there's no chance of Gavino being able to concentrate >> >>> >> >>>>> on *anything* for that long. I'd be surprised if he can piss while >> >>> >> >>>>> standing up! >> >>> >> >>>>> Nicely factored: >> >>> >> >>>>> : swap? ( n1 n2 -- n1 n2 | n2 n1) >> >>> >> >>>>> 2dup< if swap then ; >> >>> >> >>>>> : gavino ( n1 n2 n3 - n) >> >>> >> >>>>> swap? rot swap? drop dup * swap dup * + ; >> >>> >> >>>> I doubt if you can concentrate long enough to fathom it, since you're >> >>> >> >>>> busy being both rich and a published author and all that, so here >> >>> >> >>>> goes: >> >>> >> >>>> swap? rot swap? drop >> >>> >> >>>> It's a very simple bubble-sort - worse case 2 swaps required where we >> >>> >> >>>> bring the lowest number to the top of the stack and then drop it. >> >>> >> >>>> We then square the two remaining numbers and add their sums: dup * >> >>> >> >>>> swap dup * + >> >>> >> >>> step 2 I get >> >>> >> >>> step one has be puzzled a bit- Hide quoted text - >> >>> >> >>> - Show quoted text - >> >> >> >> Step 1 is this: >> >> >> >> swap? rot swap? >> >> >> >> swap? looks at the top two numbers on the stack, and swaps them if the >> >> number on the top of stack is> than the one underneath it. >> >> >> >> So... If you have this on the stack: >> >> >> >> 12 16 19 >> >> >> >> after swap? you will get >> >> >> >> 12 19 16 >> >> >> >> So we have moved the smaller of the two numbers to the top. Now we >> >> need to check the 12 against top of stack, so we get the 12 to the top >> >> with a ROT, so now the stack looks like this: >> >> >> >> 19 16 12 >> >> >> >> and we do a swap? again. This time, swap? takes no action, because the >> >> lower number is already at the top. >> >> >> >> So we can safely drop the top number, giving us >> >> >> >> 19 16 >> >> >> >> Then it's a matter of DUPing them, adding them to together to square >> >> them, and summing them at the end. > > What I am stuck on is the< in swap? > > I get you english explanation. > > but if the top 2 numbers are say 55 44 and< is used why do you say greater than in the english description? I would answer this, but it is ***so*** hard to follow when you don't trim your quotes to the parts you are talking about... Rick
[toc] | [prev] | [next] | [standalone]
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-11 06:25 -0800 |
| Message-ID | <09608d85-e6f7-4c33-938e-371e2b800dc9@googlegroups.com> |
| In reply to | #18658 |
On Friday, January 11, 2013 6:12:45 AM UTC-8, M.R.W Wills wrote: > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > Please post a forth solution. > > > > > > First you should post how you might go about doing it by hand. > > > Describe how you might take 3 numbers and work out the sum of the > > > squares of the two larger numbers. > > > > Alex, > > > > I hear you, but there's no chance of Gavino being able to concentrate > > on *anything* for that long. I'd be surprised if he can piss while > > standing up! > > > > Nicely factored: > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > 2dup < if swap then ; > > > > : gavino ( n1 n2 n3 - n) > > swap? rot swap? drop dup * swap dup * + ; doesn't seem to work on gforth hmm
[toc] | [prev] | [next] | [standalone]
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-11 06:28 -0800 |
| Message-ID | <160a40f3-c0fe-4442-86fe-3a069caac701@googlegroups.com> |
| In reply to | #18663 |
On Friday, January 11, 2013 6:25:18 AM UTC-8, gavino_himself wrote: > On Friday, January 11, 2013 6:12:45 AM UTC-8, M.R.W Wills wrote: > > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > > > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > > > > > > > > > Please post a forth solution. > > > > > > > > > > > > > > First you should post how you might go about doing it by hand. > > > > > > > Describe how you might take 3 numbers and work out the sum of the > > > > > > > squares of the two larger numbers. > > > > > > > > > > > > Alex, > > > > > > > > > > > > I hear you, but there's no chance of Gavino being able to concentrate > > > > > > on *anything* for that long. I'd be surprised if he can piss while > > > > > > standing up! > > > > > > > > > > > > Nicely factored: > > > > > > > > > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > > > > 2dup < if swap then ; > > > > > > > > > > > > : gavino ( n1 n2 n3 - n) > > > > > > swap? rot swap? drop dup * swap dup * + ; > > > > doesn't seem to work on gforth > > hmm Actually it does work. in gforth NICE!!
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-01-11 06:33 -0800 |
| Message-ID | <2c2c13e1-86a2-4516-b7ca-98cb018bb374@ci3g2000vbb.googlegroups.com> |
| In reply to | #18663 |
On Jan 11, 2:25 pm, gavino_himself <visplovesl...@gmail.com> wrote: > On Friday, January 11, 2013 6:12:45 AM UTC-8, M.R.W Wills wrote: > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > Please post a forth solution. > > > > First you should post how you might go about doing it by hand. > > > > Describe how you might take 3 numbers and work out the sum of the > > > > squares of the two larger numbers. > > > Alex, > > > I hear you, but there's no chance of Gavino being able to concentrate > > > on *anything* for that long. I'd be surprised if he can piss while > > > standing up! > > > Nicely factored: > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > 2dup < if swap then ; > > > : gavino ( n1 n2 n3 - n) > > > swap? rot swap? drop dup * swap dup * + ; > > doesn't seem to work on gforth > hmm- Hide quoted text - > > - Show quoted text - Unfortunately I don't have GForth installed on my machine, but it works on my home-brew system. I think why it wouldn't work in Gforth though. Looks okay to me... Hmmm...
[toc] | [prev] | [next] | [standalone]
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-11 06:37 -0800 |
| Message-ID | <cd268454-c116-412a-8fb2-6434dd673c5c@googlegroups.com> |
| In reply to | #18665 |
On Friday, January 11, 2013 6:33:19 AM UTC-8, M.R.W Wills wrote: > On Jan 11, 2:25 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > On Friday, January 11, 2013 6:12:45 AM UTC-8, M.R.W Wills wrote: > > > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > > > Please post a forth solution. > > > > > > > > First you should post how you might go about doing it by hand. > > > > > > > > Describe how you might take 3 numbers and work out the sum of the > > > > > > > > squares of the two larger numbers. > > > > > > > Alex, > > > > > > > I hear you, but there's no chance of Gavino being able to concentrate > > > > > > > on *anything* for that long. I'd be surprised if he can piss while > > > > > > > standing up! > > > > > > > Nicely factored: > > > > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > > > > > 2dup < if swap then ; > > > > > > > : gavino ( n1 n2 n3 - n) > > > > > > > swap? rot swap? drop dup * swap dup * + ; > > > > > > doesn't seem to work on gforth > > > hmm- Hide quoted text - > > > > > > - Show quoted text - > > > > Unfortunately I don't have GForth installed on my machine, but it > > works on my home-brew system. I think why it wouldn't work in Gforth > > though. Looks okay to me... Hmmm... no no it works my mistake damnit now I am going to have to learn why b4 bed, in spite of my lack of concentration
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-01-11 06:56 -0800 |
| Message-ID | <0081330b-0432-4726-b573-754e1070bf16@x20g2000vbf.googlegroups.com> |
| In reply to | #18658 |
On Jan 11, 2:12 pm, Mark Wills <forthfr...@gmail.com> wrote:
> On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote:
>
> > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote:
>
> > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
>
> > > Please post a forth solution.
>
> > First you should post how you might go about doing it by hand.
> > Describe how you might take 3 numbers and work out the sum of the
> > squares of the two larger numbers.
>
> Alex,
>
> I hear you, but there's no chance of Gavino being able to concentrate
> on *anything* for that long. I'd be surprised if he can piss while
> standing up!
>
> Nicely factored:
>
> : swap? ( n1 n2 -- n1 n2 | n2 n1)
> 2dup < if swap then ;
>
> : gavino ( n1 n2 n3 - n)
> swap? rot swap? drop dup * swap dup * + ;
Actually, this is possibly "better" in the sense that it's smaller and
more efficient:
: gavino ( n1 n2 n3 - n)
2dup < if swap then rot max dup * swap dup * + ;
[toc] | [prev] | [next] | [standalone]
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-11 08:03 -0800 |
| Message-ID | <21782e98-42ad-48ec-bbba-55106a687a86@googlegroups.com> |
| In reply to | #18669 |
On Friday, January 11, 2013 6:56:35 AM UTC-8, M.R.W Wills wrote: > On Jan 11, 2:12 pm, Mark Wills <forthfr...@gmail.com> wrote: > > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > > Please post a forth solution. > > > > > > > First you should post how you might go about doing it by hand. > > > > Describe how you might take 3 numbers and work out the sum of the > > > > squares of the two larger numbers. > > > > > > Alex, > > > > > > I hear you, but there's no chance of Gavino being able to concentrate > > > on *anything* for that long. I'd be surprised if he can piss while > > > standing up! > > > > > > Nicely factored: > > > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > 2dup < if swap then ; > > > > > > : gavino ( n1 n2 n3 - n) > > > swap? rot swap? drop dup * swap dup * + ; > > > > Actually, this is possibly "better" in the sense that it's smaller and > > more efficient: > > > > : gavino ( n1 n2 n3 - n) > > 2dup < if swap then rot max dup * swap dup * + ; say you have 1 2 3 can you describe what this does? I am having trouble because < must be compiled following what happens. 2dup < if swap then ;
[toc] | [prev] | [next] | [standalone]
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-11 08:06 -0800 |
| Message-ID | <d061684e-00e3-4ec0-bda6-c6a95bab56a9@googlegroups.com> |
| In reply to | #18672 |
On Friday, January 11, 2013 8:03:13 AM UTC-8, gavino_himself wrote: > On Friday, January 11, 2013 6:56:35 AM UTC-8, M.R.W Wills wrote: > > > On Jan 11, 2:12 pm, Mark Wills <forthfr...@gmail.com> wrote: > > > > > > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > > > > > > > > > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > > > > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > > > > > > > > > > Please post a forth solution. > > > > > > > > > > > > > > > First you should post how you might go about doing it by hand. > > > > > > > > Describe how you might take 3 numbers and work out the sum of the > > > > > > > > squares of the two larger numbers. > > > > > > > > > > > > > > Alex, > > > > > > > > > > > > > > I hear you, but there's no chance of Gavino being able to concentrate > > > > > > > on *anything* for that long. I'd be surprised if he can piss while > > > > > > > standing up! > > > > > > > > > > > > > > Nicely factored: > > > > > > > > > > > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > > > > > 2dup < if swap then ; > > > > > > > > > > > > > > : gavino ( n1 n2 n3 - n) > > > > > > > swap? rot swap? drop dup * swap dup * + ; > > > > > > > > > > > > Actually, this is possibly "better" in the sense that it's smaller and > > > > > > more efficient: > > > > > > > > > > > > : gavino ( n1 n2 n3 - n) > > > > > > 2dup < if swap then rot max dup * swap dup * + ; > > > > > > > > say you have 1 2 3 > > can you describe what this does? > > I am having trouble because < must be compiled following what happens. > > 2dup < if swap then ; I guess it goes 1 2 3 then has 1 2 3 2 3 then < sees that 2 is less than 3 in the top 2, consuming them in the process, and executes swap, to produce 1 3 2 ok wow this takes a little getting used to I was confusing myself thinking that < too 3 off the top and made 3 < 2
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <forthfreak@gmail.com> |
|---|---|
| Date | 2013-01-11 12:27 -0800 |
| Message-ID | <848a9eb6-17a5-4893-b004-0adcbc10bed5@c14g2000vbd.googlegroups.com> |
| In reply to | #18673 |
On Jan 11, 4:06 pm, gavino_himself <visplovesl...@gmail.com> wrote: > On Friday, January 11, 2013 8:03:13 AM UTC-8, gavino_himself wrote: > > On Friday, January 11, 2013 6:56:35 AM UTC-8, M.R.W Wills wrote: > > > > On Jan 11, 2:12 pm, Mark Wills <forthfr...@gmail.com> wrote: > > > > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > Please post a forth solution. > > > > > > First you should post how you might go about doing it by hand. > > > > > > Describe how you might take 3 numbers and work out the sum of the > > > > > > squares of the two larger numbers. > > > > > Alex, > > > > > I hear you, but there's no chance of Gavino being able to concentrate > > > > > on *anything* for that long. I'd be surprised if he can piss while > > > > > standing up! > > > > > Nicely factored: > > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > > > 2dup < if swap then ; > > > > > : gavino ( n1 n2 n3 - n) > > > > > swap? rot swap? drop dup * swap dup * + ; > > > > Actually, this is possibly "better" in the sense that it's smaller and > > > > more efficient: > > > > : gavino ( n1 n2 n3 - n) > > > > 2dup < if swap then rot max dup * swap dup * + ; > > > say you have 1 2 3 > > > can you describe what this does? > > > I am having trouble because < must be compiled following what happens. > > > 2dup < if swap then ; > > I guess it goes 1 2 3 > then has 1 2 3 2 3 > then < sees that 2 is less than 3 in the top 2, consuming them in the process, and executes swap, to produce > 1 3 2 > > ok wow > > this takes a little getting used to > > I was confusing myself thinking that < too 3 off the top and made 3 < 2 That's exactly right. You got it. If you execute the following in Forth: 5 9 < What you are asking is "is 5 less than 9?". The answer is yes, so a TRUE flag will be left on the stack. Note also that < "consumes" its arguments (5 and 9 in this example) which is why you need a 2dup.
[toc] | [prev] | [next] | [standalone]
| From | gavino_himself <visploveslisp@gmail.com> |
|---|---|
| Date | 2013-01-13 17:32 -0800 |
| Message-ID | <cc31680b-d95e-447e-9824-06866c87ed8d@googlegroups.com> |
| In reply to | #18677 |
On Friday, January 11, 2013 12:27:34 PM UTC-8, M.R.W Wills wrote: > On Jan 11, 4:06 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > On Friday, January 11, 2013 8:03:13 AM UTC-8, gavino_himself wrote: > > > > On Friday, January 11, 2013 6:56:35 AM UTC-8, M.R.W Wills wrote: > > > > > > > > On Jan 11, 2:12 pm, Mark Wills <forthfr...@gmail.com> wrote: > > > > > > > > > On Jan 11, 1:47 pm, Alex McDonald <b...@rivadpm.com> wrote: > > > > > > > > > > On Jan 11, 12:22 pm, gavino_himself <visplovesl...@gmail.com> wrote: > > > > > > > > > > > Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. > > > > > > > > > > > Please post a forth solution. > > > > > > > > > > First you should post how you might go about doing it by hand. > > > > > > > > > > Describe how you might take 3 numbers and work out the sum of the > > > > > > > > > > squares of the two larger numbers. > > > > > > > > > Alex, > > > > > > > > > I hear you, but there's no chance of Gavino being able to concentrate > > > > > > > > > on *anything* for that long. I'd be surprised if he can piss while > > > > > > > > > standing up! > > > > > > > > > Nicely factored: > > > > > > > > > : swap? ( n1 n2 -- n1 n2 | n2 n1) > > > > > > > > > 2dup < if swap then ; > > > > > > > > > : gavino ( n1 n2 n3 - n) > > > > > > > > > swap? rot swap? drop dup * swap dup * + ; > > > > > > > > Actually, this is possibly "better" in the sense that it's smaller and > > > > > > > > more efficient: > > > > > > > > : gavino ( n1 n2 n3 - n) > > > > > > > > 2dup < if swap then rot max dup * swap dup * + ; > > > > > > > say you have 1 2 3 > > > > > > > can you describe what this does? > > > > > > > I am having trouble because < must be compiled following what happens. > > > > > > > 2dup < if swap then ; > > > > > > I guess it goes 1 2 3 > > > then has 1 2 3 2 3 > > > then < sees that 2 is less than 3 in the top 2, consuming them in the process, and executes swap, to produce > > > 1 3 2 > > > > > > ok wow > > > > > > this takes a little getting used to > > > > > > I was confusing myself thinking that < too 3 off the top and made 3 < 2 > > > > That's exactly right. You got it. > > > > If you execute the following in Forth: > > > > 5 9 < > > > > What you are asking is "is 5 less than 9?". The answer is yes, so a > > TRUE flag will be left on the stack. Note also that < "consumes" its > > arguments (5 and 9 in this example) which is why you need a 2dup. Mr Willis you have taught me some forth!!! I salute you. AWESOME I have not failed to notice how the forth solution is in fewer lines than the lisp solution!! I am now motivated to finish starting forth and read thinking forth. You have single handedly ressurected my motivation to explore forth!
[toc] | [prev] | [next] | [standalone]
Page 1 of 6 [1] 2 3 4 5 6 Next page →
Back to top | Article view | comp.lang.forth
csiph-web