Re: 0-arity compound terms

"Richard A. O'Keefe" <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 28/11/2013, at 2:10 AM, Jan Wielemaker wrote:
> 
> If you decide to define a DSL to accomodate a more concise and/or
> natural description of your domain you want building blocks that allows
> for creating an as natural as possible representation. That is an
> important reason why we have operators. It is also the reason why SWI
> supports A[42] as valid syntax (and YAP, ECLiPSe, B-Prolog, Ciao (not
> sure)). f() is just another example of a commonly found construct that
> is a useful building block for defining the syntax of such languages. I
> do not expect much use outside this limited application area. Of course,
> one never knows. It might be that someone finds another good use for
> f().

The issue is not the existence of a notation for f().
The issue is the creation of a new kind of term with an
atom function symbol and arity 0 that is not the atom.

If someone wants an embedded DSL and wants to use f()
then for their purposes, mapping this to '()'(f) may well be
adequate.  It does _not_ have to be a new *kind* of Prolog term.

Exercise for the reader:

 000100 BEGIN, ATLAS PROGRAM ’LAB1, PART 3’ $
 000110 DECLARE, VARIABLE, ’RESULTS’ IS DECIMAL$
 000120 DECLARE, VARIABLE, ’A’ IS INTEGER $
 000130 DECLARE, VARIABLE, ’HI-PIN’ IS ARRAY (1 THRU 2) OF CONNECTION
        (J1-3, J1-4) INITIAL = CONNECTION J1-3, CONNECTION J1-4 $ 
E500100 APPLY, DC SIGNAL, VOLTAGE 5 V, CNX HI ’HI-PIN’(2) LO J1-11 $
 500110 OUTPUT, C’WAITING FOR 30 SEC FOR INPUT POWER STABILIZATION’,C’\LF\’ $
 500112 CALCULATE, ’A’ = 30 $
 500115 WAIT FOR, ’A’ SEC $
 500120 APPLY, AC SIGNAL, VOLTAGE 5 V, FREQ 60 HZ, CNX HI ’HI-PIN’(1) LO J1-10 $
 500130 VERIFY, (VOLTAGE INTO ’RESULTS’), AC SIGNAL,
        NOM 25.2 V UL26.7 V LL23.7 V,
        VOLTAGE RANGE 20 V TO 30 V, CNX HI J1-22 LO EARTH $
 500140 IF, GO, THEN $
 500150 OUTPUT, C'UUT PASSED' $
 500160 ELSE $
 500170 OUTPUT, C'UUT FAILED' $
 500180 END, IF $
 500190 WAIT FOR, 10 SEC $
 500200 VERIFY, (VOLTAGE INTO ’RESULTS’), AC SIGNAL,
        NOM 25.2 V UL 26.7 V LL 23.7 V,
        VOLTAGE RANGE 20 V TO 30 V, CNX HI J1-22 LO EARTH $
 500210 IF, GO, THEN $
 500220 OUTPUT, C’UUT PASSED’ $ 500230 ELSE $
 500240 OUTPUT, C’UUT FAILED’ $ 500250 END, IF $
 500260 REMOVE, ALL $
 999999 TERMINATE, ATLAS PROGRAM $

(Yes, there _is_ an E at the beginning of one line, and yes, it matters.)
(a) This is a much used programming language that has been around for
    about 40 years.  What is its *full* name?
(b) Is "f()" helpful for _this_ language?
(c) Which languages other than C-family and functional languages
    (counting Javascript as having a pseudopod in each camp)
    _is_ f() helpful for?
(d) Design an embedding of this language (or even this fragment!) in
    Prolog, explaining how either the source language programmer's
    expectations (maybe lower case would be required?) or the target
    language's rules (maybe "numbers can't be prefix operators"?) would
    have to be violated.

To revert to f().
I am *not* arguing against having "f()" being legal syntax.
I *am* arguing that making it a NEW KIND OF TERM
 - imposes high cognitive and practical costs on Prolog programmers
 - provides no benefit to people doing many DSLs
 - provides somewhere between "little" and "no" benefit to
   people doing other DSLs (that is, little or no benefit
   from BEING A NEW KIND OF TERM, not little or no benefit
   from making f and f() distinguishable).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.