Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Motif Programming Style

9 views
Skip to first unread message

Aaron W. Hsu

unread,
Jul 18, 2008, 4:33:26 PM7/18/08
to
Hello,

I am planning on writing some bindings for Motif to Scheme and I had a
question about style. Is it generally considered better Motif style to
use the variable arity procedures or the static arity procedures? I
know that there seem to be plenty of examples of using both, but I can't
tell whether one or the other is a better choice for designing a
consistent style.

Thanks!
Aaron Hsu
--
+++++++++++++++ ((lambda (x) (x x)) (lambda (x) (x x))) +++++++++++++++
Email: <arc...@sacrideo.us> | WWW: <http://www.sacrideo.us>
Scheme Programming is subtle; subtlety can be hard.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

arahne

unread,
Jul 20, 2008, 4:55:27 PM7/20/08
to
Aaron W. Hsu wrote:
> Hello,
>
> I am planning on writing some bindings for Motif to Scheme and I had a
> question about style. Is it generally considered better Motif style to
> use the variable arity procedures or the static arity procedures? I
> know that there seem to be plenty of examples of using both, but I can't
> tell whether one or the other is a better choice for designing a
> consistent style.

If by arity you mean
XtVaSet... XtVaGet...
versue
XtGet... XtSet
then I would consider XtVa functions to be superior,
since you can do more with one call.
Also gcc 4 or later will warn you of missing sentinel (ending NULL)
in XtVa functions, so it is not so error prone as before.
But this is just my opinion, I would not go so far as
categorically advise one style over another.

Best regards

Dušan Peterc
http://wwwa.arahne.si

Aaron W. Hsu

unread,
Jul 20, 2008, 6:00:47 PM7/20/08
to
arahne <ara...@arahne.si> writes:

Thanks for your suggestion. In the end, I do not intend the user of these
bindings to see the C parts at all. However, I want to make sure that the
bindings are flexible and easy to maintain for others down the road.
Finding a consistent way of using the large number of Motif procedures
seems like the best way to do this. I assume that both functions are
more or less equal in expressivity?

arahne

unread,
Jul 21, 2008, 6:21:29 AM7/21/08
to
Aaron W. Hsu wrote:

> Thanks for your suggestion. In the end, I do not intend the user of these
> bindings to see the C parts at all. However, I want to make sure that the
> bindings are flexible and easy to maintain for others down the road.
> Finding a consistent way of using the large number of Motif procedures
> seems like the best way to do this. I assume that both functions are
> more or less equal in expressivity?

They are exactly the same in their expression power.
They are there just to help the programmer in simplifying the code.

Actually, all your questions regarding style and motivation
are answered in XtVa... sections of
Volume 5
X Toolkit Intrinsic Reference Manual
Third edition
for X11 Release 4 and Release 5
By O'Reilly & Associates, Inc.
edited by David Flanagan.

This same book is open source book, since it is out of print
http://www.archive.org/details/xtoolkitintrirefman05oreimiss
but only the first edition is open sourced.
So it does not cover XtVa... functions, which were introduced
with X11R4.
Fortunately, you can get it at Powells for $8.75
http://www.powells.com/biblio?isbn=1-56592-007-4
Or you can ask O'Reilly to open source the updated versions, too.
Even the last edition is 16 years old now.

Dušan Peterc
http://www.arahne.si

Fred

unread,
Jul 23, 2008, 10:26:29 AM7/23/08
to
On Jul 21, 3:21 am, arahne <ara...@arahne.si> wrote:
> Aaron W. Hsu wrote:
> > Thanks for your suggestion. In the end, I do not intend the user of these
> > bindings to see the C parts at all. However, I want to make sure that the
> > bindings are flexible and easy to maintain for others down the road.
> > Finding a consistent way of using the large number of Motif procedures
> > seems like the best way to do this. I assume that both functions are
> > more or less equal in expressivity?
>
> They are exactly the same in their expression power.
> They are there just to help the programmer in simplifying the code.
>
> Actually, all your questions regarding style and motivation
> are answered in XtVa... sections of
> Volume 5
> X Toolkit Intrinsic Reference Manual
> Third edition
> for X11 Release 4 and Release 5
> By O'Reilly & Associates, Inc.
> edited by David Flanagan.
>
> This same book is open source book, since it is out of printhttp://www.archive.org/details/xtoolkitintrirefman05oreimiss

> but only the first edition is open sourced.
> So it does not cover XtVa... functions, which were introduced
> with X11R4.
> Fortunately, you can get it at Powells for $8.75http://www.powells.com/biblio?isbn=1-56592-007-4

> Or you can ask O'Reilly to open source the updated versions, too.
> Even the last edition is 16 years old now.
>

Both have advantages and disadvantages.
the XtVa... style allows for a single call, and ease of adding,
removing, or
commenting out one or more resource settings:
XtVaSetValues( widget,
resourceName, value,
resourceName, value,
/* resourceName, value,*/
NULL);

But the non-variadic functions have the advantage of not requiring
a lot of malloc/free thrashing in the variadic functions, and also
allow ease of setting resources based on some condition:
n = 0;
XtSetValues( arg[n], resourceName, value); n++;
if (soemthing) {
XtSetValues( arg[n], resourceName, value); n++;
XtSetValues( arg[n], resourceName, value); n++;
XtSetValues( arg[n], resourceName, value); n++;
}
XtSetValues( widget, args, n );
Remembering, of course, to dimension the arg array appropriately.

The choice is up to you. Personally, I prefer the latter.
--
Fred Kleinschmidt

Bill Schottstaedt

unread,
Jul 26, 2008, 1:30:10 PM7/26/08
to
There's a set of X/Xt/Motif bindings in libxm:

ftp://ccrma-ftp.stanford.edu/pub/Lisp/libxm.tar.gz

Guile and Gauche are supported, as well as Ruby and Forth.
Used by Snd -- lots of examples in its scheme files.

0 new messages