<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Fabrice,<div class="">Thanks for your reply, very heart-warming indeed. :)</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 25 Apr 2021, at 03:52, Fabrice Nicol <<a href="mailto:fabrnicol@gmail.com" class="">fabrnicol@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class="">Sean, <div dir="auto" class="">Your testimony is an interesting one.</div></div></div></blockquote><div><br class=""></div>Thanks.</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Yes, Mercury does have a steep learning curve, but after a while your code will build like a charm and you'll get hooked. It is very rewarding, especially if you have had some prior experience with prolog. (Which helps a bit yet may be misleading at times).</div></div></div></blockquote><div><br class=""></div>I started with GNU Prolog, wow, just looked, EIGHT years ago ( <a href="https://github.com/emacstheviking/gnuprolog-redisclient" class="">https://github.com/emacstheviking/gnuprolog-redisclient</a> ) and really took to that. I wrote an SDL2 wrapper with it and a simple JSON encoder/decoder. Then I wrote a Redis wrapper as well and that, remarkably is now in the SDWI Prolog code base somewhere, Jan W. Asked if he could steal it and I was thoroughly flattered. I am no newcomer to Prolog, but I am no expert either. I can write DCGS to parse things very comfortably, I am very confident with backtracking, unifications, all the usual things. I’ve learned about Horne clauses, logic, all sorts of interesting stuff along the way, not least in part thanks to all the great people out there that produce things like SWI and Mercury etc. Shout outs to Anne Ogborn for some great SI tutorials and the SWI forum is one of the best and friendliest I’ve ever used.</div><div><br class=""></div><div>I recently taught myself just enough J to realise the cleverness of it but also that I probably won’t ever need it, I had some fun writing a native Postgres wrapper for it to the point where it worked. Moved on since then, that was after playing with Dialog APL for 18 months. Lockdown!!! :)</div><div><br class=""></div><div>Slowly I am fearing the build process less and less; and when the code compiles the sense of ‘Yeah!!!!’ Is getting very hard to beat. The code just feels ‘clean’. My current day job is python+Django, so a lot less rigorous. There is something about the way you are literally forced to know exactly what your code is doing to get the mmc to eat it, even though I always use types with Python, the runtime does nothing with it, it’s a linter sham!</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div dir="auto" class=""><br class=""></div><div dir="auto" class="">My advice: read Julien's code (mercury_json, mercury_cairo, and more). I'm a big fan of his. It is very clearly commented and nicely laid out. You will learn a lot from it, provided that you keep the docs open at hand. </div></div></div></blockquote><div><br class=""></div><div>Yes!! I’ve already been reading in earnest now. I also gained a lot from the source code for mmc-doc. I had to updated mmc-doc to use the newer getopt_io and I have made a pull request back into the main project but no news on that yet. That was good practice too.</div><div><br class=""></div><div></div><div>This app: <a href="https://github.com/emacstheviking/mcnew" class="">https://github.com/emacstheviking/mcnew</a>. I intend to keep adding things to, the next thing is to add a ‘genopt’ option so that given a simple configuration file, it can spit out the skeleton code for short_option/long_option/default_optiosn etc etc. One of the things that -was- daunting to begin with was all the preamble for starting even a hello world, but now all I have to do is:</div><div><br class=""></div><div> $ mcnew stub foo > foo.m</div><div> $ mcnew makefile foo > Makefile</div><div><br class=""></div><div>And away I go!</div><div> </div><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div dir="auto" class=""><br class=""></div><div dir="auto" class="">And don't be discouraged by compiler whinings, like 'instantiatedness not being the same in all branches of if-then-elses', or 'arguments being clobbered while still alive' (OMG, this one nearly drove me mad a few times). You'll come to manage these and a few other exotic delicacies over time, with some musings and a wee bit of sweat.</div></div></div></blockquote><div><br class=""></div><div>I am getting used to the error messages, in my makefile (produced by my first ever mercury self-written tool!) I have the -E option for extra fibre. The messages are long but way more helpful than GHC at times!</div><div><br class=""></div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div dir="auto" class="">Best</div><div dir="auto" class="">Fabrice</div></div></div></blockquote><div><br class=""></div>Likewise, the path is an interesting one but always rewarding.</div><div><br class=""></div><div>Thanks, and all the best to you and everybody else on the journey!</div><div>:)</div><div>Sean</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div dir="auto" class=""><br class=""></div><div dir="auto" class=""><br class=""><div dir="auto" class=""><br class=""></div></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le sam. 24 avr. 2021 à 10:35 PM, <<a href="mailto:users-request@lists.mercurylang.org" class="">users-request@lists.mercurylang.org</a>> a écrit :<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send users mailing list submissions to<br class="">
<a href="mailto:users@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users@lists.mercurylang.org</a><br class="">
<br class="">
To subscribe or unsubscribe via the World Wide Web, visit<br class="">
<a href="https://lists.mercurylang.org/listinfo/users" rel="noreferrer noreferrer" target="_blank" class="">https://lists.mercurylang.org/listinfo/users</a><br class="">
or, via email, send a message with subject or body 'help' to<br class="">
<a href="mailto:users-request@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users-request@lists.mercurylang.org</a><br class="">
<br class="">
You can reach the person managing the list at<br class="">
<a href="mailto:users-owner@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users-owner@lists.mercurylang.org</a><br class="">
<br class="">
When replying, please edit your Subject line so it is more specific<br class="">
than "Re: Contents of users digest..."<br class="">
<br class="">
<br class="">
Today's Topics:<br class="">
<br class="">
1. DCG-s in Mercury (Sean Charles (emacstheviking))<br class="">
2. Re: DCG-s in Mercury (Tomas By)<br class="">
3. Re: DCG-s in Mercury (Julien Fischer)<br class="">
4. Re: DCG-s in Mercury (Sean Charles (emacstheviking))<br class="">
5. getopt_io return value type on success?<br class="">
(Sean Charles (emacstheviking))<br class="">
6. Re: getopt_io return value type on success? (Zoltan Somogyi)<br class="">
7. Re: getopt_io return value type on success?<br class="">
(Sean Charles (emacstheviking))<br class="">
<br class="">
<br class="">
----------------------------------------------------------------------<br class="">
<br class="">
Message: 1<br class="">
Date: Sat, 24 Apr 2021 10:33:31 +0100<br class="">
From: "Sean Charles (emacstheviking)" <<a href="mailto:objitsu@gmail.com" target="_blank" rel="noreferrer" class="">objitsu@gmail.com</a>><br class="">
To: users <<a href="mailto:users@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users@lists.mercurylang.org</a>><br class="">
Subject: [m-users.] DCG-s in Mercury<br class="">
Message-ID: <<a href="mailto:6D19C8E1-8CD9-47D5-87E8-C7CE587E06A0@gmail.com" target="_blank" rel="noreferrer" class="">6D19C8E1-8CD9-47D5-87E8-C7CE587E06A0@gmail.com</a>><br class="">
Content-Type: text/plain; charset=utf-8<br class="">
<br class="">
Hi,<br class="">
<br class="">
I am but a mere mortal, not formally schooled in logic and its terminology. Despite repeated googling, watching and reading my entire set of Prolog books, the terms ‘existential’ and ‘universal’ barely mean anything to me and now I have two sets of DCG rules to port from SWI Prolog and I just don’t know where to start. At the root ?<br class="">
<br class="">
Is there anywhere to be found a short, concise example of how to create a DCG rule, just so I can see some examples of the mode declarations, mine are not going to be used as generators, just as a lever and a parser/AST builder. I use phrase_from_file/3 in SWI Prolog, and the debugger means I can step through any rules that aren’t doing what I think. So far in mercury I have not even worked out how to start calling the head rule, if you call it that.<br class="">
<br class="">
I’ve built and use an ROTD from sources:<br class="">
<br class="">
➜ mcnew mmc —version<br class="">
Mercury Compiler, version rotd-2021-04-15, on x86_64-apple-darwin19.6.0<br class="">
Copyright (C) 1993-2012 The University of Melbourne<br class="">
Copyright (C) 2013-2021 The Mercury team<br class="">
<br class="">
<br class="">
I continue reading the Mercury language reference guide in hope of more Eureka moments, I really think Mercury is the one language I could spend the rest of my days being happy with, it has the good bits from Prolog and Haskell and much more but as a non-degree/CS person, as a completely self-taught developer going back 35 years, the documentation is somewhat lacking in sympathy for newcomers, not its fault to be sure but Mercury is not mainstream and so there is not an awful lot of example stuff out there and what I have found suffers from the same problem: I am not smart enough to understand the awesomely flowery language as it leaves me feeling cold and glazed over and totally disillusioned at times. Again, as they say, “It’s not you, it’s me”.<br class="">
<br class="">
So. Thanks for Mercury chaps, a brilliant piece of work that the world probably won’t ever fully appreciate, but I do.<br class="">
It’s just a shame I can’t use it yet! <br class="">
:)<br class="">
<br class="">
All the best,<br class="">
Sean.<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
------------------------------<br class="">
<br class="">
Message: 2<br class="">
Date: Sat, 24 Apr 2021 11:56:01 +0200<br class="">
From: Tomas By <<a href="mailto:tomas@basun.net" target="_blank" rel="noreferrer" class="">tomas@basun.net</a>><br class="">
To: "Sean Charles (emacstheviking)" <<a href="mailto:objitsu@gmail.com" target="_blank" rel="noreferrer" class="">objitsu@gmail.com</a>><br class="">
Cc: users <<a href="mailto:users@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users@lists.mercurylang.org</a>><br class="">
Subject: Re: [m-users.] DCG-s in Mercury<br class="">
Message-ID: <<a href="mailto:8735vg80r2.wl-tomas@basun.net" target="_blank" rel="noreferrer" class="">8735vg80r2.wl-tomas@basun.net</a>><br class="">
Content-Type: text/plain; charset=ISO-8859-7<br class="">
<br class="">
On Sat, 24 Apr 2021 11:33:31 +0200, Sean Charles (emacstheviking) wrote:<br class="">
> [...] now I have two sets of DCG rules to port from SWI Prolog and I<br class="">
> just don’t know where to start. [...]<br class="">
<br class="">
<br class="">
There are a couple of problems: partical data structures and<br class="">
nondeterminism. If the DCG is for a formal language (ie programming<br class="">
code) then it is better to rewrite the parser, for example using<br class="">
`continuation passing' (I think it's called).<br class="">
<br class="">
To implement a DCG in Mercury you need to have solutions/2 at the top,<br class="">
and then make all the `grammar rules' nondet. Constructing the output<br class="">
holistically, as is/was common in DCGs, does not work (unless it has<br class="">
been added in the twenty years or so since I tried it).<br class="">
<br class="">
But to begin with you can just remove all the output parameters from<br class="">
the DCG, and then look at that problem after the parsing works.<br class="">
<br class="">
There are some minor advantages compared to Prolog, e.g. you can write<br class="">
Kleene operators (star, plus, question mark) to make things<br class="">
prettier. This has been discussed here before I believe.<br class="">
<br class="">
/Tomas<br class="">
<br class="">
<br class="">
------------------------------<br class="">
<br class="">
Message: 3<br class="">
Date: Sat, 24 Apr 2021 21:53:09 +1000 (AEST)<br class="">
From: Julien Fischer <<a href="mailto:jfischer@opturion.com" target="_blank" rel="noreferrer" class="">jfischer@opturion.com</a>><br class="">
To: "Sean Charles (emacstheviking)" <<a href="mailto:objitsu@gmail.com" target="_blank" rel="noreferrer" class="">objitsu@gmail.com</a>><br class="">
Cc: users <<a href="mailto:users@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users@lists.mercurylang.org</a>><br class="">
Subject: Re: [m-users.] DCG-s in Mercury<br class="">
Message-ID: <<a href="mailto:af1d114b-c9a3-91f0-b364-744d1b7a5033@opturion.com" target="_blank" rel="noreferrer" class="">af1d114b-c9a3-91f0-b364-744d1b7a5033@opturion.com</a>><br class="">
Content-Type: text/plain; charset="utf-8"; Format="flowed"<br class="">
<br class="">
<br class="">
Hi Sean,<br class="">
<br class="">
On Sat, 24 Apr 2021, Sean Charles (emacstheviking) wrote:<br class="">
<br class="">
> Is there anywhere to be found a short, concise example of how to<br class="">
> create a DCG rule, just so I can see some examples of the mode<br class="">
> declarations, mine are not going to be used as generators, just as a<br class="">
> lever and a parser/AST builder. I use phrase_from_file/3 in SWI<br class="">
> Prolog, and the debugger means I can step through any rules that<br class="">
> aren’t doing what I think. So far in mercury I have not even worked<br class="">
> out how to start calling the head rule, if you call it that.<br class="">
<br class="">
Have a look at samples/calculator.m in the Mercury distribution.<br class="">
It contains an example of a parser for simple aritmetic expressions<br class="">
implemented using DCGs.<br class="">
<br class="">
Julien.<br class="">
<br class="">
------------------------------<br class="">
<br class="">
Message: 4<br class="">
Date: Sat, 24 Apr 2021 15:55:33 +0100<br class="">
From: "Sean Charles (emacstheviking)" <<a href="mailto:objitsu@gmail.com" target="_blank" rel="noreferrer" class="">objitsu@gmail.com</a>><br class="">
To: Julien Fischer <<a href="mailto:jfischer@opturion.com" target="_blank" rel="noreferrer" class="">jfischer@opturion.com</a>><br class="">
Cc: users <<a href="mailto:users@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users@lists.mercurylang.org</a>><br class="">
Subject: Re: [m-users.] DCG-s in Mercury<br class="">
Message-ID: <<a href="mailto:D45C65A5-292E-4CCD-A67C-057287FB0095@gmail.com" target="_blank" rel="noreferrer" class="">D45C65A5-292E-4CCD-A67C-057287FB0095@gmail.com</a>><br class="">
Content-Type: text/plain; charset=utf-8<br class="">
<br class="">
Brilliant!<br class="">
<br class="">
Thank you Julien.<br class="">
<br class="">
> On 24 Apr 2021, at 12:53, Julien Fischer <<a href="mailto:jfischer@opturion.com" target="_blank" rel="noreferrer" class="">jfischer@opturion.com</a>> wrote:<br class="">
> <br class="">
> <br class="">
> Hi Sean,<br class="">
> <br class="">
> On Sat, 24 Apr 2021, Sean Charles (emacstheviking) wrote:<br class="">
> <br class="">
>> Is there anywhere to be found a short, concise example of how to<br class="">
>> create a DCG rule, just so I can see some examples of the mode<br class="">
>> declarations, mine are not going to be used as generators, just as a<br class="">
>> lever and a parser/AST builder. I use phrase_from_file/3 in SWI<br class="">
>> Prolog, and the debugger means I can step through any rules that<br class="">
>> aren’t doing what I think. So far in mercury I have not even worked<br class="">
>> out how to start calling the head rule, if you call it that.<br class="">
> <br class="">
> Have a look at samples/calculator.m in the Mercury distribution.<br class="">
> It contains an example of a parser for simple aritmetic expressions<br class="">
> implemented using DCGs.<br class="">
> <br class="">
> Julien.<br class="">
<br class="">
<br class="">
<br class="">
------------------------------<br class="">
<br class="">
Message: 5<br class="">
Date: Sat, 24 Apr 2021 20:56:56 +0100<br class="">
From: "Sean Charles (emacstheviking)" <<a href="mailto:objitsu@gmail.com" target="_blank" rel="noreferrer" class="">objitsu@gmail.com</a>><br class="">
To: users <<a href="mailto:users@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users@lists.mercurylang.org</a>><br class="">
Subject: [m-users.] getopt_io return value type on success?<br class="">
Message-ID: <<a href="mailto:41AECD75-D420-4E49-B2BD-588FFF353383@gmail.com" target="_blank" rel="noreferrer" class="">41AECD75-D420-4E49-B2BD-588FFF353383@gmail.com</a>><br class="">
Content-Type: text/plain; charset="utf-8"<br class="">
<br class="">
Hi,<br class="">
<br class="">
I have managed to implement a working command line but I am struggling to figure out how to return the ok(X) value to my caller, I have written a predicate that I call from main():<br class="">
<br class="">
:- pred do_command_line(<br class="">
list(string)::out,<br class="">
getopt_io.option_table(?)::out,<br class="">
io::di, io::uo<br class="">
) is det.<br class="">
<br class="">
<br class="">
I know that ok(X) indicates an option table is now open to being queried etc but I can’t work out what actual type I need to use. I want to pass this object into the following code so that it can act on the various settings that were specified. The declaration of option_table is:<br class="">
<br class="">
:- type option_table(OptionType) == map(OptionType, option_data).<br class="">
<br class="">
But I have so far failed to make the mental connection between whatever is in OptionType and the fact that my options look like this:<br class="">
<br class="">
:- pred short_option(char::in, option::out) is semidet.<br class="">
<br class="">
short_option('h', help).<br class="">
short_option('v', version).<br class="">
short_option('w', code_wrap).<br class="">
short_option('s', syntax_check).<br class="">
short_option('t', target).<br class="">
short_option('T', list_targets).<br class="">
short_option('o', output).<br class="">
short_option('p', packed).<br class="">
short_option('e', error_mode).<br class="">
<br class="">
I want to just call, from main(),<br class="">
<br class="">
do_command_line(FileNames, Options, !IO),<br class="">
<br class="">
But I don’t know what type to make `Options`.<br class="">
<br class="">
Thank you.<br class="">
Sean<br class="">
<br class="">
-------------- next part --------------<br class="">
An HTML attachment was scrubbed...<br class="">
URL: <<a href="http://lists.mercurylang.org/archives/users/attachments/20210424/178404e0/attachment-0001.html" rel="noreferrer noreferrer" target="_blank" class="">http://lists.mercurylang.org/archives/users/attachments/20210424/178404e0/attachment-0001.html</a>><br class="">
<br class="">
------------------------------<br class="">
<br class="">
Message: 6<br class="">
Date: Sun, 25 Apr 2021 06:26:51 +1000 (AEST)<br class="">
From: "Zoltan Somogyi" <<a href="mailto:zoltan.somogyi@runbox.com" target="_blank" rel="noreferrer" class="">zoltan.somogyi@runbox.com</a>><br class="">
To: "Sean Charles" <<a href="mailto:objitsu@gmail.com" target="_blank" rel="noreferrer" class="">objitsu@gmail.com</a>><br class="">
Cc: users <<a href="mailto:users@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users@lists.mercurylang.org</a>><br class="">
Subject: Re: [m-users.] getopt_io return value type on success?<br class="">
Message-ID: <<a href="mailto:E1laOrb-0007a9-W5@rmmprod07.runbox" class="">E1laOrb-0007a9-W5@rmmprod07.runbox</a>><br class="">
Content-Type: text/plain; charset="utf-8"<br class="">
<br class="">
<br class="">
<br class="">
On Sat, 24 Apr 2021 20:56:56 +0100, "Sean Charles (emacstheviking)" <<a href="mailto:objitsu@gmail.com" target="_blank" rel="noreferrer" class="">objitsu@gmail.com</a>> wrote:<br class="">
> But I don’t know what type to make `Options`.<br class="">
<br class="">
That type should have one alternative for each of the options<br class="">
of your program.<br class="">
<br class="">
There are several examples of how to use getopt<br class="">
in the extras directory. Have a look at them.<br class="">
<br class="">
Zoltan.<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
------------------------------<br class="">
<br class="">
Message: 7<br class="">
Date: Sat, 24 Apr 2021 21:34:44 +0100<br class="">
From: "Sean Charles (emacstheviking)" <<a href="mailto:objitsu@gmail.com" target="_blank" rel="noreferrer" class="">objitsu@gmail.com</a>><br class="">
To: Zoltan Somogyi <<a href="mailto:zoltan.somogyi@runbox.com" target="_blank" rel="noreferrer" class="">zoltan.somogyi@runbox.com</a>><br class="">
Cc: users <<a href="mailto:users@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users@lists.mercurylang.org</a>><br class="">
Subject: Re: [m-users.] getopt_io return value type on success?<br class="">
Message-ID: <<a href="mailto:E9690DDC-0C51-4312-ABAC-88BC324485C8@gmail.com" target="_blank" rel="noreferrer" class="">E9690DDC-0C51-4312-ABAC-88BC324485C8@gmail.com</a>><br class="">
Content-Type: text/plain; charset=utf-8<br class="">
<br class="">
Bingo!<br class="">
<br class="">
The penny has dropped, I looked at the align_right.m sample (useful code to read) and saw how to parameterise the type.<br class="">
<br class="">
Thanks Zoltan!<br class="">
<br class="">
It’s the journey not the destination.<br class="">
Getting there one day would be nice. :)<br class="">
<br class="">
> On 24 Apr 2021, at 21:26, Zoltan Somogyi <<a href="mailto:zoltan.somogyi@runbox.com" target="_blank" rel="noreferrer" class="">zoltan.somogyi@runbox.com</a>> wrote:<br class="">
> <br class="">
> <br class="">
> <br class="">
> On Sat, 24 Apr 2021 20:56:56 +0100, "Sean Charles (emacstheviking)" <<a href="mailto:objitsu@gmail.com" target="_blank" rel="noreferrer" class="">objitsu@gmail.com</a>> wrote:<br class="">
>> But I don’t know what type to make `Options`.<br class="">
> <br class="">
> That type should have one alternative for each of the options<br class="">
> of your program.<br class="">
> <br class="">
> There are several examples of how to use getopt<br class="">
> in the extras directory. Have a look at them.<br class="">
> <br class="">
> Zoltan.<br class="">
> <br class="">
> <br class="">
<br class="">
<br class="">
<br class="">
------------------------------<br class="">
<br class="">
Subject: Digest Footer<br class="">
<br class="">
_______________________________________________<br class="">
users mailing list<br class="">
<a href="mailto:users@lists.mercurylang.org" target="_blank" rel="noreferrer" class="">users@lists.mercurylang.org</a><br class="">
<a href="https://lists.mercurylang.org/listinfo/users" rel="noreferrer noreferrer" target="_blank" class="">https://lists.mercurylang.org/listinfo/users</a><br class="">
<br class="">
<br class="">
------------------------------<br class="">
<br class="">
End of users Digest, Vol 80, Issue 9<br class="">
************************************<br class="">
</blockquote></div>
_______________________________________________<br class="">users mailing list<br class=""><a href="mailto:users@lists.mercurylang.org" class="">users@lists.mercurylang.org</a><br class="">https://lists.mercurylang.org/listinfo/users<br class=""></div></blockquote></div><br class=""></div></body></html>