# XPCE Optional Arguments

**URL:** <https://swi-prolog.discourse.group/t/xpce-optional-arguments/791>\
**Category:** Help!\
**Created:** [June 11, 2019, 8:08pm UTC](https://swi-prolog.discourse.group/t/xpce-optional-arguments/791 "2019-06-11T20:08:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)\
**Post date:** [June 11, 2019, 8:08pm UTC](https://swi-prolog.discourse.group/t/xpce-optional-arguments/791/1 "2019-06-11T20:08:29Z")

</div>

I know XPCE is, if not deprecated, not really being worked on anymore; regardless, I’ve been trying to give it a try. I’m wondering how I can make my own code have the “optional” arguments, like `new(S, path(kind := poly, points := [point(0, 0)]))`.

What do I need to do so, for example, I can do:

```prolog
:- pce_begin_class(foo, device, "Foobar").

initialise(F, Baz:[int], Bar:[int]) :->
   "Create a new foobar"::
   format("baz = ~w, bar = ~w", [Baz, Bar]).

:- pce_end_class.

% how do I make this work?
?- new(F, foo(bar := 100)). % want: baz = @default, bar = 100
% ERROR: foo ->initialise: No argument named bar
?- new(F, foo(bar := 1, baz := 2)). % baz = 2, bar = 1

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [June 12, 2019, 7:11am UTC](https://swi-prolog.discourse.group/t/xpce-optional-arguments/791/2 "2019-06-12T07:11:08Z")

</div>

What is the problem? The `initialise` method should call the super implementation and do something with the `@default` (typically call `default/3` or pass it on to some other method that handles it.

---

<div class="post-metadata">

**Author:** ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)\
**Post date:** [June 12, 2019, 11:05am UTC](https://swi-prolog.discourse.group/t/xpce-optional-arguments/791/3 "2019-06-12T11:05:55Z")

</div>

The problem is that what I’ve written gives the error `foo ->initialise: No argument named bar`. How do I tell it what the names of the arguments are?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [June 12, 2019, 11:21am UTC](https://swi-prolog.discourse.group/t/xpce-optional-arguments/791/4 "2019-06-12T11:21:51Z")

</div>

> [@jamesnvc](#):
>
> initialise(F, Baz:[int], Bar:[int]) :-\>

I see. A quick look at the pce library suggests this:

```prolog
initialise(F, Baz:baz=[int], Bar:bar=[int]) :->

```

my xpce is also getting rusty ☹

---

<div class="post-metadata">

**Author:** ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)\
**Post date:** [June 12, 2019, 12:53pm UTC](https://swi-prolog.discourse.group/t/xpce-optional-arguments/791/5 "2019-06-12T12:53:52Z")

</div>

Ah, that did it! Thanks Jan!
