From: Volkan YAZICI
Subject: FORMAT Conditionals Weirdness
Date: 
Message-ID: <9d82155c-2544-4ea7-9dae-b349e16f248f@m45g2000hsb.googlegroups.com>
Hi,

Shouldn't (format nil "~{~:[NOT NULL~;~]·@[ DEFAULT ~a~]~^, ~}" '((nil
12) (t nil))) be outputting "NOT NULL DEFAULT 12, " instead of "
DEFAULT (T NIL)"? (Using SBCL 1.0.19.27)


Regards.

P.S. BTW, is "22.3.7.2 Tilde Left-Bracket: Conditional Expression"
poorly documented (e.g. no explanation for `#' directive, but just an
example) or it's just me?

From: cmo
Subject: Re: FORMAT Conditionals Weirdness
Date: 
Message-ID: <e549300c-7bd1-4481-b08a-29bc09ab71c8@i76g2000hsf.googlegroups.com>
On Sep 18, 5:36 pm, Volkan YAZICI <·············@gmail.com> wrote:
> Hi,
>
> Shouldn't (format nil "~{~:[NOT NULL~;~]·@[ DEFAULT ~a~]~^, ~}" '((nil
> 12) (t nil))) be outputting "NOT NULL DEFAULT 12, " instead of "
> DEFAULT (T NIL)"? (Using SBCL 1.0.19.27)
>
> Regards.
>
> P.S. BTW, is "22.3.7.2 Tilde Left-Bracket: Conditional Expression"
> poorly documented (e.g. no explanation for `#' directive, but just an
> example) or it's just me?

the output should be " DEFAULT (T NIL)".

read through

http://gigamonkeys.com/book/a-few-format-recipes.html

regards

cmo
From: Thomas A. Russ
Subject: Re: FORMAT Conditionals Weirdness
Date: 
Message-ID: <ymik5d9flr1.fsf@blackcat.isi.edu>
Volkan YAZICI <·············@gmail.com> writes:

> Hi,
> 
> Shouldn't (format nil "~{~:[NOT NULL~;~]·@[ DEFAULT ~a~]~^, ~}"
>                   '((nil 12) (t nil)))
>  be outputting "NOT NULL DEFAULT 12, " instead of
>  "DEFAULT (T NIL)"? (Using SBCL 1.0.19.27)

No.  It is acting correctly.
That is because the first argument passed to the ~:[ is (nil 12) and not
the nil that you expect.

To do what you want to do, you need another level of ~{...~}:

  (format nil "~{~{~:[NOT NULL~;~]·@[ DEFAULT ~a~]~}~^, ~}"
          '((nil 12) (t nil)))

> Regards.
> 
> P.S. BTW, is "22.3.7.2 Tilde Left-Bracket: Conditional Expression"
> poorly documented (e.g. no explanation for `#' directive, but just an
> example) or it's just me?

No.  The standard tends to be a bit terse, but # is not a directive, but
is instead a standard part of the format syntax that can be used in the
place where normally one would have a parameter.  It is documented
earlier in the text in section 22.3:

  In place of a prefix parameter to a directive, V (or v) can be
  used. In this case, format takes an argument from args as a parameter
  to the directive. The argument should be an integer or character. If
  the arg used by a V parameter is nil, the effect is as if the
  parameter had been omitted. # can be used in place of a prefix
  parameter; it represents the number of args remaining to be
  processed. When used within a recursive format, in the context of ~?
  or ~{, the # prefix parameter represents the number of format
  arguments remaining within the recursive call.

So, this is just pointing out a good use of # to pass the number of
remaining arguments as a parameter to the ~[ directive.




-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Volkan YAZICI
Subject: Re: FORMAT Conditionals Weirdness
Date: 
Message-ID: <5c392a7e-775f-4a60-bd46-96722402a014@59g2000hsb.googlegroups.com>
On Sep 18, 7:43 pm, ····@sevak.isi.edu (Thomas A. Russ) wrote:
> Volkan YAZICI <·············@gmail.com> writes:
> > Shouldn't (format nil "~{~:[NOT NULL~;~]·@[ DEFAULT ~a~]~^, ~}"
> >                   '((nil 12) (t nil)))
> >  be outputting "NOT NULL DEFAULT 12, " instead of
> >  "DEFAULT (T NIL)"? (Using SBCL 1.0.19.27)
>
> No.  It is acting correctly.
> That is because the first argument passed to the ~:[ is (nil 12) and not
> the nil that you expect.
>
> To do what you want to do, you need another level of ~{...~}:
>
>   (format nil "~{~{~:[NOT NULL~;~]·@[ DEFAULT ~a~]~}~^, ~}"
>           '((nil 12) (t nil)))
>
> > Regards.
>
> > P.S. BTW, is "22.3.7.2 Tilde Left-Bracket: Conditional Expression"
> > poorly documented (e.g. no explanation for `#' directive, but just an
> > example) or it's just me?
>
> No.  The standard tends to be a bit terse, but # is not a directive, but
> is instead a standard part of the format syntax that can be used in the
> place where normally one would have a parameter.  It is documented
> earlier in the text in section 22.3:
>
>   In place of a prefix parameter to a directive, V (or v) can be
>   used. In this case, format takes an argument from args as a parameter
>   to the directive. The argument should be an integer or character. If
>   the arg used by a V parameter is nil, the effect is as if the
>   parameter had been omitted. # can be used in place of a prefix
>   parameter; it represents the number of args remaining to be
>   processed. When used within a recursive format, in the context of ~?
>   or ~{, the # prefix parameter represents the number of format
>   arguments remaining within the recursive call.
>
> So, this is just pointing out a good use of # to pass the number of
> remaining arguments as a parameter to the ~[ directive.

My bad. Sorry for the noise and thanks for the detailed reply.


Regards.
From: ·······@eurogaran.com
Subject: Re: FORMAT Conditionals Weirdness
Date: 
Message-ID: <ca6dcdf3-007b-49f6-8ba9-049774d519f4@z66g2000hsc.googlegroups.com>
It is perhaps a better practice to pump the conditionals out of the
format statements:
(if (null condition)
  (format nil "condition is null")
  (format nil "condition is true"))

That way, you have all the power of the language.
From: Pascal J. Bourguignon
Subject: Re: FORMAT Conditionals Weirdness
Date: 
Message-ID: <7c8wtoqkwt.fsf@anevia.com>
·······@eurogaran.com writes:

> It is perhaps a better practice to pump the conditionals out of the
> format statements:
> (if (null condition)
>   (format nil "condition is null")
>   (format nil "condition is true"))
>
> That way, you have all the power of the language.

or:

(format nil "condition is ~A" (if (null condition) "NIL" "true"))


-- 
__Pascal Bourguignon__