[mercury-users] Lisp-like syntax for Mercury (Mercury & macros)
Richard A. O'Keefe
ok at cs.otago.ac.nz
Fri Jun 7 13:38:12 AEST 2002
Milan Zamazal <pdm at zamazal.org> wrote:
- Good editor support (as a former participant of an attempt to create a
modern Prolog mode for Emacs, I know how painful Prolog's syntax is
from the point of view of editor support).
That's odd. My tiny Emacs-ish editor (thief/top) has what I consider to
be good support for Prolog (like it can detect syntax errors and singleton
errors, knows the beginning of a predicate when it sees one, and can step
over Prolog goals &c) and it was *EASY*. Mind you, I didn't have to fight
Emacs lisp to do it...
(defmodule sort
(:export main))
What happened to the arity?
(define main (* *)
(:types (io:state io:state)
:modes ((di uo :det)))
This strikes me as rather un-lispy. Why not
(define (main (W0 io:state) (W io:state))
"Some documentation."
[io:command-line-arguments Args]
Here I part company with you. The use of square brackets is common
in some Scheme dialects, and was known in Interlisp (where brackets
were "stronger" than parentheses, so [(((x] was legal). But it is
not part of normal (Common) Lisp practice, nor blessed by any version
of the Scheme report.
(or [= Args '()]
[handle-args [no] [no] * *]
[sort * *]
/
I haven't the faintest idea what / might be. In Marseilles Prolog
it was the cut. OHHHHH, I see.
(or g11 ... / g21 ... / g31 ...)
really means
(or (and g11 ...)
(and g21 ...)
(and g31 ...))
I can't help thinking that using 'and' would be lispier than using /.
[= Args '(Input)]
[handle-args [yes Input] [no] * *]
[sort * *]
/
[= Args '(Input Output)]
[handle-args [yes Input] [yes Output] * *]
[sort * *]
/
[= Args '(_ _ _ . _)]
[io:write-string "Usage: sort [Input [Output]]~%" * *]))
I really have trouble understanding what the stars mean.
(Some Prolog dialects have used "*" the way Edinburgh Prolog uses "_".
That threw me.) If a quaint abbreviation is to be used, wouldn't
":io" be clearer than "* *"?
Here it is in a lispier style.
(define (main (W0 io:state) (W io:state)
:modes ((di uo :det)))
"Some documentation."
(io:command-line-arguments Args)
(case Args
(()
(handle-args (no) (no) W0 W1)
(sort W1 W))
((Input)
(handle-args (yes Input) (no) W0 W1)
(sort W1 W))
((Input Output)
(handle-args (yes Input) (yes Output) W0 W1)
(sort W1 W))
((_ _ _ . _)
(io:write-string "Usage: sort [Input [Output]]~%" W0 W))))
If something is going to use a lispy syntax, then since 'case' is part
of Lisp syntax, 'case' might as well be used.
On the other hand, distinguishing between W and w isn't really very lispy.
This isn't going to be pretty, but it's arguably lispier:
(define (main (,W0 io:state) (,W io:state)
:modes ((di uo :det)))
"Some documentation."
(io:command-line-arguments ,Args)
(case ,Args
(()
(handle-args (no) (no) ,W0 ,W1)
(sort ,W1 ,W))
((,Input)
(handle-args (yes ,Input) (no) ,W0 ,W1)
(sort ,W1 ,W))
((,Input ,Output)
(handle-args (yes ,Input) (yes ,Output) ,W0 ,W1)
(sort ,W1 ,W))
((_ _ _ . _)
(io:write-string "Usage: sort [Input [Output]]~%" ,W0 ,W))))
Hmm.
#main(io:state,io:state)-det(di,uo).
+main(W0,W)-io:command_line_arguments(A)-main_body(A,W0,W).
#main_body(list(string),io:state,io:state)-det(in,di,uo).
+main_body(nil,W0,W) -handle_args(no,no,W0,W1) -sort(W1,W).
+main_body(I.nil,W0,W) -handle_args(yes(I),no,W0,W1) -sort(W1,W).
+main_body(I.O.nil,W0,W)-handle_args(yes(I),yes(O),W0,W1)-sort(W1,W).
+main_body(_._._._,W0,W)-io:write_string("Usage: sort [In [Out]]\n",W0,W).
Maybe we abandoned Marseilles Prolog syntax too soon? (:-)
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list