Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #25726
| From | "Alex McDonald" <blog@rivadpm.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Simple Forth problem |
| Date | 2013-09-17 16:53 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <l19tt1$fvn$1@dont-email.me> (permalink) |
| References | <l19804$g8k$1@dont-email.me> <844c148c-849f-4f6b-9b09-f78894f34c47@googlegroups.com> <hronr1bdzw8s$.i7lpb9cr071t.dlg@40tude.net> |
on 17/09/2013 16:05:48, Coos Haak wrote:
> Op Tue, 17 Sep 2013 03:28:52 -0700 (PDT) schreef VoidVolker:
>
>> вторник, 17 сентября 2013 г., 13:39:17 UTC+4 пользователь WJ написал:
>>> 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) -> xy)
>>>
>>> (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) -> xy) |>
>>>
>>> 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.
>>
>> http://www.nncron.ru/download/plugins/vv/lists.spf>
>> For named lists:
>>
>> LIST: l1
>> LIST: l2
>> l1[ 3 5 7 8 12 ]l1
>> l2[ 2 5 8 10 12 ]l2
>> : lists-compare
>> l1-- l2-- \ Init list iterators
>> BEGIN \ Start cicle
>> l1@ 0<> \ ? \ Compare curent node value of l1 with 0
>> l2@ 0<> \ ? ? \ Compare curent node value of l2 with 0
>> AND \ ? \
>> WHILE \ Cicle rule
>> l1@ l2@ \ ? \ Compare curent node values of lists
>> IF \ Check the flag on stack
>> l1@ . \ And do some actions
>> THEN \ Actions end
>> l1> l2> \ Switch list iterators to next nodes
>> REPEAT \ Cicle end
>> ;
>>
>> Start the code in console:
>> lists-compare
>> 5 12 Ok
>>
>> For noname lists:
>>
>> : lists-compare2 { l1 l2 -- }
>> l1 LIST-- l2 LIST--
>> BEGIN
>> l1 LIST@ 0<>
>> l2 LIST@ 0<>
>> AND
>> WHILE
>> l1 LIST@
>> l2 LIST@
>> IF
>> l1 LIST@ .
>> THEN
>> l1 LIST>
>> l2 LIST>
>> REPEAT
>> ;
>
> create l1 3 , 5 , 7 , 8 , 12 , 0 ,
> create l2 2 , 5 , 8 , 10 , 12 , 0 ,
>
>: lists-compare
> l1 l2
> begin over @ 0<> over @ 0<> and
> while over @ over @
> if dup @ .
> then
> cell+ swap cell+ swap
> repeat
> 2drop
> ;
>
> lists-compare
> 5 12 ok
>
> --
> Coos
>
> CHForth, 16 bit DOS applications
> http://home.hccnet.nl/j.j.haak/forth.html
create l1 3 , 5 , 7 , 8 , 12 , 0 ,
create l2 2 , 5 , 8 , 10 , 12 , 0 ,
: lists-compare
begin 2dup @ swap @ 2dup *
while over - if drop else . then
cell+ swap cell+
repeat
2drop
;
cr l1 l2 lists-compare
\ 5 12 ok
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Simple Forth problem "WJ" <w_a_x_man@yahoo.com> - 2013-09-17 09:39 +0000
Re: Simple Forth problem VoidVolker <voidvolker@gmail.com> - 2013-09-17 03:28 -0700
Re: Simple Forth problem Coos Haak <chforth@hccnet.nl> - 2013-09-17 17:05 +0200
Re: Simple Forth problem "Alex McDonald" <blog@rivadpm.com> - 2013-09-17 16:53 +0100
Re: Simple Forth problem Howerd <howerdo@yahoo.co.uk> - 2013-09-17 09:18 -0700
Re: Simple Forth problem VoidVolker <voidvolker@gmail.com> - 2013-09-17 11:06 -0700
Re: Simple Forth problem Alex McDonald <blog@rivadpm.com> - 2013-09-17 12:13 -0700
Re: Simple Forth problem VoidVolker <voidvolker@gmail.com> - 2013-09-17 22:42 -0700
Re: Simple Forth problem mhx@iae.nl - 2013-09-18 00:00 -0700
Re: Simple Forth problem Howerd <howerdo@yahoo.co.uk> - 2013-09-17 13:26 -0700
Re: Simple Forth problem Doug Hoffman <glidedog@gmail.com> - 2013-09-18 08:42 -0400
Re: Simple Forth problem "Ed" <invalid@invalid.com> - 2013-09-18 14:22 +1000
csiph-web