Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #34852 > unrolled thread
| Started by | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| First post | 2014-12-09 05:13 +0000 |
| Last post | 2014-12-13 09:00 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.forth
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Simple Forth problem "WJ" <w_a_x_man@yahoo.com> - 2014-12-09 05:13 +0000
Re: Simple Forth problem mix <mix@test.net> - 2014-12-13 08:58 +0000
Re: Simple Forth problem mix <mix@test.net> - 2014-12-13 09:00 +0000
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2014-12-09 05:13 +0000 |
| Subject | Re: Simple Forth problem |
| Message-ID | <m660cv$7uo$1@dont-email.me> |
WJ wrote: > Make a list of the elements that are found in both lists > at the same index. > > OCaml: > > > open List;; > map fst > (filter (fun (x,y) -> x=y) > (combine [3;5;7;8;12] [2;5;8;10;12]));; > > [5; 12] > > > Using the piping operator (|>): > > > combine [3;5;7;8;12] [2;5;8;10;12] |> > filter (fun (x,y) -> x=y) |> > map fst ;; > > > Since every gavino "knows" that Forth amplifies programmer productivity, > let's see several Forth solutions that are more concise than the > OCaml ones. Gauche Scheme: (use srfi-42) (list-ec (:parallel (: x '(3 5 7 8 12)) (: y '(2 5 8 10 12))) (if (= x y)) x) ===> (5 12)
[toc] | [next] | [standalone]
| From | mix <mix@test.net> |
|---|---|
| Date | 2014-12-13 08:58 +0000 |
| Message-ID | <m6gv0v$9ov$1@news.mixmin.net> |
| In reply to | #34852 |
"WJ" <w_a_x_man@yahoo.com> wrote: > WJ wrote: > >> Make a list of the elements that are found in both lists >> at the same index. >> >> OCaml: >> >> >> open List;; >> map fst >> (filter (fun (x,y) -> x=y) >> (combine [3;5;7;8;12] [2;5;8;10;12]));; >> >> [5; 12] >> >> >> Using the piping operator (|>): >> >> >> combine [3;5;7;8;12] [2;5;8;10;12] |> >> filter (fun (x,y) -> x=y) |> >> map fst ;; >> >> >> Since every gavino "knows" that Forth amplifies programmer productivity, >> let's see several Forth solutions that are more concise than the >> OCaml ones. Not sure if your request makes any sense. ANSI Forth have no such thing as "lists", but it provides you with the ways to create them. You seem to have no problems with using libraries in OCaml or Scheme. I assume you won't mind using one in Forth. I've never tried OCaml or Scheme before, but I know that in Forth language can be changed dramatically because of previously included source code files. It probably would be more fair to compare source code of translator (compiler or interpreter in case of other languages), then code of specific libraries, then the actual source code. Long time ago I wrote Forth translator for OS X using x86_64 assembler (GNU as). After I added some words, here is how your code looks like: ;[ ;[ 16 12 8 7 5 3 ]list ;[ 12 10 8 5 2 ]list combine-lists( x y = ) ]named-list resultingList resultingList print-list Output: 12 5 ok Not sure if I know what are lists in OCaml. This code is using arrays of cells preceding with a cell containing size of an array. With Forth, you can make your code look as concise as you want, if you keep ugly parts in other files (just like you did with your SP-Forth code). > Gauche Scheme: > > (use srfi-42) > (list-ec > (:parallel (: x '(3 5 7 8 12)) (: y '(2 5 8 10 12))) > (if (= x y)) > x) > > ===> > (5 12) -- mix x
[toc] | [prev] | [next] | [standalone]
| From | mix <mix@test.net> |
|---|---|
| Date | 2014-12-13 09:00 +0000 |
| Message-ID | <m6gv6o$a6u$1@news.mixmin.net> |
| In reply to | #34852 |
"WJ" <w_a_x_man@yahoo.com> wrote: > WJ wrote: > >> Make a list of the elements that are found in both lists >> at the same index. >> >> OCaml: >> >> >> open List;; >> map fst >> (filter (fun (x,y) -> x=y) >> (combine [3;5;7;8;12] [2;5;8;10;12]));; >> >> [5; 12] >> >> >> Using the piping operator (|>): >> >> >> combine [3;5;7;8;12] [2;5;8;10;12] |> >> filter (fun (x,y) -> x=y) |> >> map fst ;; >> >> >> Since every gavino "knows" that Forth amplifies programmer productivity, >> let's see several Forth solutions that are more concise than the >> OCaml ones. Not sure if your request makes any sense. ANSI Forth have no such thing as "lists", but it provides you with the ways to create them. You seem to have no problems with using libraries in OCaml or Scheme. I assume you won't mind using one in Forth. I've never tried OCaml or Scheme before, but I know that in Forth language can be changed dramatically because of previously included source code files. It probably would be more fair to compare source code of translator (compiler or interpreter in case of other languages), then code of specific libraries, then the actual source code. Long time ago I wrote Forth translator for OS X using x86_64 assembler (GNU as). After I added some words, here is how your code looks like: ;[ ;[ 16 12 8 7 5 3 ]list ;[ 12 10 8 5 2 ]list combine-lists( x y = ) ]named-list resultingList resultingList print-list Output: 12 5 ok Not sure if I know what are lists in OCaml. This code is using arrays of cells preceding with a cell containing size of an array. With Forth, you can make your code look as concise as you want, if you keep ugly parts in other files (just like you did with your SP-Forth code). > Gauche Scheme: > > (use srfi-42) > (list-ec > (:parallel (: x '(3 5 7 8 12)) (: y '(2 5 8 10 12))) > (if (= x y)) > x) > > ===> > (5 12) -- mix x
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web