Possible to use format/2 to print a table with right-justified columns?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible to use format/2 to print a table with right-justified columns?

Paulo Moura-2
Hi,

Is it possible to use GNU Prolog format/2 predicate to print a table with right-justified columns? The original Quintus Prolog implementation of this predicate provide format control sequences to set and align with tab stops but this seems to not be implemented in GNU Prolog. Is there any alternative usage of the format/2 predicate that I'm missing?

Cheers,

Paulo

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:[hidden email]>
Web:   <http://logtalk.org/>
-----------------------------------------------------------------





_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Possible to use format/2 to print a table with right-justified columns?

emacstheviking
Best I managed was this:

yes

| ?- format('~*c~s',[10,32,"Hello"]).

format('~*c~s',[10,32,"Hello"]).

          Hello


yes

| ?- format('~*c~s',[20,32,"Hello"]).

format('~*c~s',[20,32,"Hello"]).

                    Hello



VALUE would be replaced with whatever you want to print at that point, probably another format specifier. By using * you can alter the width and the 'c' (with 32) allows spaces to be used as the pad.

Thanks,
Sean.


On 21 August 2014 12:19, Paulo Moura <[hidden email]> wrote:
Hi,

Is it possible to use GNU Prolog format/2 predicate to print a table with right-justified columns? The original Quintus Prolog implementation of this predicate provide format control sequences to set and align with tab stops but this seems to not be implemented in GNU Prolog. Is there any alternative usage of the format/2 predicate that I'm missing?

Cheers,

Paulo

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:[hidden email]>
Web:   <http://logtalk.org/>
-----------------------------------------------------------------





_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Possible to use format/2 to print a table with right-justified columns?

emacstheviking
Forgot to add that I would write a small predicate to then calculate the length of the string from the padding and actually make the number of spaces ensure right justification blah blah yadda yadda but I am sure you got that anyway!

:)
Perhaps I should do it for myself anyway!



On 21 August 2014 13:53, emacstheviking <[hidden email]> wrote:
Best I managed was this:

yes

| ?- format('~*c~s',[10,32,"Hello"]).

format('~*c~s',[10,32,"Hello"]).

          Hello


yes

| ?- format('~*c~s',[20,32,"Hello"]).

format('~*c~s',[20,32,"Hello"]).

                    Hello



VALUE would be replaced with whatever you want to print at that point, probably another format specifier. By using * you can alter the width and the 'c' (with 32) allows spaces to be used as the pad.

Thanks,
Sean.


On 21 August 2014 12:19, Paulo Moura <[hidden email]> wrote:
Hi,

Is it possible to use GNU Prolog format/2 predicate to print a table with right-justified columns? The original Quintus Prolog implementation of this predicate provide format control sequences to set and align with tab stops but this seems to not be implemented in GNU Prolog. Is there any alternative usage of the format/2 predicate that I'm missing?

Cheers,

Paulo

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:[hidden email]>
Web:   <http://logtalk.org/>
-----------------------------------------------------------------





_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog



_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Possible to use format/2 to print a table with right-justified columns?

emacstheviking
rpad(S, W, Chr, Out) :-
    length(S, L),
    Pad is W - L,
    format_to_codes(Out, '~*c~s', [Pad, Chr, S]).

Works for me!
:)
Sean



On 21 August 2014 13:56, emacstheviking <[hidden email]> wrote:
Forgot to add that I would write a small predicate to then calculate the length of the string from the padding and actually make the number of spaces ensure right justification blah blah yadda yadda but I am sure you got that anyway!

:)
Perhaps I should do it for myself anyway!



On 21 August 2014 13:53, emacstheviking <[hidden email]> wrote:
Best I managed was this:

yes

| ?- format('~*c~s',[10,32,"Hello"]).

format('~*c~s',[10,32,"Hello"]).

          Hello


yes

| ?- format('~*c~s',[20,32,"Hello"]).

format('~*c~s',[20,32,"Hello"]).

                    Hello



VALUE would be replaced with whatever you want to print at that point, probably another format specifier. By using * you can alter the width and the 'c' (with 32) allows spaces to be used as the pad.

Thanks,
Sean.


On 21 August 2014 12:19, Paulo Moura <[hidden email]> wrote:
Hi,

Is it possible to use GNU Prolog format/2 predicate to print a table with right-justified columns? The original Quintus Prolog implementation of this predicate provide format control sequences to set and align with tab stops but this seems to not be implemented in GNU Prolog. Is there any alternative usage of the format/2 predicate that I'm missing?

Cheers,

Paulo

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:[hidden email]>
Web:   <http://logtalk.org/>
-----------------------------------------------------------------





_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog




_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Possible to use format/2 to print a table with right-justified columns?

Paulo Moura-2
In reply to this post by emacstheviking
Hi Sean,

On 21/08/2014, at 13:56, emacstheviking <[hidden email]> wrote:

> Forgot to add that I would write a small predicate to then calculate the length of the string from the padding and actually make the number of spaces ensure right justification blah blah yadda yadda but I am sure you got that anyway!

That's what I'm trying to avoid. But I may have no alternative to do it as I need this functionality for a new Logtalk port profiler (a performance analysis tool). The format/2 predicate only provide the necessary functionality in 5 out of 11 backend Prolog compilers supported by Logtalk.

Thanks for your feedback. Cheers,

Paulo


> :)
> Perhaps I should do it for myself anyway!
>
>
>
> On 21 August 2014 13:53, emacstheviking <[hidden email]> wrote:
> Best I managed was this:
> yes
> | ?- format('~*c~s',[10,32,"Hello"]).
> format('~*c~s',[10,32,"Hello"]).
>           Hello
>
> yes
> | ?- format('~*c~s',[20,32,"Hello"]).
> format('~*c~s',[20,32,"Hello"]).
>                     Hello
>
>
> VALUE would be replaced with whatever you want to print at that point, probably another format specifier. By using * you can alter the width and the 'c' (with 32) allows spaces to be used as the pad.
>
> Thanks,
> Sean.
>
>
> On 21 August 2014 12:19, Paulo Moura <[hidden email]> wrote:
> Hi,
>
> Is it possible to use GNU Prolog format/2 predicate to print a table with right-justified columns? The original Quintus Prolog implementation of this predicate provide format control sequences to set and align with tab stops but this seems to not be implemented in GNU Prolog. Is there any alternative usage of the format/2 predicate that I'm missing?
>
> Cheers,
>
> Paulo
>
> -----------------------------------------------------------------
> Paulo Moura
> Logtalk developer
>
> Email: <mailto:[hidden email]>
> Web:   <http://logtalk.org/>
> -----------------------------------------------------------------
>
>
>
>
>
> _______________________________________________
> Users-prolog mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/users-prolog
>
>

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:[hidden email]>
Web:   <http://logtalk.org/>
-----------------------------------------------------------------





_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Possible to use format/2 to print a table with right-justified columns?

Paulo Moura-2
In reply to this post by emacstheviking

On 21/08/2014, at 14:07, emacstheviking <[hidden email]> wrote:

> rpad(S, W, Chr, Out) :-
>     length(S, L),
>     Pad is W - L,
>     format_to_codes(Out, '~*c~s', [Pad, Chr, S]).
>
> Works for me!

Thanks for the code snippet :-)

Cheers,

Paulo

> On 21 August 2014 13:56, emacstheviking <[hidden email]> wrote:
> Forgot to add that I would write a small predicate to then calculate the length of the string from the padding and actually make the number of spaces ensure right justification blah blah yadda yadda but I am sure you got that anyway!
>
> :)
> Perhaps I should do it for myself anyway!
>
>
>
> On 21 August 2014 13:53, emacstheviking <[hidden email]> wrote:
> Best I managed was this:
> yes
> | ?- format('~*c~s',[10,32,"Hello"]).
> format('~*c~s',[10,32,"Hello"]).
>           Hello
>
> yes
> | ?- format('~*c~s',[20,32,"Hello"]).
> format('~*c~s',[20,32,"Hello"]).
>                     Hello
>
>
> VALUE would be replaced with whatever you want to print at that point, probably another format specifier. By using * you can alter the width and the 'c' (with 32) allows spaces to be used as the pad.
>
> Thanks,
> Sean.
>
>
> On 21 August 2014 12:19, Paulo Moura <[hidden email]> wrote:
> Hi,
>
> Is it possible to use GNU Prolog format/2 predicate to print a table with right-justified columns? The original Quintus Prolog implementation of this predicate provide format control sequences to set and align with tab stops but this seems to not be implemented in GNU Prolog. Is there any alternative usage of the format/2 predicate that I'm missing?
>
> Cheers,
>
> Paulo
>
> -----------------------------------------------------------------
> Paulo Moura
> Logtalk developer
>
> Email: <mailto:[hidden email]>
> Web:   <http://logtalk.org/>
> -----------------------------------------------------------------
>
>
>
>
>
> _______________________________________________
> Users-prolog mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/users-prolog
>
>
>

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:[hidden email]>
Web:   <http://logtalk.org/>
-----------------------------------------------------------------





_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog