Jump to content

Modulinos: Difference between revisions

→‎{{header|Haskell}}: Add Factor, as best as I understand it.
(Add a warning with a link to the talk page.)
(→‎{{header|Haskell}}: Add Factor, as best as I understand it.)
Line 284:
main(_) ->
io:format("Test: The meaning of life is ~w~n", [meaning_of_life()]).</lang>
 
=={{header|Factor}}==
This "fibonacci" vocabulary exports both a <tt>fib</tt> word (from [[Fibonacci sequence#Factor]]) and a main entry point.
 
<lang factor>USING: kernel io math math.parser sequences ;
IN: fibonacci
 
: fib ( n -- m )
dup 2 < [
[ 0 1 ] dip [ swap [ + ] keep ] times
drop
] unless ;
 
: first-15 ( -- )
15 iota [
dup
fib number>string write
14 = [ "\n" ] [ ", " ] if write
] each ;
 
MAIN: first-15</lang>
 
One can run the main program in the listener:
 
<pre>( scratchpad ) "fibonacci" run
Loading resource:work/fibonacci/fibonacci.factor
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377</pre>
 
One can also use the exported words (in the listener, or in another program):
 
<pre>( scratchpad ) USE: fibonacci
( scratchpad ) 20 fib .
6765</pre>
 
However, nothing happens if you run it as a script (<tt>./factor work/fibonacci/fibonacci.factor</tt>), because there is no code to call the main entry point.
 
=={{header|Haskell}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.