Loops/Foreach: Difference between revisions

Content deleted Content added
Update
new Emacs Lisp
Line 595:
 
each [1..10]</lang>
 
=={{header|Emacs Lisp}}==
For a list either <code>dolist</code> macro
 
<lang Lisp>(dolist (x '(1 2 3 4))
(message "x=%d" x))</lang>
 
or <code>mapc</code> function
 
<lang Lisp>(mapc (lambda (x)
(message "x=%d" x))
'(1 2 3 4))</lang>
 
<code>dolist</code> and <code>mapc</code> are both builtin in current Emacs. For past Emacs both can be had from <code>cl.el</code> with for instance <code>(eval-when-compile (require 'cl))</code>.
 
<code>cl.el</code> also offers a <code>loop</code> macro similar in style to [[#Common Lisp|Common Lisp]].
 
 
=={{header|Erlang}}==
Line 601 ⟶ 618:
However, to iterate over each element of a list, Erlang uses <tt>lists:map/2</tt>, except in the case of IO where <tt>lists:foreach/2</tt> has to be used as the evaluation order is defined to be the same as the order of the elements in the list.
<lang erlang>lists:foreach(fun(X) -> io:format("~p~n",[X]) end, Collection).</lang>
 
 
 
 
 
=={{header|Euphoria}}==