[m-users.] Sean' request
Fabrice Nicol
fabrnicol at gmail.com
Sun Apr 25 12:52:36 AEST 2021
Sean,
Your testimony is an interesting one.
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).
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.
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.
Best
Fabrice
Le sam. 24 avr. 2021 à 10:35 PM, <users-request at lists.mercurylang.org> a
écrit :
> Send users mailing list submissions to
> users at lists.mercurylang.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.mercurylang.org/listinfo/users
> or, via email, send a message with subject or body 'help' to
> users-request at lists.mercurylang.org
>
> You can reach the person managing the list at
> 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>
> To: users <users at lists.mercurylang.org>
> Subject: [m-users.] DCG-s in Mercury
> Message-ID: <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>
> To: "Sean Charles (emacstheviking)" <objitsu at gmail.com>
> Cc: users <users at lists.mercurylang.org>
> Subject: Re: [m-users.] DCG-s in Mercury
> Message-ID: <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>
> To: "Sean Charles (emacstheviking)" <objitsu at gmail.com>
> Cc: users <users at lists.mercurylang.org>
> Subject: Re: [m-users.] DCG-s in Mercury
> Message-ID: <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>
> To: Julien Fischer <jfischer at opturion.com>
> Cc: users <users at lists.mercurylang.org>
> Subject: Re: [m-users.] DCG-s in Mercury
> Message-ID: <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> 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>
> To: users <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>
> 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
> >
>
> ------------------------------
>
> Message: 6
> Date: Sun, 25 Apr 2021 06:26:51 +1000 (AEST)
> From: "Zoltan Somogyi" <zoltan.somogyi at runbox.com>
> To: "Sean Charles" <objitsu at gmail.com>
> Cc: users <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> 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>
> To: Zoltan Somogyi <zoltan.somogyi at runbox.com>
> Cc: users <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>
> 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>
> wrote:
> >
> >
> >
> > On Sat, 24 Apr 2021 20:56:56 +0100, "Sean Charles (emacstheviking)" <
> 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
> https://lists.mercurylang.org/listinfo/users
>
>
> ------------------------------
>
> End of users Digest, Vol 80, Issue 9
> ************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20210425/0a31a79c/attachment-0001.html>
More information about the users
mailing list