[m-users.] Sean' request

Sean Charles (emacstheviking) objitsu at gmail.com
Sun Apr 25 22:00:37 AEST 2021


Hi Fabrice,
Thanks for your reply, very heart-warming indeed.  :)


> On 25 Apr 2021, at 03:52, Fabrice Nicol <fabrnicol at gmail.com> wrote:
> 
> Sean, 
> Your testimony is an interesting one.

Thanks.

> 
> 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).

I started with GNU Prolog, wow, just looked, EIGHT years ago ( https://github.com/emacstheviking/gnuprolog-redisclient <https://github.com/emacstheviking/gnuprolog-redisclient> ) 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.

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!!!  :)

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!

> 
> 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. 

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.

This app:  https://github.com/emacstheviking/mcnew <https://github.com/emacstheviking/mcnew>.  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:

    $ mcnew stub foo > foo.m
    $ mcnew makefile foo > Makefile

And away I go!
 
> 
> 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.

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!




> Best
> Fabrice

Likewise, the path is an interesting one but always rewarding.

Thanks, and all the best to you and everybody else on the journey!
:)
Sean


> 
> 
> 
> 
> Le sam. 24 avr. 2021 à 10:35 PM, <users-request at lists.mercurylang.org <mailto:users-request at lists.mercurylang.org>> a écrit :
> Send users mailing list submissions to
>         users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://lists.mercurylang.org/listinfo/users <https://lists.mercurylang.org/listinfo/users>
> or, via email, send a message with subject or body 'help' to
>         users-request at lists.mercurylang.org <mailto:users-request at lists.mercurylang.org>
> 
> You can reach the person managing the list at
>         users-owner at lists.mercurylang.org <mailto:users-owner at lists.mercurylang.org>
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of users digest..."
> 
> 
> Today's Topics:
> 
>    1. DCG-s in Mercury (Sean Charles (emacstheviking))
>    2. Re: DCG-s in Mercury (Tomas By)
>    3. Re: DCG-s in Mercury (Julien Fischer)
>    4. Re: DCG-s in Mercury (Sean Charles (emacstheviking))
>    5. getopt_io return value type on success?
>       (Sean Charles (emacstheviking))
>    6. Re: getopt_io return value type on success? (Zoltan Somogyi)
>    7. Re: getopt_io return value type on success?
>       (Sean Charles (emacstheviking))
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Sat, 24 Apr 2021 10:33:31 +0100
> From: "Sean Charles (emacstheviking)" <objitsu at gmail.com <mailto:objitsu at gmail.com>>
> To: users <users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>>
> Subject: [m-users.] DCG-s in Mercury
> Message-ID: <6D19C8E1-8CD9-47D5-87E8-C7CE587E06A0 at gmail.com <mailto:6D19C8E1-8CD9-47D5-87E8-C7CE587E06A0 at gmail.com>>
> Content-Type: text/plain;       charset=utf-8
> 
> Hi,
> 
> 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 ?
> 
> 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.
> 
> I’ve built and use an ROTD from sources:
> 
>     ➜  mcnew mmc —version
>     Mercury Compiler, version rotd-2021-04-15, on x86_64-apple-darwin19.6.0
>     Copyright (C) 1993-2012 The University of Melbourne
>     Copyright (C) 2013-2021 The Mercury team
> 
> 
> 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”.
> 
> So. Thanks for Mercury chaps, a brilliant piece of work that the world probably won’t ever fully appreciate, but I do.
> It’s just a shame I can’t use it yet! 
> :)
> 
> All the best,
> Sean.
> 
> 
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Sat, 24 Apr 2021 11:56:01 +0200
> From: Tomas By <tomas at basun.net <mailto:tomas at basun.net>>
> To: "Sean Charles (emacstheviking)" <objitsu at gmail.com <mailto:objitsu at gmail.com>>
> Cc: users <users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>>
> Subject: Re: [m-users.] DCG-s in Mercury
> Message-ID: <8735vg80r2.wl-tomas at basun.net <mailto:8735vg80r2.wl-tomas at basun.net>>
> Content-Type: text/plain; charset=ISO-8859-7
> 
> On Sat, 24 Apr 2021 11:33:31 +0200, Sean Charles (emacstheviking) wrote:
> > [...] now I have two sets of DCG rules to port from SWI Prolog and I
> > just don’t know where to start. [...]
> 
> 
> There are a couple of problems: partical data structures and
> nondeterminism. If the DCG is for a formal language (ie programming
> code) then it is better to rewrite the parser, for example using
> `continuation passing' (I think it's called).
> 
> To implement a DCG in Mercury you need to have solutions/2 at the top,
> and then make all the `grammar rules' nondet. Constructing the output
> holistically, as is/was common in DCGs, does not work (unless it has
> been added in the twenty years or so since I tried it).
> 
> But to begin with you can just remove all the output parameters from
> the DCG, and then look at that problem after the parsing works.
> 
> There are some minor advantages compared to Prolog, e.g. you can write
> Kleene operators (star, plus, question mark) to make things
> prettier. This has been discussed here before I believe.
> 
> /Tomas
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Sat, 24 Apr 2021 21:53:09 +1000 (AEST)
> From: Julien Fischer <jfischer at opturion.com <mailto:jfischer at opturion.com>>
> To: "Sean Charles (emacstheviking)" <objitsu at gmail.com <mailto:objitsu at gmail.com>>
> Cc: users <users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>>
> Subject: Re: [m-users.] DCG-s in Mercury
> Message-ID: <af1d114b-c9a3-91f0-b364-744d1b7a5033 at opturion.com <mailto:af1d114b-c9a3-91f0-b364-744d1b7a5033 at opturion.com>>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
> 
> 
> Hi Sean,
> 
> On Sat, 24 Apr 2021, Sean Charles (emacstheviking) wrote:
> 
> > 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.
> 
> Have a look at samples/calculator.m in the Mercury distribution.
> It contains an example of a parser for simple aritmetic expressions
> implemented using DCGs.
> 
> Julien.
> 
> ------------------------------
> 
> Message: 4
> Date: Sat, 24 Apr 2021 15:55:33 +0100
> From: "Sean Charles (emacstheviking)" <objitsu at gmail.com <mailto:objitsu at gmail.com>>
> To: Julien Fischer <jfischer at opturion.com <mailto:jfischer at opturion.com>>
> Cc: users <users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>>
> Subject: Re: [m-users.] DCG-s in Mercury
> Message-ID: <D45C65A5-292E-4CCD-A67C-057287FB0095 at gmail.com <mailto:D45C65A5-292E-4CCD-A67C-057287FB0095 at gmail.com>>
> Content-Type: text/plain;       charset=utf-8
> 
> Brilliant!
> 
> Thank you Julien.
> 
> > On 24 Apr 2021, at 12:53, Julien Fischer <jfischer at opturion.com <mailto:jfischer at opturion.com>> wrote:
> > 
> > 
> > Hi Sean,
> > 
> > On Sat, 24 Apr 2021, Sean Charles (emacstheviking) wrote:
> > 
> >> 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.
> > 
> > Have a look at samples/calculator.m in the Mercury distribution.
> > It contains an example of a parser for simple aritmetic expressions
> > implemented using DCGs.
> > 
> > Julien.
> 
> 
> 
> ------------------------------
> 
> Message: 5
> Date: Sat, 24 Apr 2021 20:56:56 +0100
> From: "Sean Charles (emacstheviking)" <objitsu at gmail.com <mailto:objitsu at gmail.com>>
> To: users <users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>>
> Subject: [m-users.] getopt_io return value type on success?
> Message-ID: <41AECD75-D420-4E49-B2BD-588FFF353383 at gmail.com <mailto:41AECD75-D420-4E49-B2BD-588FFF353383 at gmail.com>>
> Content-Type: text/plain; charset="utf-8"
> 
> Hi,
> 
> 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():
> 
>     :- pred do_command_line(
>             list(string)::out,
>             getopt_io.option_table(?)::out,
>             io::di, io::uo
>      ) is det.
> 
> 
> 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:
> 
> :- type option_table(OptionType) == map(OptionType, option_data).
> 
> 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:
> 
> :- pred short_option(char::in, option::out) is semidet.
> 
> short_option('h', help).
> short_option('v', version).
> short_option('w', code_wrap).
> short_option('s', syntax_check).
> short_option('t', target).
> short_option('T', list_targets).
> short_option('o', output).
> short_option('p', packed).
> short_option('e', error_mode).
> 
> I want to just call, from main(),
> 
>         do_command_line(FileNames, Options, !IO),
> 
> But I don’t know what type to make `Options`.
> 
> Thank you.
> Sean
> 
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.mercurylang.org/archives/users/attachments/20210424/178404e0/attachment-0001.html <http://lists.mercurylang.org/archives/users/attachments/20210424/178404e0/attachment-0001.html>>
> 
> ------------------------------
> 
> Message: 6
> Date: Sun, 25 Apr 2021 06:26:51 +1000 (AEST)
> From: "Zoltan Somogyi" <zoltan.somogyi at runbox.com <mailto:zoltan.somogyi at runbox.com>>
> To: "Sean Charles" <objitsu at gmail.com <mailto:objitsu at gmail.com>>
> Cc: users <users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>>
> Subject: Re: [m-users.] getopt_io return value type on success?
> Message-ID: <E1laOrb-0007a9-W5 at rmmprod07.runbox>
> Content-Type: text/plain; charset="utf-8"
> 
> 
> 
> On Sat, 24 Apr 2021 20:56:56 +0100, "Sean Charles (emacstheviking)" <objitsu at gmail.com <mailto:objitsu at gmail.com>> wrote:
> > But I don’t know what type to make `Options`.
> 
> That type should have one alternative for each of the options
> of your program.
> 
> There are several examples of how to use getopt
> in the extras directory. Have a look at them.
> 
> Zoltan.
> 
> 
> 
> 
> ------------------------------
> 
> Message: 7
> Date: Sat, 24 Apr 2021 21:34:44 +0100
> From: "Sean Charles (emacstheviking)" <objitsu at gmail.com <mailto:objitsu at gmail.com>>
> To: Zoltan Somogyi <zoltan.somogyi at runbox.com <mailto:zoltan.somogyi at runbox.com>>
> Cc: users <users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>>
> Subject: Re: [m-users.] getopt_io return value type on success?
> Message-ID: <E9690DDC-0C51-4312-ABAC-88BC324485C8 at gmail.com <mailto:E9690DDC-0C51-4312-ABAC-88BC324485C8 at gmail.com>>
> Content-Type: text/plain;       charset=utf-8
> 
> Bingo!
> 
> The penny has dropped, I looked at the align_right.m sample (useful code to read) and saw how to parameterise the type.
> 
> Thanks Zoltan!
> 
> It’s the journey not the destination.
> Getting there one day would be nice.  :)
> 
> > On 24 Apr 2021, at 21:26, Zoltan Somogyi <zoltan.somogyi at runbox.com <mailto:zoltan.somogyi at runbox.com>> wrote:
> > 
> > 
> > 
> > On Sat, 24 Apr 2021 20:56:56 +0100, "Sean Charles (emacstheviking)" <objitsu at gmail.com <mailto:objitsu at gmail.com>> wrote:
> >> But I don’t know what type to make `Options`.
> > 
> > That type should have one alternative for each of the options
> > of your program.
> > 
> > There are several examples of how to use getopt
> > in the extras directory. Have a look at them.
> > 
> > Zoltan.
> > 
> > 
> 
> 
> 
> ------------------------------
> 
> Subject: Digest Footer
> 
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>
> https://lists.mercurylang.org/listinfo/users <https://lists.mercurylang.org/listinfo/users>
> 
> 
> ------------------------------
> 
> End of users Digest, Vol 80, Issue 9
> ************************************
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org
> https://lists.mercurylang.org/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20210425/cccd0fd3/attachment-0001.html>


More information about the users mailing list