From: Bigos on
There's one thing that puzzles me most. What is best practice to group
several functions together? For example in body of a loop.

(dotimes (x 3)
(tagbody
(format t "one ~a~%" x )
(format t "two ~a~%" x)
(format t "three ~a~%" x) ) )

Is tagbody the right way to do it or even for one loop I need to
define a function.

(defun mytagbody (x)
(format t "one ~a~%" x )
(format t "two ~a~%" x)
(format t "three ~a~%" x))
(dotimes (x 3)
(mytagbody x))

I am puzzled because in Lisp code I have seen so far I didn't see
tagbody being being used, although in other languages there are
constructs to group statements together.
From: Willem Broekema on
On 27 okt, 17:17, Bigos <ruby.obj...(a)googlemail.com> wrote:
> There's one thing that puzzles me most. What is best practice to group
> several functions together? For example in body of a loop.
>
> (dotimes (x 3)
>   (tagbody
>      (format t "one ~a~%" x )
>      (format t "two ~a~%" x)
>      (format t "three ~a~%" x) ) )

PROGN is what you're looking for, though DOTIMES has an implicit PROGN
so in this example you don't need a grouping statement.

Please see:
http://groups.google.nl/group/comp.lang.lisp/browse_frm/thread/f4223a902f868503/

- Willem
From: Tamas K Papp on
On Tue, 27 Oct 2009 09:17:52 -0700, Bigos wrote:

> There's one thing that puzzles me most. What is best practice to group
> several functions together? For example in body of a loop.
>
> (dotimes (x 3)
> (tagbody
> (format t "one ~a~%" x )
> (format t "two ~a~%" x)
> (format t "three ~a~%" x) ) )
>
> Is tagbody the right way to do it or even for one loop I need to define
> a function.
>
> (defun mytagbody (x)
> (format t "one ~a~%" x )
> (format t "two ~a~%" x)
> (format t "three ~a~%" x))
> (dotimes (x 3)
> (mytagbody x))
>
> I am puzzled because in Lisp code I have seen so far I didn't see
> tagbody being being used, although in other languages there are
> constructs to group statements together.

Tagbody is best used when you want use labels and GO, CL's answer to
goto.

Use progn to just group code.

Most forms have an "implicit" progn, including dotimes, lambda, and thus
defun. So the idiomatic way is

(dotimes (x 3)
(format t "one ~a~%" x)
(format t "two ~a~%" x)
(format t "three ~a~%" x))

I would suggest that you try working through an intro Lisp book, eg ANSI
Common Lisp or Practical Common Lisp (available online). You will learn
about these constructs and also see a lot of idiomatic Lisp code.

HTH,

Tamas
From: xach on
Willem Broekema <metawilm(a)gmail.com> writes:

> On 27 okt, 17:17, Bigos <ruby.obj...(a)googlemail.com> wrote:
>> There's one thing that puzzles me most. What is best practice to group
>> several functions together? For example in body of a loop.
>>
>> (dotimes (x 3)
>>   (tagbody
>>      (format t "one ~a~%" x )
>>      (format t "two ~a~%" x)
>>      (format t "three ~a~%" x) ) )
>
> PROGN is what you're looking for, though DOTIMES has an implicit PROGN
> so in this example you don't need a grouping statement.

Actually, DOTIMES (and some other constructs) have an implicit TAGBODY,
not an implicit PROGN.

Zach
From: Bigos on
On 27 Oct, 16:31, Willem Broekema <metaw...(a)gmail.com> wrote:
> On 27 okt, 17:17, Bigos <ruby.obj...(a)googlemail.com> wrote:
>
> > There's one thing that puzzles me most. What is best practice to group
> > several functions together? For example in body of a loop.
>
> > (dotimes (x 3)
> >   (tagbody
> >      (format t "one ~a~%" x )
> >      (format t "two ~a~%" x)
> >      (format t "three ~a~%" x) ) )
>
> PROGN is what you're looking for, though DOTIMES has an implicit PROGN
> so in this example you don't need a grouping statement.
>
> Please see:
>  http://groups.google.nl/group/comp.lang.lisp/browse_frm/thread/f4223a....
>
> - Willem

thanks everyone the code below does the trick, later I will also check
dotimes

(progn
(format t "one~%")
(format t "two~%")
3 )