Re: goal_expansion
"Richard A. O'Keefe" <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 11/02/2014, at 5:38 AM, Jonathon Doran wrote:
> My thanks to everyone for your comments. I was overthinking things. I messed
> around with goal_expansion and have something I like:
>
> goal_expansion(optional_param(Tag:Value, Parameters, Generator), Y) :-
> Y = (
> member(Tag:Value, Parameters) ->
> true
> ;
> Generator
> ).
>
> It is possible that one or more of the list members find this offensive.
> It is hard not to fall back upon old habits when one doesn't know better.
> But I find it much easier to read/write
> optional_param(color:Color, Parameter_List,
> (
> random_color(Color)
> )),
>
> than to have the full expansion appear in the source.
But you don't *NEED* macros of any kind for this!
optional_param(Tag:Value, Parameters, Generator) :-
( member(Tag:Value, Parameters) -> true
; call(Generator)
).
And now you read/write
optional_param(color:Color, Parameter_List, (
random_color(Color)
))
and it just WORKS. No macros required.
This is not C.
You do NOT need macros to pass code fragments as arguments!